###### 山庄来客的专栏

Android, Linux Kernel Research Notes

###### NeHe教程Qt实现——lesson12

NeHe 系列教程之十二： 显示列表

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
// 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++) {
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
}

#### Qt下使用OpenGL（23）-根据NeHe的教程改写的

2014-04-14 16:25:38

#### Nehe OpenGL教程第一课-创建一个OpenGL窗口(Win32)

2014-01-10 13:41:54

#### nehe的openGL教程（Qt版）

2015年02月12日 2.85MB 下载

#### 用OpenSceneGraph实现的NeHe OpenGL教程 - 第一课

2014-01-16 19:12:55

#### 【Qt OpenGL教程】资源文件

2015年08月03日 2.47MB 下载

#### 新手上路:Jeff Molofee(NeHe) 的 OPENGL 教程-第一课

2001-04-28 00:04:00

#### NeHe OpenGL中文教程+源代码

2011年06月19日 7.51MB 下载

#### NeHe的OpenGL教程

2010年04月07日 2.36MB 下载

#### opengl学习笔记1：vs2013 nehe教程第一课 创建窗口

2016-01-29 15:11:13

#### NeHe OpenGL系列教程（中英文版附带VC++源码）中英文系列

2013-12-16 10:25:53

## 不良信息举报

NeHe教程Qt实现——lesson12