Hi folks,
I'm trying to dra an 2D scene with an image as background an some OpenGl objects on this background. And I'm using the glOrtho Projection because my application is only 2D. Now I've got the following problem: if I habe enabled the gloOrtho, my background image isn't displayed. If I draw my background image before enabling thoe glOrtho, the image is displayed only for ca 1 second. But the image is drawn correctly, if i didn't use the glOrtho like it is shown in the following source code where I've commented the part with the glOrtho. public void display(GLAutoDrawable drawable) { // TODO Auto-generated method stub final GL gl = drawable.getGL(); // Clear screen. gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); TextureCoords tc = tex.getImageTexCoords (); float tx1 = tc.left (); float ty1 = tc.top (); float tx2 = tc.right (); float ty2 = tc.bottom (); // Enable two-dimensional texturing. tex.enable (); // Bind this texture to the current rendering context. tex.bind (); //gl.glTexCoord2f (0, 0); gl.glBegin(GL.GL_QUADS); gl.glVertex3f (-1.0f, 1.0f, 1.0f); gl.glTexCoord2f (tx2, ty1); gl.glVertex3f (-1.0f, -1.0f, 1.0f); gl.glTexCoord2f (tx2, ty2); gl.glVertex3f (1.0f, -1.0f, 1.0f); gl.glTexCoord2f (tx1, ty2); gl.glVertex3f (1.0f, 1.0f, 1.0f); //gl.glColor3f(0, 0, 1); gl.glEnd(); tex.disable (); /* // #######################activation of glOrthomode!!!################## // y-Achse ist noch gespielgelt!!! gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, 624, 442, 0, -1, 1); gl.glMatrixMode(GL.GL_MODELVIEW); for (int i = 0; i < galaxy.getPlaneten().size(); i++) { gl.glBegin(GL.GL_POINTS); // gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glColor3f(galaxy.getPlaneten().get(i).getColor().getRed(), galaxy.getPlaneten().get(i).getColor().getGreen(), galaxy.getPlaneten().get(i).getColor().getBlue()); gl.glVertex2d(galaxy.getPlaneten().get(i).getxKoord(), galaxy .getPlaneten().get(i).getyKoord()); gl.glEnd(); } gl.glEnable(GL.GL_POINT_SMOOTH); gl.glPointSize((float) PLANETRADIUS); if (fleets.size() > 0) { drawFleets(gl); } */ } Does anybody know how I can use the gl.glTexCoord2f in the glOrtho mode ? Thanks in advance, Daniel |
Administrator
|
Maybe its just a depth/faceculling or lighting issue.
Have u tried disabling these ? gl.glDisable(GL.GL_DEPTH_TEST); gl.glDisable(GL.GL_CULL_FACE); Guess its worth a shot to see if this works. Also remember that OpenGL is as statemachine. Once u set a state u have to explicitly reset to its default state afterwards. I can't see that u restore/reset the state in ur display method. |
Hi,
thanks for your hints (statemachine ;-). I'm still not so firm with OpenGL. I've tried gl.glDisable(GL.GL_DEPTH_TEST) and gl.glDisable(GL.GL_CULL_FACE); but nothing changed. So I have search a lot in the internet and coded a new example. Now textures and glOrtho work fine. but I can't draw anythiong on my background image. I'm guessing that I have to load the Modelview matrix after drawing the quad with the texture. But I can't get it runnig.... Maybe you know the right instructions :-) Here is my display Method: public void display(GLAutoDrawable drawable) { // TODO Auto-generated method stub final GL gl = drawable.getGL(); // Clear screen. gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL.GL_PROJECTION); // Select Projection gl.glPushMatrix(); // Push The Matrix gl.glLoadIdentity(); // Reset The Matrix gl.glOrtho(0, 640, 480, 0, -1, 1); // Select Ortho Mode (640x480) gl.glMatrixMode(GL.GL_MODELVIEW); // Select Modelview Matrix gl.glPushMatrix(); // Push The Matrix gl.glLoadIdentity(); // Reset The Matrix // Enable two-dimensional texturing. tex.enable (); // Bind this texture to the current rendering context. tex.bind (); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f(0, 1); // Texture Coordinate ( 0, 1 ) gl.glVertex2f(0, 0); // First Vertex ( 0, 0 ) // Texture Coordinate ( 0, 0 ) gl.glTexCoord2f(0, 0 ); gl.glVertex2f(0, 480); // Second Vertex ( 0, 480 ) // Texture Coordinate ( 1, 0 ) gl.glTexCoord2f(1 , 0 ); gl.glVertex2f(640, 480); // Third Vertex ( 640, 480 ) // Texture Coordinate ( 1, 1 ) gl.glTexCoord2f(1 , 1 ); gl.glVertex2f(640, 0); // Fourth Vertex ( 640, 0 ) gl.glEnd(); tex.disable (); // this trinagle isn't shown gl.glBegin(GL.GL_TRIANGLES); gl.glColor3f(1,0,0); gl.glVertex2d(100,100); gl.glVertex2d(150,150); gl.glVertex2d(300,300); gl.glEnd(); } Thanks in advance! Greetings, Daniel |
Free forum by Nabble | Edit this page |