开发者

gluLookAt() makes blank screen

I don't have much OpenGL experience. I am trying to draw a teapot and move a camera around the teapot. To this end I am using the gluLookAt function. The problem is that when I call gluLookAt the screen is blank and I can't see my teapot.

#include "openGLer.h"

void openGLer::simulate(grid* toSim, int* argc, char** argv)
{
    myGrid = toSim;
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(400, 400); //Set the window size
    glutCreateWindow("");
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutKeyboardFunc(handleKeypress);
    glEnable(GL_DEPTH_TEST);
    glutMainLoop();
}

void openGLer::handleKeypress(unsigned char key, //The key that was pressed
                              int x, int y)
{
    switch (key)
    {
    case 27: exit(0);
    }
}

void openGLer::camera()
{
    gluLookAt(3, 3, 0,
            开发者_C百科  0, 0, 0,
              0, 1, 0
              );
}

void openGLer::draw()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    camera();
    glutWireTeapot(0.5);
    glutSwapBuffers();
}

void openGLer::display()
{
    draw();
}

Why does gluLookAt() make the screen blank and how do I fix this? When camera() is not called code performs as expected; with a teapot being displayed.


Have you set up your projection matrix correctly? Otherwise, your call to gluLookAt will cause the teapot to be too far away and therefore be clipped by the far plane.

Try adding this to your initialization code (and also your resize handler to fix the aspect ratio when the window is resized). I've set the far plane at 100, which should be plenty for your teapot.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective (60.0, width/(float)height, 0.1, 100.0);
glMatrixMode(GL_MODELVIEW);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜