GLU.gluLookAt( ... ) not working

Started by
9 comments, last by 21st Century Moose 7 years, 3 months ago

A gremlin that gets rubbed in my face all the time is that i'm still using GL10. I'm going to sort that out later as the mechanics of other underlying code is complex enough and is keeping me extremely busy in other parts of the program.

In the mean time GLU.gluLookAt( cameraPosition, centreOfView, upDirection ) should still work. But however much i change the parameters of the camera position and the centre of view - the object drawn doesn't shift a bit

Here is the GL code, something must be wrong with the order of the code. Does any one know? Thanks and Happy new year

BTW this is GLES on Android platform


		@Override
		   public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
		       gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);  
		       gl.glClearDepthf(1.0f);            
		       gl.glEnable(GL10.GL_DEPTH_TEST);   
		       gl.glDepthFunc(GL10.GL_LEQUAL);   
		       gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);  
		       gl.glShadeModel(GL10.GL_SMOOTH);        
    		       gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
		 
		   } 
		 
			@Override
		   public void onSurfaceChanged(GL10 gl, int width, int height) { 
			   if (height == 0) height = 1;  
			   float aspect = (float)width / height;
			   gl.glViewport(0, 0, width, height);			
			   gl.glMatrixMode(GL10.GL_PROJECTION); 
			   gl.glLoadIdentity();                 
		     		  			  
			   GLU.gluPerspective(gl, 45, aspect, 0.1f, 100.0f);		
			   gl.glMatrixMode(GL10.GL_MODELVIEW);             
			   gl.glLoadIdentity();                 		
			   GLU.gluLookAt(gl,    0.0f, 6.0f, 0.0f,     0.0f, -6.0f, 0.0f,    0.0f, 1.0f, 0.0f);
		   } 
		 
			@Override
		   public void onDrawFrame(GL10 gl) { 
		     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 
		     gl.glMatrixMode(GL10.GL_MODELVIEW); 
		     gl.glLoadIdentity();
		     
		     cPuzzle.setByteBuffers();
		     cPuzzle.rotateObj(gl);
		     cPuzzle.drawObj(gl);
		   } 

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

Advertisement

Lookat can not be on a parallel line with your up vector. In short you cant look perfectly up and down. At least not with that up vector.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

Good point Slicer, so I changed the direction, (like I did several times already, in fact it was too much 'changelings' that got me to that odd direction in the first place) to


GLU.gluLookAt(gl,    0.0f, 0.0f, 5.0f,     0.0f, 0.0f, -5.0f,    0.0f, 1.0f, 0.0f);

and


GLU.gluLookAt(gl,    0.0f, 0.0f, -5.0f,     0.0f, 0.0f, 0.0f,    0.0f, 1.0f, 0.0f);  and

GLU.gluLookAt(gl,    0.0f, 0.0f, 5.0f,     0.0f, 0.0f, 0.0f,    0.0f, 1.0f, 0.0f);

but the problem remains - the view is not changing. So there is still something fundamentally wrong with the sequence/order of the code which I can't figure out

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

GLU.gluLookAt(gl, 0.0f, 6.0f, 0.0f, 0.0f, -6.0f, 0.0f, 0.0f, 1.0f, 0.0f);

Whats that gl for? I didn't know you could do that and I can't find an example.

ED: Nevermind, I just realized that wasn't c++

What 'gl' is for .... see documentation below

[attachment=34372:glu lookAt.jpg]

Still original problem remains unsolved, view doesn't change on changing gluLookAt ( ... ) camera position and centre of view

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

What I'm seeing is the modelView matrix is being set to identity at draw, overwriting the matrix state set by lookAt in onSurfaceChange.


What I'm seeing is the modelView matrix is being set to identity at draw, overwriting the matrix state set by lookAt in onSurfaceChange.

Thanks @[member='Goliath Forge'], so how can i fix it?

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

What do you mean? Don't overwrite your matrix set by glLookAt. If you need additional model transforms after you get this part working, you'd be looking toward glPushMatrix, glPopMatrix, glMultMatrixf and friends. Or move to modern opengl.

how could I use gluLookAt( ... ) effectively without causing an overwrite?

Like I said switching to modern GL is on the agenda, but in the current order of things the view change needs to be changeable first, thnx

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

gluLookAt is not what's causing the overwrite.

Look at your code again. In onSurfaceChanged you have this:


			   gl.glMatrixMode(GL10.GL_MODELVIEW);             
			   gl.glLoadIdentity();                 		
			   GLU.gluLookAt(gl,    0.0f, 6.0f, 0.0f,     0.0f, -6.0f, 0.0f,    0.0f, 1.0f, 0.0f);

In onDrawFrame you have this:


		     gl.glMatrixMode(GL10.GL_MODELVIEW); 
		     gl.glLoadIdentity();

So onDrawFrame is what's overwriting the matrix. The solution is to remove those two lines from onDrawFrame.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement