显示列表

创建显示列表:

GLuint box;
box = glGenLists(1);
glNewList(box, GL_COMPILE);
......
glEndList();

example:

//创建显示列表
GLuint box;
box = glGenLists(1);
glNewList(box, GL_COMPILE);

//绘制立方体
glBegin(GL_QUADS);

//x
//glColor4ub(200, 0, 0, 255);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.5f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(0.5f, -0.5f, -0.5f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(0.5f, 0.5f, -0.5f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(0.5f, 0.5f, 0.5f);

//-x
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);

//y
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(0.5f, 0.5f, 0.5f);
glVertex3f(0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);

//-y
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(0.5f, -0.5f, -0.5f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(0.5f, -0.5f, 0.5f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-0.5f, -0.5f, 0.5f);

//z
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.5f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(0.5f, 0.5f, 0.5f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-0.5f, 0.5f, 0.5f);

//-z
glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(0.5f, 0.5f, -0.5f);

glEnd();
glEndList();

调用显示列表:

glCallList(...);

example:

glPushMatrix();
glTranslatef(-4.0f, 3.0f, -10.0f);
glCallList(box);
glPopMatrix();

你可能感兴趣的:(显示列表)