Re: Using JOGL to Draw on 2D Coordinates
Posted by JOGLn00b on Oct 03, 2013; 3:27pm
URL: https://forum.jogamp.org/Using-JOGL-to-Draw-on-2D-Coordinates-tp4030146p4030148.html
Thanks for the reply, it helped a lot :).
Yeah you are right, i am pretty new to this openGL stuff but i spent the last 2 days reading and watching tutorials and examples. in the documentation and/or an article i even read that i have to use gl.glMatrixMode(gl.GL_PROJECTION) :D
the reason why i did not use it was because i did not see anything if i used it. but i was able to fix this problem even though i dont understand why it works and now i have two other questions:
if i use the following method and use negative values in the z-variable, i can see the quads i want to draw, but i gave a positive value for glOrtho in order to create a clipping plane there... obisously the code works, i just dont know why because i think the quads are out of render-range(if i might call it like this :D)
my second question is, why is the blue quad in front of the red one, no matter what z-coordinate i give it? the one drawn last (in the code) always gets rendered in front :/.
propably its because i forgot to put some mode, but i dont know where to read what i need to change. in all the documentaries i read it was just said that the quad, that is nearest to the eye/camera, is in front.
thanks for your help, it brought me quite a bit further already :)
Edit: never mind, i forgot to enable depth test :P, thanks anyways
@Override
public void display(GLAutoDrawable drawable) {
// TODO Auto-generated method stub
final GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity(); // Reset The View
//gl.glViewport(0, 0, 800, 600);
gl.glOrtho(0, 800, 600, 0, 0, 128);
int x = 100;
int y = 100;
gl.glColor3f(1,0,0);;
gl.glBegin (GL2.GL_QUADS);
gl.glVertex3f ( 0.0f, 0.0f, -1.0f);
gl.glVertex3f ( x, 0.0f, -1.0f);
gl.glVertex3f ( x, y, -1.0f);
gl.glVertex3f ( 0.0f, y, -1.0f);
gl.glColor3f(0,0,1);
gl.glVertex3f ( 0.0f, 0.0f, -2.0f);
gl.glVertex3f ( 2*x, 0.0f, -2.0f);
gl.glVertex3f ( 2*x, 2*y, -2.0f);
gl.glVertex3f ( 0.0f, 2*y, -2.0f);
gl.glEnd ();
gl.glFlush();
}