PushMatrix/PopMatrix

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

PushMatrix/PopMatrix

AlexRNL
Hi everyone!

I am currently working with JOGL 1.1 and i'm running into a problem and I hope you could help :)

I'm trying to draw 2 simple objects using the couple gl.glPushMatrix() & glPopMatrix() to draw them independently.

But it doesn't seem to work: the first one is draw correctly but the second one is not visble. And when I remove the calls to Push/PopMatrix i can see my 2 triangles in my scene.

Here's the drawing code :
	gl.glMatrixMode(GL.GL_MODELVIEW);
	gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
	gl.glLoadIdentity();

	gl.glPushMatrix();
		gl.glTranslatef(offsetX, offsetY, zoom);
		gl.glRotatef(xRot, 1.0f, 0.0f, 0.0f);
		gl.glRotatef(yRot, 0.0f, 1.0f, 0.0f);
		gl.glRotatef(zRot, 0.0f, 0.0f, 1.0f);
		gl.glBegin(GL.GL_TRIANGLES);
			gl.glColor3f(1, 1, 0); gl.glVertex3f(0, 0, 1);
			gl.glColor3f(0, 1, 1); gl.glVertex3f(5, 0, -1);
			gl.glColor3f(1, 0, 1); gl.glVertex3f(5, 5, 0);
		gl.glEnd();
	gl.glPopMatrix();

	gl.glPushMatrix();
		gl.glTranslatef(2.0f, 1.5f, 0.0f);
		gl.glBegin(GL.GL_TRIANGLES);
			gl.glColor3f(1, 0, 0); gl.glVertex3f(0, 0, 1);
			gl.glColor3f(0, 1, 0); gl.glVertex3f(5, 0, -1);
			gl.glColor3f(0, 0, 1); gl.glVertex3f(5, 5, 0);
		gl.glEnd();	
	gl.glPopMatrix();

Any clues why this is not working?
Reply | Threaded
Open this post in threaded view
|

Re: PushMatrix/PopMatrix

Wade Walker
Administrator
It's probably working, just not doing what you expect it to  For example, depending on where your camera is and what direction it's facing, it could be that the with the push/pop in place, the zoom factor makes the first triangle visible but not the second. So then when you take push/pop out, the zoom is applied to both, and you can now see them both.

I'd advise resetting the values in the translate/rotate statements to zero, then gradually changing them so you can get a feel for what's going on.
Reply | Threaded
Open this post in threaded view
|

Re: PushMatrix/PopMatrix

AlexRNL
Wade Walker wrote
It's probably working, just not doing what you expect it to  For example, depending on where your camera is and what direction it's facing, it could be that the with the push/pop in place, the zoom factor makes the first triangle visible but not the second. So then when you take push/pop out, the zoom is applied to both, and you can now see them both.

I'd advise resetting the values in the translate/rotate statements to zero, then gradually changing them so you can get a feel for what's going on.

Thanks a lot!
Didn't think it was that simple... feel kind of stupid right now
Reply | Threaded
Open this post in threaded view
|

Re: PushMatrix/PopMatrix

Wade Walker
Administrator
No reason to feel stupid -- I've been doing this a long time, and still it seems like every 3D program I ever write comes up with a black screen the first time I run it  And it's usually the same few issues:

- My camera is (behind/facing away from/inside of/too far from/too near) the scene
- The lights are off
- My vertices are clockwise instead of counter-clockwise
- I'm looking at the back side of single-sided polys
- My matrices/transforms are not set up right

I think 3D programs are just inherently hard to debug, since the graphics hardware is a black box that you can't see inside of.
Reply | Threaded
Open this post in threaded view
|

Re: PushMatrix/PopMatrix

AlexRNL
Wade Walker wrote
No reason to feel stupid -- I've been doing this a long time, and still it seems like every 3D program I ever write comes up with a black screen the first time I run it  And it's usually the same few issues:

- My camera is (behind/facing away from/inside of/too far from/too near) the scene
- The lights are off
- My vertices are clockwise instead of counter-clockwise
- I'm looking at the back side of single-sided polys
- My matrices/transforms are not set up right
Nice checklist  I'll try to keep it in mind for the future !

Wade Walker wrote
I think 3D programs are just inherently hard to debug, since the graphics hardware is a black box that you can't see inside of.
Indeed, they are...