绘制正方体

#include <GL/glut.h>
void display();
void init();
void display() 
{ 
 glClear(GL_COLOR_BUFFER_BIT); 
 glMatrixMode(GL_MODELVIEW); 
    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
  glutWireCube(1.0);
    glPopMatrix();
 glutSwapBuffers();
 glFlush();
} 
//init the window
void init() 
{ 
 glClearColor(1.0,1.0,1.0,1.0); 
    glColor3f(0.0,0.0,0.0);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 glOrtho(1.0,1.0,0.0,1.0,-1.0,1.0);
}
//the program starts here
int main(int argc,char** argv) 
{ 
 glutInit(&argc,argv); 
 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 
 glutInitWindowSize(500,500); 
 glutInitWindowPosition(0,0); 
 glutCreateWindow("cube");
 init();
 glutDisplayFunc(display); 
 glutMainLoop(); 
}
/*
是立体图形,只是你采用了平行投影来观察,且视点设在与立方体的侧面垂直的位置上,故只能看到一个面。 
建议改变视点,或者对立方体先做旋转45度,
*/

你可能感兴趣的:(OpenGL)