Here's the standard method for a 3D game w/2D controls:

onSurfaceChanged:
this means you have a new GL context so it's a fresh state machine
ready to be configured.
set viewport and enable and configure things that will always be used,
like texturing, texture coordinate arrays, vert arrays, erase color,
etc
you can set your projection matrix here if it's going to be fixed
load textures, vbos and anything else into vram

onDrawFrame:
clear depth and color buffer
for dynamic projection (like if FoV or near/far clip plane can
change), switch to projection matrix, load identity and set.
switch to modelview matrix
set lookAt
enable depth test
// draw each totally opaque object sorted front to back
for (GameObject gameObject : sortedGameObjects) {
  push matrix
  draw opaque parts of the object
  pop matrix
}
// draw alpha blended parts of objects sorts back to front
enable blending
for (GameObject gameObject : sortedGameObjects) {
  push matrix
  draw alpha parts of the object
  pop matrix
}
// draw HUD
switch to projection matrix
push matrix
set ortho
switch to modelview matrix
push matrix
load identity
disable depth test
// draw HUD components in orthographic screen space
enable depth test
pop matrix
switch to projection matrix
pop matrix
// done - the way the matrix stack was handled here means the
projection and modelview are exactly as they were before the HUD was
drawn, so for the next frame, your projection doesn't need to be reset
unless it's dynamic (changing fov or near/far clip)


On Jun 27, 7:01 am, Navigateur <[email protected]> wrote:
> Can somebody take me step-by-step how to draw 2D stuff over a 3D scene
> (such as controls, etc.). What I've been doing so far has not been
> working (it only draws the 3D scene), which is (in every frame): draw
> the 3D scene as normal, projection matrix mode, load identity, call
> GLU.gluOrtho2D(gl, 0, myScreenWidthInPixels, 0,
> myScreenHeightInPixels), switch the array pointers (vertices and
> texture coords) to the ones for my 2D stuff, then drawElements with an
> appropriate index list. (then switch the array pointers back so the 3D
> stuff works again).
>
> I get nothing added to the screen (just the 3D stuff).
>
> Do I need to be doing something else for it to draw? Can somebody take
> me step-by-step?

-- 
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

Reply via email to