PDA

View Full Version : gllookat() not working!



12-12-2001, 06:32 PM
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();

yakuza
12-12-2001, 06:45 PM
Shouldn't you have a draw() of some sort after you set gluLookAt?

Spiral Man
12-12-2001, 07:18 PM
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...

12-12-2001, 07:37 PM
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?

yakuza
12-12-2001, 08:22 PM
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.

Questions Burner
12-12-2001, 08:28 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

Bob
12-13-2001, 02:33 AM
And another thing, DO NOT set the near Z-plane to zero when using perspective projection.

FoxDie
12-13-2001, 09:10 AM
Try to set the z-plane to 0.1f

endo
12-14-2001, 06:45 AM
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

Bob
12-14-2001, 01:19 PM
It's a mathematical problem, and I can't explain it very well (if at all http://www.opengl.org/discussion_boards/ubb/smile.gif ).

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.

DFrey
12-14-2001, 01:49 PM
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).]

Keermalec
12-16-2001, 10:56 AM
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

Bob
12-17-2001, 03:36 AM
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).