NeHe教程Qt实现——lesson12
来源:互联网 发布:手机怎么登陆淘宝店铺 编辑:程序博客网 时间:2024/04/28 17:01
NeHe 系列教程之十二: 显示列表
英文教程地址:lesson12
本课主要演示了显示列表的使用。代码基于第六课。
显示列表的主要接口:
glGenLists
glNewList
glCallList
具体来看代码中的使用:
namespace { ... static GLfloat boxcol[5][3]= // Array For Box Colors { // Bright: Red, Orange, Yellow, Green, Blue {1.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{1.0f,1.0f,0.0f},{0.0f,1.0f,0.0f},{0.0f,1.0f,1.0f} }; static GLfloat topcol[5][3]= // Array For Top Colors { // Dark: Red, Orange, Yellow, Green, Blue {.5f,0.0f,0.0f},{0.5f,0.25f,0.0f},{0.5f,0.5f,0.0f},{0.0f,0.5f,0.0f},{0.0f,0.5f,0.5f} }; GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f }; // Ambient Light Values ( NEW ) GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f }; // Diffuse Light Values ( NEW ) GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }; // Light Position ( NEW ) GLvoid BuildLists() // Build Box Display List { box=glGenLists(2); // Building Two Lists glNewList(box,GL_COMPILE); // New Compiled box Display List glBegin(GL_QUADS); // Front Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad // Back Face glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad // Top Face glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad // Bottom Face glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad // Right face glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad // Left Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad glEnd(); glEndList(); top = box + 1; glNewList(top,GL_COMPILE); // Top Face glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad glEndList(); }}
最后 我们再看在绘制代码中的使用:
void MyGLWidget::paintGL(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The Current Modelview Matrix glTranslatef(0.0f,0.0f,-5.0f); // Move Into The Screen 5 Units glBindTexture(GL_TEXTURE_2D, texture[0]); // Select Our Texture for (yloop=1;yloop<6;yloop++) { for (xloop=0;xloop<yloop;xloop++) { glLoadIdentity(); glTranslatef(1.4f+(float(xloop)*2.8f)-(float(yloop)*1.4f),((6.0f-float(yloop))*2.4f)-7.0f,-20.0f); glRotatef(45.0f-(2.0f*yloop)+xrot,1.0f,0.0f,0.0f); // Tilt The Cubes Up And Down glRotatef(45.0f+yrot,0.0f,1.0f,0.0f); // Spin Cubes Left And Right glColor3fv(boxcol[yloop-1]); // Select A Box Color glCallList(box); glColor3fv(topcol[yloop-1]); // Select The Top Color glCallList(top); // Draw The Top } } xrot += 0.3f; // X Axis Rotation yrot += 0.2f; // Y Axis Rotation}
运行效果如下图所示:
- NeHe教程Qt实现——lesson12
- NeHe教程Qt实现——lesson01
- NeHe教程Qt实现——lesson02
- NeHe教程Qt实现——lesson03
- NeHe教程Qt实现——lesson04
- NeHe教程Qt实现——lesson05
- NeHe教程Qt实现——lesson06
- NeHe教程Qt实现——lesson07
- NeHe教程Qt实现——lesson08
- NeHe教程Qt实现——lesson09
- NeHe教程Qt实现——lesson10
- NeHe教程Qt实现——lesson11
- NeHe教程Qt实现——lesson13
- NeHe教程Qt实现——lesson14
- NeHe教程Qt实现——lesson15
- NeHe教程Qt实现——lesson16
- NeHe教程Qt实现——lesson17
- 用OpenInventor实现的NeHe OpenGL教程-第一课
- C++编程思想学习—C++中的C特征
- 通过struts2获取存储到数据库出现中文乱码问题
- linux tty pty pts 概念 区别
- Filter 学习 (2) 字符编码。
- Flume OG & Flume NG
- NeHe教程Qt实现——lesson12
- 多线程阻塞问题的监控与调试
- HDU 2222 AC_Automation 第一道AC自动机
- 初学C#,入门好材料
- Qt arm平台移植
- sygate破解版
- 共用体的妙用
- oracle中如何批量编译视图和存储过程
- 让VBS脚本也有GUI图形界面