OpenGL ES color picking on the iPhone

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 06:13:17

问题


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:


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)



来源:https://stackoverflow.com/questions/3652692/opengl-es-color-picking-on-the-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!