|
I am trying to create a hud using the technique of drawing on a BufferedImage, then using the image as a texture on a rectangle. I render the rectangle in orthographic mode. The parts of the image which don't contain controls are transparent so the 3D world can be seen.
Well it works fine, but I can't work out how to scale things so the image exactly fills the screen. Ideally I would like the buffered image to be exactly the size of the window, so items are placed on the screen exactly as if they were using Java2D.
Here is my code:
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -5.0f);
gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
gl.glOrtho(-1, 1, -1, 1, -1.0, 1.0);
getTexture(gl, 128, 128);
gl.glBegin(GL.GL_POLYGON);
gl.glTexCoord2d(0f, 0f);
gl.glVertex2f(-0.5f, -0.5f);
gl.glTexCoord2d(1, 0f);
gl.glVertex2f(-0.5f, 0.5f);
gl.glTexCoord2d(1, 1);
gl.glVertex2f(0.5f, 0.5f);
gl.glTexCoord2d(0f, 1);
gl.glVertex2f(0.5f, -0.5f);
gl.glEnd();
I am also finding that if I don't do a glTranslatef, or if the translation is too small (eg -4) the polygon is not visible at all.
Anyone have an example of how to do this?
|