为什么视网膜屏幕坐标值是像素值的两倍 [英] Why retina screen coordinate value is twice the value of pixel value

查看:89
本文介绍了为什么视网膜屏幕坐标值是像素值的两倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的计算机是具有13英寸视网膜屏幕的Mac pro.屏幕分辨率为1280 * 800(默认).

My computer is a Mac pro with a 13 inch retina screen. The screen resolution is 1280*800 (default).

使用以下代码:

gWindow = glfwCreateWindow(800, 600, "OpenGL Tutorial", NULL, NULL);

//case 1
glViewport(0,0,1600,1200);
//case 2
glViewport(0,0,800,600);

情况1产生一个适合窗口的三角形.

Case 1 results in a triangle that fits the window.

情况2产生的三角形是窗口大小的1/4.

Case 2 results in a triangle that is 1/4th the size of the window.

半视口:

GLFW文档指出了以下内容(来自此处):

The GLFW documentation indicates the following (from here):

虽然以屏幕坐标来衡量窗口的大小,但OpenGL 适用于像素.例如,您传入glViewport的大小, 应该以像素为单位.在某些机器上,屏幕坐标和像素 是相同的,但在其他方面则不会.还有第二套 函数以像素为单位检索帧的大小 窗口.

While the size of a window is measured in screen coordinates, OpenGL works with pixels. The size you pass into glViewport, for example, should be in pixels. On some machines screen coordinates and pixels are the same, but on others they will not be. There is a second set of functions to retrieve the size, in pixels, of the framebuffer of a window.

为什么我的视网膜屏幕坐标值是像素值的两倍?

Why my retina screen coordinate value is twice the value of pixel value?

推荐答案

Sabuncu 所述,很难知道结果如何在不知道如何绘制三角形的情况下应该是正确的.

As Sabuncu said is hard to know what result should be correct without knowing how you draw the triangle.

但是我想您的问题与视网膜屏幕有关,当您使用2.0比例因子时,您需要渲染的像素是常规屏幕的两倍-

But I guess your problems is related to the fact that with retina screen, when you use the 2.0 scale factor you need to render twice the pixels as you would with a regular screen - see here

您追求的方法仅显示在GLFL链接下方几行

The method you're after is shown just a few lines below your GLFL link

还有glfwGetFramebufferSize可以直接获取窗口的帧缓冲区的当前大小.

There is also glfwGetFramebufferSize for directly retrieving the current size of the framebuffer of a window.

int width, height;
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);

例如,如果在常规监视器和高DPI监视器之间拖动窗口,则帧缓冲区的大小可能会独立于窗口的大小而变化.

The size of a framebuffer may change independently of the size of a window, for example if the window is dragged between a regular monitor and a high-DPI one.

在您的情况下,我敢打赌您将获得的帧缓冲区大小将是窗口大小的两倍,并且gl视口需要匹配它.

In your case I'm betting the framebuffer size you'll get will be twice the window size, and your gl viewport needs to match it.

这篇关于为什么视网膜屏幕坐标值是像素值的两倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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