Sign in to follow this  

GLU.gluLookAt( ... ) not working

Recommended Posts

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);
		   } 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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++ Edited by fleabay

Share this post


Link to post
Share on other sites

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 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

 

Perfect!!!  Just tested it now and that was the reason for the view not changing.  Many thanks  @mhagain

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this