views:

139

answers:

1

I'm looking into 3D on the iPhone, I have managed to get a 3D cube on the device but would like to add interactivity such as touching one face fires a specific event and an other face a different event. I'd rather steer clear of ray picking as this adds extra complexity that I do not want in my app.

I've read up on quite a few color picking tutorials, but there doesn't seem to be any iPhone specific tutorials or sample code anywhere on the web.

My main problem is drawing unique colored objects to the back buffer and textured objects to the front buffer, never showing the unique colored objects to the user but detecting the color of the pixel touched from the back buffer.

So my question is can anyone point me in the direction of an Objective-C tutorial or post some sample code?

Any help or advice would be much appreciated.

+1  A: 

OK, so after 18 hours I've finally fixed my issue. In the render method all I had to do was prevent the presentRenderbuffer call when the render was in SELECT mode. I could kick myself right now!

if (mode == SELECT) {
    glDisable(GL_DITHER);
    glDisable(GL_LIGHTING);
    glDisable(GL_LIGHT0);
}

// Draws the cube object, face by face and adds unique color to each face
[Face1 draw];
[Face2 draw];
[Face3 draw];
[Face4 draw];
[Face5 draw];
[Face6 draw];

if (mode == SELECT) {
    glEnable(GL_DITHER);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
}

// Wrapping presentRenderbuffer with this if statement fixed
// the problem where the unique colors would appear onscreen
if (mode == RENDER) {
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
}

I hope this may help someone else in future :o)

davgothic