Issue about textures and glOrtho
Posted by Daniel S. on Mar 14, 2011; 11:35am
URL: https://forum.jogamp.org/Issue-about-textures-and-glOrtho-tp2675799.html
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