简体   繁体   English

iPhone上的OpenGL ES颜色选择

[英]OpenGL ES color picking on the iPhone

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. 我正在iPhone上查看3D,我已经设法在设备上获得3D立方体但是想要添加交互性,例如触摸一个面部发射特定事件而另一个面部发生不同事件。 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. 我已经阅读了很多颜色选择教程,但在网络上的任何地方似乎都没有任何特定于iPhone的教程或示例代码。

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? 所以我的问题是,任何人都可以指向Objective-C教程的方向或发布一些示例代码吗?

Any help or advice would be much appreciated. 任何帮助或建议将不胜感激。

OK, so after 18 hours I've finally fixed my issue. 好的,所以18小时后我终于解决了我的问题。 In the render method all I had to do was prevent the presentRenderbuffer call when the render was in SELECT mode. 在render方法中,我所要做的就是在渲染处于SELECT模式时阻止presentRenderbuffer调用。 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) 我希望将来可以帮助别人:o)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM