Default "camera" position when starting application

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

Default "camera" position when starting application

saps
Hello, I have probably very basic question and I am not fully sure where does it belong, but since I am learning using JOGL I will ask it here. Basically I have triangle rendered on the screen using very basic example:
gl2.glBegin(GL2.GL_TRIANGLES);
gl2.glColor3f(1.0f, 0.0f, 0.0f);
gl2.glVertex3f(-0.5f, -0.5f,  0.0f);
gl2.glVertex3f( 0.5f, -0.5f,  0.0f);
gl2.glVertex3f(-0.5f,  0.5f,  0.0f);
gl2.glEnd();

It is displaying correctly as I expect the red triangle. Now if I add another one at exactly the same position, but with z = -0.5f for each vertex (with green color for example). I see green colored triangle displayed over the red one. I would like to understand why? The coordinate system suggest that the negative Z should be placing objects further in the space, but it looks like it is not true.

I am not applying any projection, the diplay() method is composed soloely by the two triangles and the:
gl2.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

In init() method I do enable the depth test.
gl2.glEnable(GL2.GL_DEPTH_TEST);
gl2.glDepthMask(true);

So why in this case I see the green triangle over the red one and not the other way around (which seems more logical according to the coordinate system explanations I have read in multiple sites)?
Reply | Threaded
Open this post in threaded view
|

Re: Default "camera" position when starting application

gouessej
Administrator
Hi

I advise you to read this tutorial, especially the parts about the model, view and projection matrices:
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/
Julien Gouesse | Personal blog | Website