iPhone 上的 OpenGL ES 可能存在 Retina 问题吗?

发布于 2024-11-30 04:28:49 字数 1058 浏览 0 评论 0原文

这可能与 有关我的另一个未解之谜

我正在 iPhone 上使用真实设备和模拟器绘制正交 2d。我正在尝试将像素着色为给定颜色,具体取决于它们与我传入的“A”像素空间中的任意点的距离(硬代码)。我所做的一切都是在 Retina 960x640 分辨率下进行的。我计算从 A 到 gl_FragCoord 的距离,并基于两种颜色之间的跳跃进行着色,“最大”距离为 300 像素。

在模拟器上(使用视网膜显示屏)时,我需要为屏幕中点 X 提供“460”像素的中心点..YI 给出 ​​160px,并且我寻找“300”px 的距离..以获得相同的效果 在设备上,我需要 960X 的中心和 150 的距离才能获得相同的结果(有趣的是,px 80 不会给出我想要的相同结果,但 160 可能会超出在原来的...)

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

我正在使用:

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 *)[自身视图] setContentScaleFactor:2.0f];

This is probably linked to another unsolved mystery of mine.

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.

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?

I'm using:

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

and:

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

And:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

私藏温柔 2024-12-07 04:28:49

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

glViewport(0, 0, framebufferWidth, framebufferHeight);

也不要硬编码内容比例,您可以通过以下方式找出内容比例:

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

关于像素距离,因为如果您希望距离是视网膜显示的两倍,则可以使用内容比例向着色器添加制服。

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.

南风几经秋 2024-12-07 04:28:49

现在iOS设备可以有多个不同的屏幕,并且可以将UIWindow放置在非主屏幕中。在这种情况下,您可以使用 self.view.window.screen.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文