下面的程序本来用opengl显示列表要绘制6个彩色三角形,为什么只绘制出一个?百思不得其解,望高手指点!
#include<windows.h>
#include<gl/glut.h>
GLuint listName
void myInit(void)
{
listName=glGenLists(1);
glClearColor(0.0,0.0,0.0,0.0);
glNewList(listName,GL_COMPILE);
glBegin(GL_POLYGON);
glColor3f(1.0,0.0,0.0);
glVertex2f(1.0,1.0);
glColor3f(0.0,1.0,0.0);
glVertex2f(2.0,2.0);
glColor3f(0.0,0.0,1.0);
glVertex2f(1.5,2.5);
glTranslatef(0.5,-0.5,0.0);
glEnd();
glEndList();
glShadeModel(GL_SMOOTH);
}
void myDisplay(void)
{
GLuint i;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
for(i=0;i<6;i++)
glCallList(listName);
glFlush();
}
void myReshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
glOrtho(-4.0,4.0,-4.0*(GLfloat)h/(GLfloat)w,4.0*(GLfloat)h/(GLfloat)w,-8.0,8.0);
else
glOrtho(-4.0,4.0*(GLfloat)w/(GLfloat)h,-4.0,4.0,-8.0,8.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-4.0,0.0,-3.0);
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,200);
glutCreateWindow("display list");
myInit();
glutReshapeFunc(myReshape);
glutDisplayFunc(myDisplay);
glutMainLoop();
return(0);
}