具体代码如下:为什么我用glutWireCube函数却画除了平面图形,而不是立方体呢

#include <GL/glut.h>
#include <stdlib.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(); 
}

神不在的星期二
浏览 123回答 2
2回答

蛊毒传说

是立体图形,只是你采用了平行投影来观察,且视点设在与立方体的侧面垂直的位置上,故只能看到一个面。&nbsp;建议改变视点,或者对立方体先做旋转45度,

繁星点点滴滴

帮你修改的代码#include <windows.h>&nbsp;&nbsp;#include <gl/glut.h>void init(void){glClearColor(0.0,0.0,0.0,0.0);glShadeModel(GL_FLAT);}void display(void){glClear(GL_COLOR_BUFFER_BIT);glPushMatrix();glPushMatrix();glutWireCube(1.0);glPopMatrix();glPopMatrix();glutSwapBuffers();}void reshape(int w, int h){glViewport(0,0,(GLsizei)w,(GLsizei)h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(65.0,(GLfloat)w/(GLfloat)h,1.0,20.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0,0.0,-5.0);}int main(int argc, char ** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);glutInitWindowSize(500,500);glutInitWindowPosition(100,100);glutCreateWindow("cube");init();glutDisplayFunc(display);glutReshapeFunc(reshape);glutMainLoop();return 0;}
打开App,查看更多内容
随时随地看视频慕课网APP