gllookat() not working!

for some reason my call to gllookat() does absolutely nothing? anyone have any ideas, here is the code im using now…
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,1,0,2,2,0,0,1,0);
glFlush();

Shouldn’t you have a draw() of some sort after you set gluLookAt?

also, you dont post any other code. are you drawing to a double buffered display, if you are, you need to swap the buffers instead of calling glFlush(). also, you dont show how you set up your projection matrix, perhaps that is the problem, or any of your other drawing code that you havent posted…

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gluPerspective(45.0, 1.0, 0.0, 500.0);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,-1.0 ,0.0,0.0,0.0 ,0.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
draw();
return TRUE;

thats the whole draw func, can anyone help now?

I could be mistaken (OpenGL newbie myself), but I think you want to load the identity for the projection matrix before you setup gluPerspective(). I also don’t think you need to call that every time you draw, only if the window is resized.

Try the following code

void draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Render something
glFlush();
}

void resize(GLsizei width, GLsizei height)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, width, height);
gluPerspective(60, 1, 1, 30);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
}

Where resize() only call when your scene is being resized and you program start. And draw() call when you need to draw or redraw something. I think calling glMatrixMode() and glLoadIdentity() when rendering scene is redundant.

Hope this help

And another thing, DO NOT set the near Z-plane to zero when using perspective projection.

Try to set the z-plane to 0.1f

Probably a silly question - by why not set it to zero?

ps I’m still new to this, so dont shout at me if it is a silly question please

It’s a mathematical problem, and I can’t explain it very well (if at all ).

To understand the problem, you have to know how perspective projections with homogenous coordinates works. Basically, what happens is that you project all the vertices into one single point (a singularity I believe), and you cannot get them out of there again, since all vertices all become the same. You need to project them to a plance near this point. This way, you can keep them apart, but still project them towards this point. You must keep them apart, otherwise you cannot transform them to the viewport.

Imagine a frustum, with your eye at the apex of the frustum, looking down the axis of frustum. Now, Znear specifies the position of the ‘screen’ along the axis to which points beyond the screen are projected onto. If Znear was 0, the ‘screen’ would be coincident with your eye, and all points beyond the ‘screen’ get projected onto a single point. Basically, the math falls apart because you end up trying to divide by 0 if you set Znear to 0.

[This message has been edited by DFrey (edited 12-14-2001).]

here’s my code:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLightfv(GL_LIGHT0,GL_POSITION,lPosition);
glPushMatrix();
glLoadIdentity();
gluLookAt(pt0.x, pt0.y, pt0.z, pt0.x + lx, pt0.y + ly, pt0.z + lz, 0.0f, 1.0f, 0.0f);
glPopMatrix();
glutSwapBuffers( );

I am not sure you can have 0,0,0 for parameters 3, 4, and 5 as this means the observer is looking no-where. try setting them to 1,0,0

If you set parameter 3, 4 and 5 to the vector (0,0,0) you are looking at the world origin, which is perfectly valid. These three parameters tells gluLookAt at which point you are looking, not in which direction you are looking (if that was the case, the zero vector would be pointless).