PDA

View Full Version : gluLookAt is not responding



pontifikas
08-11-2009, 02:25 AM
I've been trying to set my OpenGL scene and I can't get gluLookAt to work. The following function is called whenever a change in the parameters of the gluLookAt(or gluPerspective) function occurs


int err = Gl.GL_NO_ERROR;

try
{
//Set the new Viewport Parameters
Gl.glViewport(0, 0, DeviceFrameSize.Width, DeviceFrameSize.Height);

Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Glu.gluPerspective(Projection.fovy, Projection.aspect, Projection.zNear, Projection.zFar);

Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
Glu.gluLookAt(LookAt.eyeX, LookAt.eyeY, LookAt.eyeZ,
LookAt.centerX, LookAt.centerY, LookAt.centerZ,
LookAt.upX, LookAt.upY, LookAt.upZ);

err = Gl.glGetError();
if (err != Gl.GL_NO_ERROR) throw new Exception(Glu.gluErrorString(err));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

Every call of the above is followed by the call of the drawing function below


int err = Gl.GL_NO_ERROR;

try
{
// Clear the window with current clearing color
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

Gl.glPushMatrix();
Gl.glLoadIdentity();

Gl.glTranslatef(0, 0, -7);//Move the object inside the frustrum
/*DRAWING A CUBE HERE*/
Gl.glPopMatrix();

err = Gl.glGetError();
if (err != Gl.GL_NO_ERROR) throw new Exception(Glu.gluErrorString(err));
}
catch (Exception ex)
{
string er = ex.Message;
}

And a SwapBuffers after that.
The initial values of the projection and lookat parameters are:


public const double InitialProjectionFovy = 45.0;
public const double InitialProjectionZNear = 1.0;
public const double InitialProjectionZFar = 500.0;

public const double InitialLookAtEyeX = 0.0;
public const double InitialLookAtEyeY = 0.0;
public const double InitialLookAtEyeZ = 10.0;

public const double InitialLookAtCentreX = 0.0;
public const double InitialLookAtCentreY = 0.0;
public const double InitialLookAtCentreZ = 0.0;

public const double InitialLookAtUpX = 0.0;
public const double InitialLookAtUpY = 1.0;
public const double InitialLookAtUpZ = 0.0;

By running the application under the debugger I can verify that value changes are passed correctly and that no glLoadIdentity occurs after gluLookAt is called.
However, while changes in the parameters of the gluPerspective are reflected on the screen, gluLookAt appears irresponsive to it's parameter changes.

Any suggestions?
I thank you in advance!

EDIT: It seems weird but I tried performing some translations (instead of gluLookAt) after calling Gl.glMatrixMode(Gl.GL_MODELVIEW); and Gl.glLoadIdentity(); and also before calling PushMatrix in the Drawing function but they had no effect. The translation though inside the push-popMatrix compound and some others I added work fine!!As if the system ignores all modelview transformations outside glPush-PopMatrix

datsua
08-11-2009, 05:25 AM
You should remove the Gl.glLoadIdentity() from your drawing function as this resets the modelview matrix to identity.

pontifikas
08-11-2009, 11:53 PM
This is embarrassing...I had the silly notion that putting LoadIdentity inside push-popMatrix would be "eliminated".

I thank you datsua.

pontifikas
08-17-2009, 12:53 PM
EDIT: I found what I was asking for. No further questions