1
我想使用OpenGL繪製3D立方體這是我的新代碼如何糾正錯誤........................ .................................................. .....使用Opengl繪製立方體3D
float ver[8][3] =
{
{-1.0,-1.0,1.0},
{-1.0,1.0,1.0},
{1.0,1.0,1.0},
{1.0,-1.0,1.0},
{-1.0,1.0,-1.0},
{1.0,1.0,-1.0},
};
GLfloat color[8][3] =
{
{0.0,0.0,0.0},
{1.0,0.0,0.0},
{1.0,1.0,0.0},
{0.0,1.0,0.0},
{1.0,1.0,1.0},
{0.0,1.0,1.0},
};
void quad(int a,int b,int c,int d)
{
glBegin(GL_QUADS);
glColor3fv(color[a]);
glVertex3fv(ver[a]);
glColor3fv(color[b]);
glVertex3fv(ver[b]);
glColor3fv(color[d]);
glVertex3fv(ver[d]);
glEnd();
}
void colorcube()
{
quad(0,3,2,1);
quad(2,3,7,6);
}
void display(){
// Clear screen and Z-buffer
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
colorcube();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(640, 480);
glutCreateWindow("GLUT");
glutDisplayFunc(display);
glutDisplayFunc(specialKeys);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 0;
}