LIST.C
上传用户:tengyuc
上传日期:2007-08-14
资源大小:722k
文件大小:2k
- // 本程序演示如何创建和运行一个显式列表
#include <GL/glut.h>
#include <stdlib.h>
GLuint listName;
static void init (void)
{
- // 生成显式列表名称索引
listName = glGenLists (1);
- // 创建一个显式列表
glNewList (listName, GL_COMPILE);
glColor3f (1.0, 0.0, 0.0); // 当前颜色是红色
glBegin (GL_TRIANGLES);
glVertex2f (0.0, 0.0);
glVertex2f (1.0, 0.0);
glVertex2f (0.0, 1.0);
glEnd ();
glTranslatef (1, 0.0, 0.0); // 移动位置
glEndList ();
glShadeModel (GL_FLAT);
}
static void drawLine (void)
{
glBegin (GL_LINES);
glVertex2f (0.0, 0.5);
glVertex2f (15.0, 0.5);
glEnd ();
}
void display(void)
{
GLuint i;
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 1.0, 0.0); // 当前颜色是绿色
for (i = 0; i < 10; i++) // 绘制10个三角形
glCallList (listName);
drawLine ();
glFlush ();
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
gluOrtho2D (0.0, 2.0, -0.5 * (GLfloat) h/(GLfloat) w,
1.5 * (GLfloat) h/(GLfloat) w);
else
gluOrtho2D (0.0, 2.0 * (GLfloat) w/(GLfloat) h, -0.5, 1.5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(300, 50);
glutCreateWindow(argv[0]);
init ();
glutReshapeFunc (reshape);
glutDisplayFunc (display);
glutKeyboardFunc (keyboard);
glutMainLoop();
return 0;
}