前面一直在画二维图形,其实三维图形的绘制就是以其为基础,可以说二维不过是三维的一种特例(相当与Z=0)。比如说要画一个正方体,它有上下左右前后共六个面组成,也就是要画出六个正方形就可以了,只是要注意绘制时应该按逆时针绘制(好像是进行纹理映射时需要的。。。)

     

      我们必须将OpenGL屏幕想象成一张很大的画纸,后面还带着许多透明的层。差不多就是个由大量的点组成的立方体。这些点从左至右、从上至下、从前到后的布满了这个立方体。如果能想象的出在屏幕的深度方向,就应该在设计新3D对象时没有任何问题。


None.gifint DrawGLScene(GLvoid)                                
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    glClear(GL_COLOR_BUFFER_BIT 
| GL_DEPTH_BUFFER_BIT);    
InBlock.gif    glLoadIdentity();                                
InBlock.gif    glTranslatef(
-1.5f,0.0f,-6.0f);                        
InBlock.gif    glRotatef(rtri,
0.0f,1.0f,0.0f);                    
InBlock.gif    glBegin(GL_TRIANGLES);                                
InBlock.gif        glColor3f(
1.0f,0.0f,0.0f);                        
InBlock.gif        glVertex3f( 
0.0f1.0f0.0f);                    
InBlock.gif        glColor3f(
0.0f,1.0f,0.0f);                        
InBlock.gif        glVertex3f(
-1.0f,-1.0f1.0f);                    
InBlock.gif        glColor3f(
0.0f,0.0f,1.0f);                        
InBlock.gif        glVertex3f( 
1.0f,-1.0f1.0f);                
InBlock.gif
InBlock.gif        glColor3f(
1.0f,0.0f,0.0f);                        
InBlock.gif        glVertex3f( 
0.0f1.0f0.0f);                
InBlock.gif        glColor3f(
0.0f,0.0f,1.0f);                        
InBlock.gif        glVertex3f( 
1.0f,-1.0f1.0f);                
InBlock.gif        glColor3f(
0.0f,1.0f,0.0f);                    
InBlock.gif        glVertex3f( 
1.0f,-1.0f-1.0f);                
InBlock.gif
InBlock.gif        glColor3f(
1.0f,0.0f,0.0f);                        
InBlock.gif        glVertex3f( 
0.0f1.0f0.0f);                    
InBlock.gif        glColor3f(
0.0f,1.0f,0.0f);                    
InBlock.gif        glVertex3f( 
1.0f,-1.0f-1.0f);                    
InBlock.gif        glColor3f(
0.0f,0.0f,1.0f);                    
InBlock.gif        glVertex3f(
-1.0f,-1.0f-1.0f);                
InBlock.gif
InBlock.gif        glColor3f(
1.0f,0.0f,0.0f);                    
InBlock.gif        glVertex3f( 
0.0f1.0f0.0f);                
InBlock.gif        glColor3f(
0.0f,0.0f,1.0f);                        
InBlock.gif        glVertex3f(
-1.0f,-1.0f,-1.0f);                
InBlock.gif        glColor3f(
0.0f,1.0f,0.0f);                        
InBlock.gif        glVertex3f(
-1.0f,-1.0f1.0f);                
InBlock.gif        glColor3f(
0.0f,1.0f,0.0f);
InBlock.gif        glVertex3f(
-1.0f,-1.0f,1.0f);
InBlock.gif        glColor3f(
0.0f,0.0f,1.0f);
InBlock.gif        glVertex3f(
1.0f,-1.0f,1.0f);
InBlock.gif        glColor3f(
0.0,1.0f,0.0f);
InBlock.gif        glVertex3f(
1.0f,-1.0f,-1.0f);
InBlock.gif        glColor3f(
0.0f,0.0f,1.0f);
InBlock.gif        glVertex3f(
-1.0f,-1.0f,-1.0f);
InBlock.gif    glEnd();                                        
InBlock.gif
InBlock.gif    glLoadIdentity();                                
InBlock.gif    glTranslatef(
1.5f,0.0f,-7.0f);                        
InBlock.gif    glRotatef(rquad,
1.0f,1.0f,1.0f);                
InBlock.gif    glBegin(GL_QUADS);                                
InBlock.gif        glColor3f(
0.0f,1.0f,0.0f);                        
InBlock.gif        glVertex3f( 
1.0f1.0f,-1.0f);                
InBlock.gif        glVertex3f(
-1.0f1.0f,-1.0f);                
InBlock.gif        glVertex3f(
-1.0f1.0f1.0f);                    
InBlock.gif        glVertex3f( 
1.0f1.0f1.0f);                    
InBlock.gif
InBlock.gif        glColor3f(
1.0f,0.5f,0.0f);                    
InBlock.gif        glVertex3f( 
1.0f,-1.0f1.0f);                
InBlock.gif        glVertex3f(
-1.0f,-1.0f1.0f);                
InBlock.gif        glVertex3f(
-1.0f,-1.0f,-1.0f);                    
InBlock.gif        glVertex3f( 
1.0f,-1.0f,-1.0f);                
InBlock.gif
InBlock.gif        glColor3f(
1.0f,0.0f,0.0f);                    
InBlock.gif        glVertex3f( 
1.0f1.0f1.0f);                
InBlock.gif        glVertex3f(
-1.0f1.0f1.0f);                
InBlock.gif        glVertex3f(
-1.0f,-1.0f1.0f);                
InBlock.gif        glVertex3f( 
1.0f,-1.0f1.0f);            
InBlock.gif        glColor3f(
1.0f,1.0f,0.0f);                    
InBlock.gif        glVertex3f( 
1.0f,-1.0f,-1.0f);                
InBlock.gif        glVertex3f(
-1.0f,-1.0f,-1.0f);                
InBlock.gif        glVertex3f(
-1.0f1.0f,-1.0f);                
InBlock.gif        glVertex3f( 
1.0f1.0f,-1.0f);                    
InBlock.gif
InBlock.gif        glColor3f(
0.0f,0.0f,1.0f);                    
InBlock.gif        glVertex3f(
-1.0f1.0f1.0f);                
InBlock.gif        glVertex3f(
-1.0f1.0f,-1.0f);                
InBlock.gif        glVertex3f(
-1.0f,-1.0f,-1.0f);                
InBlock.gif        glVertex3f(
-1.0f,-1.0f1.0f);                
InBlock.gif
InBlock.gif        glColor3f(
1.0f,0.0f,1.0f);                    
InBlock.gif        glVertex3f( 
1.0f1.0f,-1.0f);                
InBlock.gif        glVertex3f( 
1.0f1.0f1.0f);                
InBlock.gif        glVertex3f( 
1.0f,-1.0f1.0f);                    
InBlock.gif        glVertex3f( 
1.0f,-1.0f,-1.0f);                
InBlock.gif    glEnd();                                        
InBlock.gif
InBlock.gif    rtri
+=0.2f;                                            
InBlock.gif    rquad
-=0.15f;                                        
InBlock.gif    
return TRUE;                                        
ExpandedBlockEnd.gif}


200741702.JPG