为了账号安全,请及时绑定邮箱和手机立即绑定

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

具体代码如下:为什么我用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 windowvoid 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 hereint 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(); }
查看完整描述

2 回答

?
蛊毒传说

TA贡献1895条经验 获得超3个赞

是立体图形,只是你采用了平行投影来观察,且视点设在与立方体的侧面垂直的位置上,故只能看到一个面。 

建议改变视点,或者对立方体先做旋转45度,


查看完整回答
反对 回复 2023-02-20
?
繁星点点滴滴

TA贡献1803条经验 获得超3个赞

帮你修改的代码
#include <windows.h>  
#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;
}


查看完整回答
反对 回复 2023-02-20
  • 2 回答
  • 0 关注
  • 122 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信