我是openGL的新手,我面临着openGL的gluLookat函数的一些问题。我已经在glut窗口的左上角设置了原点。我将相机放置在原点处并试图查看我在原点创建的实心立方体,并将其转换为屏幕中心。无法理解gluLookat
int w = glutGet(GLUT_SCREEN_WIDTH);
int h = glutGet(GLUT_SCREEN_HEIGHT);
windowWidth = w * 2/3;
windowHeight = h * 2/3;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, windowWidth, windowHeight, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt (0.0, 0.0, 0.0, windowWidth/2, windowHeight/2, 0.0, 0.0, 0.0, 1.0); //Placing camera at the origin.
glPushMatrix(); // Set current matrix on the stack
glTranslatef (windowWidth/2, windowHeight/2, 0.0); // Translating it to the center of the screen
glutSolidSphere(5, 20,20); // creating the solid cube of radius 5
glPopMatrix(); // Pop the old matrix without the transformations.
glFlush();
I am not able to view the solid cube on the screen. What is wrong with this piece of code.
这看起来像C,而不是C++。不要为不同的语言添加标签。 – Olaf
我的不好!感谢编辑:) –