开发者

OpenGL ES color picking on the iPhone

开发者 https://www.devze.com 2023-01-14 20:14 出处:网络
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 eve

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.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消