Possible Retina issue with OpenGL ES on iPhone?

社会主义新天地 提交于 2019-12-04 15:42:50

You shouldn't hardcode "glViewport(0, 0, 960.0f, 640.0f);", setup the viewport this way:

glViewport(0, 0, framebufferWidth, framebufferHeight);

Also don't hardcode the content scale, you can findout the content scale with:

float contentScale = 1.0f;
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) {
    contentScale = [[UIScreen mainScreen] scale];
}

About the pixel distance, since you want the distance to be the double with retina display, you can add an uniform to your shader with the content scale.

Now iOS devices can have multiple different screens, and a UIWindow can be placed in a non-main screen. In that case, you can use self.view.window.screen.scale to get current screen's scale dynamically.

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