Thanks for the advice, guys. Googling "OpenGL HUD" is a step in the
right direction for anyone else looking to do this. Here's some quick
code:
private void viewOrtho2(GL10 gl, int x, int y)
{
// Set Up An Ortho View
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glMatrixMode(GL10.GL_PROJECTION); // Select Projection
gl.glPushMatrix(); // Push The Matrix
gl.glLoadIdentity(); // Reset The Matrix
gl.glOrthof(0, x, 0, y, -5, 1); // Select Ortho Mode
gl.glMatrixMode(GL10.GL_MODELVIEW); // Select Modelview Matrix
gl.glLoadIdentity(); // Reset The Matrix
// This fixes some 2D perspective issues
gl.glTranslatef(0.375f, 0.375f, 0.375f);
}
Test it out with some squares:
private void testmethod(GL10 gl)
{
ByteBuffer vbb =
ByteBuffer.allocateDirect(squareVertices.length *
4);
vbb.order(ByteOrder.nativeOrder());
FloatBuffer vertexBuffer = vbb.asFloatBuffer();
vertexBuffer.put(squareVertices);
vertexBuffer.position(0);
gl.glLineWidth(3.0f);
gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f); // blue
gl.glTranslatef(5.0f, 0.0f, 0.0f);
gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4);
gl.glTranslatef(100.0f, 0.0f, 0.0f);
gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); // Red
gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4);
gl.glTranslatef(100.0f, 0.0f, 0.0f);
gl.glColor4f(1.0f, 1.0f, 0.0f, 1.0f); // Yellow
gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4);
// Switch back to the previous view
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL10.GL_MODELVIEW);
}
This essentially shows how, even in a 3D display, you can switch to a
2D projection. Key lines of code:
gl.glOrthof(0, x, 0, y, -5, 1); // Select Ortho Mode by mapping (0,0)-
(width,height) (320x480)
gl.glDisable(GL10.GL_DEPTH_TEST); // Remove 3D depth testing
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en