山高岳小,水落石出

blog重建工作基本完成

导航

Blog统计

公告

1.关注java,关注web开发,关注互联网,关注企业信息化

2.关注实时绘制技术,关注光照技术,关注阴影技术

3.关注投资理财,关注企业管理,关注创业项目









文章

收藏

相册

my blog

存档


正在读取评论……

下面这段红宝书中的代码,我试到vc++的环境中编译,debug,发现断点设在main函数的任何一个部分都没有用,

停不下来。只有设在torus中才能停下来。

后来发现,第一次显示的时候并没有经过main和其他函数,只经过了torus和GLuint theTorus;这条语句,也就是编译

链接完了之后初次的显示就被确定了。但是后来有键盘响应的时候,又进入了keyboard和display函数,说明main包括init被

编译没了,一进来就有一次显示,后来的还和一般的程序相同。

不知道我理解的对不对。

/*

*  torus.c

*  This program demonstrates the creation of a display list.

*/

#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>


#define PI_ 3.14159265358979323846

GLuint theTorus;

/* Draw a torus */
static void torus(int numc, int numt)
{
 int i, j, k;
 double s, t, x, y, z, twopi;

 twopi = 2 * PI_;
 for (i = 0; i < numc; i++) {
  glBegin(GL_QUAD_STRIP);
  for (j = 0; j <= numt; j++) {
   for (k = 1; k >= 0; k--) {
    s = (i + k) % numc + 0.5;
    t = j % numt;
    x = (1+.1*cos(s*twopi/numc))*cos(t*twopi/numt);
    y = (1+.1*cos(s*twopi/numc))*sin(t*twopi/numt);
    z = .1 * sin(s * twopi / numc);
    glVertex3f(x, y, z);
   }
  }
  glEnd();
 }
}

/* Create display list with Torus and initialize state */
static void init(void)
{
 theTorus = glGenLists (1);
 glNewList(theTorus, GL_COMPILE);
 torus(8, 25);
 glEndList();
 glShadeModel(GL_FLAT);
 glClearColor(0.0, 0.0, 0.0, 0.0);

}

/* Clear window and draw torus */
void display(void)
{
 glClear(GL_COLOR_BUFFER_BIT);
 glColor3f (1.0, 1.0, 1.0);
 glCallList(theTorus);
 glFlush();

}

/* Handle window resize */
void reshape(int w, int h)
{
 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(30, (GLfloat) w/(GLfloat) h, 1.0, 100.0);
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
 gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
}

/* Rotate about x-axis when "x" typed; rotate about y-axis
when "y" typed; "i" returns torus to original view */
void keyboard(unsigned char key, int x, int y)
{
 switch (key) {
   case 'x':
   case 'X':
    glRotatef(30.,1.0,0.0,0.0);
    glutPostRedisplay();
    break;
   case 'y':
   case 'Y':
    glRotatef(30.,0.0,1.0,0.0);
    glutPostRedisplay();
    break;
   case 'i':
   case 'I':
    glLoadIdentity();
    gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
    glutPostRedisplay();
    break;
   case 27:
    exit(0);
    break;
 }
}

int main(int argc, char **argv)
{
 glutInitWindowSize(200, 200);
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
 glutCreateWindow(argv[0]);
 init();
 glutReshapeFunc(reshape);
 glutKeyboardFunc(keyboard);
 glutDisplayFunc(display);
 glutMainLoop();
 return 0;
}



Trackback: http://tb.donews.net/TrackBack.aspx?PostId=289488


[点击此处收藏本文]  发表于2005年02月26日 10:16 PM




正在读取评论……
大名
网址
验证码
评论