只是玩弄opengl
and glut
。我试图让立方体完全可见,所以我决定我可以用gluPerspective();
所以这里是代码
#include <iostream>
#include <GL/glut.h>
#include <GL/gl.h>
using namespace std;
float _angle = 0.1f;
void render(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluPerspective(90.0, 1, 0.1, 100.0);
gluLookAt(1, 1, 1, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
glPushMatrix();
glRotatef(_angle, 0.0f,0.0f,1.0f);
glColor3f(1.0f,0.0f,0.0f);
glutSolidCube (1.0);
glPopMatrix();
_angle +=0.03f;
// check OpenGL error
GLenum err;
while ((err = glGetError()) != GL_NO_ERROR) {
cerr << "OpenGL error: " << err << endl;
}
glutSwapBuffers();
glutPostRedisplay();
}
void init(){
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(640, 480);
glutCreateWindow("test");
glClearColor(0.2,0.2,0.2,0.0);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glutDisplayFunc(render);
glutMainLoop();
}
int main(int argc, char * argv[]) {
glutInit(&argc, argv);
init();
return 0;
}
这就是结果:
立方体的一部分看起来没有gluPerspective()
:
我怎样才能让它看起来正常?