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

China☆狼群 提交于 2019-12-01 04:35:11
rickyviking

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

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

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

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);

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.

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.

The frame-buffer size never needs to be equal to the size of the window, as of that you need to use glfwGetFramebufferSize:

This function retrieves the size, in pixels, of the framebuffer of the specified window. If you wish to retrieve the size of the window in screen coordinates, see glfwGetWindowSize.

Whenever you resize your window you need to retrieve the size of its frambuffer and update the Viewport according to it:

 glfwGetFramebufferSize(gWindow, &framebufferWidth, &framebufferHeight);

 glViewport(0, 0, framebufferWidth, framebufferHeight);

With retina display, the default framebuffer (the one that rendered onto the canvas) is twice the resolution of the display. Thus, if the display is 800x600, the internal canvas is 1600x1200, and therefore your viewpoert should be 1600x1200 since this is the "window" into the framebuffer.

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