iPhone上的OpenGL ES可能存在Retina问题? [英] Possible Retina issue with OpenGL ES on iPhone?

查看:95
本文介绍了iPhone上的OpenGL ES可能存在Retina问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能链接到.

This is probably linked to another unsolved mystery of mine.

我正在使用真实的设备和模拟器在iPhone上绘制Orthographic 2d.我正在尝试根据给定像素的颜色给像素着色,具体取决于它们与像素空间"A"中任意点的距离(硬编码).我正在使用Retina 960x640分辨率进行所有操作.我计算了从A到gl_FragCoord的距离,并根据两种颜色之间的跳跃来着色,其中最大"为300px距离.

I'm drawing Orthographic 2d on iPhone, using real device and simulator. I'm trying to color my pixels a given color depending on how far they are from arbitrary point in pixelspace of 'A', which I pass in (hard code). I'm doing everything in Retina 960x640 resolution. I calculate distance from A to gl_FragCoord, and I color based on leaping between 2 colors with the 'max' being 300px distance.

在模拟器上(带有视网膜显示屏),我需要为屏幕中点X指定一个"460"像素的中心点.YI为160px,并且我寻找"300" px的距离.以得到在设备上具有相同的效果,我需要960X的中心和150的距离才能获得相同的结果(有趣的是,px 80不能提供我想要的相同结果,但是160可能会比原始图像过大...)

When on simulator (with retina display) I need to give a center point of "460" pixels for screen midpoint X.. Y I give 160px, and I look for distance of '300'px.. to get the same effect on device I need center of 960X and distance of 150 to get the same results (interestingly, px 80 doesn't give the same results I want but 160 could be an overshoot on the original...)

显然是视网膜问题在起作用.但是在哪里,如何以及如何找到并修复它?

Obviously a retina issue is at play. But where, and how, and how do I find and fix it?

我正在使用:

glViewport(0, 0, 960.0f, 640.0f);

和:

glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth); glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight);

并且:

[self setView:[[EAGLView alloc] initWithFrame:[UIScreen mainScreen].bounds]];
[(EAGLView *)[self view] setContentScaleFactor:2.0f];

推荐答案

您不应该对"glViewport(0,0,960.0f,640.0f);"进行硬编码,以这种方式设置视口:

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.

这篇关于iPhone上的OpenGL ES可能存在Retina问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆