Hi,
I just started to learn JOGL, so i wanted to create some easy 2D Quads. I read about the command gl.glOrtho but it does not work as i expect it to do. I want to draw the turquoise quad in the back just from the upper left corner to the bottom right (from coordinate (0|0) to (600|800)). Also in my opinion the red quad should be just in front of the blue one, so you should only see the red one. I would like to know how to draw on specific coordinates and how to initialize such a coordinate system properly and the orthographic view :) Thanks for every help :) @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(gl.GL_MODELVIEW); gl.glLoadIdentity(); // Reset The View int x = 100; int y = 100; gl.glViewport(0, 0, 800, 600); gl.glOrtho(0, 800, 0, 600, 0, 128); x = 800; y = 600; gl.glColor3f(0,1,1);; gl.glBegin (GL2.GL_QUADS); gl.glVertex3f ( 0, 0, 128.0f); gl.glVertex3f ( x, 0, 128.0f); gl.glVertex3f ( x, y, 128.0f); gl.glVertex3f ( 0, y, 128.0f); gl.glEnd (); x = 100; y = 100; gl.glColor3f(1,0,0);; gl.glBegin (GL2.GL_QUADS); gl.glVertex3f ( 0.0f, 0.0f, 100.0f); gl.glVertex3f ( x, 0.0f, 100.0f); gl.glVertex3f ( x, y, 100.0f); gl.glVertex3f ( 0.0f, y, 100.0f); gl.glEnd (); gl.glColor3f(0,0,1);; gl.glBegin (GL2.GL_QUADS); gl.glVertex3f ( 0.0f, 0.0f, 110.0f); gl.glVertex3f ( x, 0.0f, 110.0f); gl.glVertex3f ( x, y, 110.0f); gl.glVertex3f ( 0.0f, y, 110.0f); gl.glEnd (); gl.glFlush(); } |
Administrator
|
Hi
You have to select the projection matrix and use glOrtho. What is wrong with this method? As long as your quads are in your frustum, they are visible. Edit.: Your code is wrong, you call glOrtho when the model view matrix is the active matrix. I advise you to learn the basics of OpenGL, maybe look at the Red Book. Its examples have been ported to JOGL and are available on our Github repository.
Julien Gouesse | Personal blog | Website
|
This post was updated on .
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(); } |
Administrator
|
Hi
Actually, you don't need to modify your projection matrix at each display, you should rather use the init() method to initialize OpenGL. The projection matrix defines the projection, both the kind of projection (orthogonal, perspective) and the frustum. The model-view matrix defines where and how you look at. In your case, the default values of the model-view matrix are ok. OpenGL isn't the kind of thing you can learn within days, keep it in mind. I advise you to look at Nehe tutorials too even though they are a bit outdated. You use immediate mode which is very slow. It's enough for pedagogical purposes but I advise you to learn about vertex arrays and VBOs. Moreover, you use the fixed pipeline, I hope you plan to learn how to use shaders when you feel comfortable with the basic concepts.
Julien Gouesse | Personal blog | Website
|
Free forum by Nabble | Edit this page |