I am creating a HUD by drawing text and controls on a transparent BufferedImage, creating a texture from it and rendering it on a rectangle using orthographic projection.
It basically works, but I can’t work out how to do the scaling. What I want ideally is to create an image the same pixel size as the window, and have it scaled so it exactly fills the window.
Here is the code (JOGL)
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();
getTexture creates and binds the texture. Any hints on how to scale it?
I find that I need to do a translate in the negative z direction to see anything. The smaller that translation, the bigger the image except that for values smaller in magnitude than -5 the texture disappears.