Hi,

I have a 3D game and I am using color-picking to know which object was
selected.

When the user touches the screen, I draw each object with a different color.
Then I read the color where the user touched the screen to know which object
was selected. After that I draw each object with their respective
textures/colors. (everything done during one onDrawFrame pass)

The problem is that sometimes the colored objects appear on the screen (~5%
of the times the user touches the screen) and it is even worse on slower
hardwares.

This is my pseudo code:

public void onDrawFrame(GL10 gl) {
if (user touched the screen) {
 gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
 gl.glMatrixMode(GL10.GL_MODELVIEW);

// DRAW COLORED OBJECTS

gl.glReadPixels(x, y, ......);
 // CHECK WHICH OBJECT WAS SELECTED
 gl.glColor4x(0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF);
 }

 gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
 gl.glMatrixMode(GL10.GL_MODELVIEW);

 // DRAW TEXTURED OBJECTS
}


As far as I understand, we always draw on the Back Buffer and only after we
finish, it swaps to the Front Buffer and updates the screen.
Is there anything wrong with the above code?

Thanks!


Thiago

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to