# How to get the ratio of 'display scale and layout'?

**URL:** <https://discourse.glfw.org/t/how-to-get-the-ratio-of-display-scale-and-layout/2348>\
**Category:** support\
**Created:** [April 3, 2023, 2:58am UTC](https://discourse.glfw.org/t/how-to-get-the-ratio-of-display-scale-and-layout/2348 "2023-04-03T02:58:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RuiJing](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@RuiJing](https://discourse.glfw.org/u/RuiJing)\
**Post date:** [April 3, 2023, 2:58am UTC](https://discourse.glfw.org/t/how-to-get-the-ratio-of-display-scale-and-layout/2348/1 "2023-04-03T02:58:00Z")

</div>

The secondary monitor of our computer was set by my colleague like this:  
Win10 settings → display → scale and layout → 300%(recommended)  
And I was not allowed to reset the ratio from 300% to 100%, but I hope to show my images with 100% scale。What should I do in my GLFW codes?

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 3, 2023, 2:47pm UTC](https://discourse.glfw.org/t/how-to-get-the-ratio-of-display-scale-and-layout/2348/2 "2023-04-03T14:47:49Z")

</div>

On the Windows platform the content scale will only alter the size of the GLFW Window if the `GLFW_SCALE_TO_MONITOR` window hint is set, the default for which is off. See:  
[https://www.glfw.org/docs/3.3/window\_guide.html#window\_scale](https://www.glfw.org/docs/3.3/window_guide.html#window_scale)

Additionally, on Windows the framebuffer size (pixel size) and window size (screen coordinates) are the same.

So if you want to display your images with 100% scale then simply draw them as you normally would - i.e. you don’t need any code to be changed to achieve this.

---

<div class="post-metadata">

**Author:** ![RuiJing](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@RuiJing](https://discourse.glfw.org/u/RuiJing)\
**Post date:** [April 4, 2023, 11:56am UTC](https://discourse.glfw.org/t/how-to-get-the-ratio-of-display-scale-and-layout/2348/3 "2023-04-04T11:56:25Z")

</div>

It didn’t work. My images were still shown with 300% scale unless I set the Win10’s ‘display scale and layout’ to 100%. Is it because I didn’t create the window in a right way? Here are my codes in the main thread:  
(graphic card: nVidia Rtx 2080 super)

> int MonitorNum;  
> GLFWwindow\* window1;  
> GLFWmonitor\*\* pMonitors;  
> int ret = glfwInit();  
> if (!ret)  
> {  
> AfxMessageBox(“GLFW Init failed”, MB\_OK | MB\_ICONSTOP);  
> return -1;  
> }
> 
> glfwWindowHint(GLFW\_CONTEXT\_VERSION\_MAJOR, 4);  
> glfwWindowHint(GLFW\_CONTEXT\_VERSION\_MINOR, 4);  
> glfwWindowHint(GLFW\_OPENGL\_PROFILE, GLFW\_OPENGL\_COMPAT\_PROFILE);  
> pMonitors = glfwGetMonitors(&MonitorNum);
> 
> int width\_mm, height\_mm;  
> glfwGetMonitorPhysicalSize(pMonitors[1], &width\_mm, &height\_mm);  
> moninfo[1].width\_cm = width\_mm / 10.0;  
> moninfo[1].height\_cm = height\_mm / 10.0;  
> const GLFWvidmode\* mode = glfwGetVideoMode(pMonitors[1]);  
> moninfo[1].height\_pixel = mode-\>height;  
> moninfo[1].width\_pixel = mode-\>width;  
> moninfo[1].redbits = mode-\>redBits;  
> moninfo[1].bluebits = mode-\>blueBits;  
> moninfo[1].greenbits = mode-\>greenBits;  
> moninfo[1].refrate = mode-\>refreshRate;  
> glfwGetMonitorPos(pMonitors[1], &moninfo[1].virtualPos[0], &moninfo[1].virtualPos[1]);
> 
> glfwWindowHint(GLFW\_RED\_BITS, moninfo[1].redbits);  
> glfwWindowHint(GLFW\_GREEN\_BITS, moninfo[1].bluebits);  
> glfwWindowHint(GLFW\_BLUE\_BITS, moninfo[1].greenbits);  
> glfwWindowHint(GLFW\_DOUBLEBUFFER, TRUE);  
> glfwWindowHint(GLFW\_RESIZABLE, GLFW\_FALSE);  
> glfwWindowHint(GLFW\_DECORATED, GLFW\_FALSE);  
> glfwWindowHint(GLFW\_SAMPLES, MULTISAMPLEN);  
> glfwWindowHint(GLFW\_FOCUSED, GLFW\_FALSE);  
> glfwWindowHint(GLFW\_FLOATING, GLFW\_TRUE);  
> glfwWindowHint(GLFW\_CENTER\_CURSOR, GLFW\_FALSE);  
> glfwWindowHint(GLFW\_AUTO\_ICONIFY, GLFW\_FALSE);  
> glfwWindowHint(GLFW\_SCALE\_TO\_MONITOR,TRUE);  
> window1 = glfwCreateWindow(moninfo[1].width\_pixel, moninfo[1].height\_pixel, “Hello”, NULL, NULL);  
> glfwSetWindowMonitor(window1, pMonitors[1], moninfo[1].virtualPos[0], moninfo[1].virtualPos[1],  
> moninfo[1].width\_pixel, moninfo[1].height\_pixel, moninfo[1].refrate);

And for the render thread:

> glfwMakeContextCurrent(window1);  
> glewExperimental = true;  
> int initcode = glewInit();  
> glViewport(0, 0, moninfo[1].width\_pixel, moninfo[1].height\_pixel);

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 5, 2023, 10:39am UTC](https://discourse.glfw.org/t/how-to-get-the-ratio-of-display-scale-and-layout/2348/4 "2023-04-05T10:39:54Z")

</div>

I think you may have misunderstood what I meant when I stated:

> [@dougbinks](#):
>
> On the Windows platform the content scale will only alter the size of the GLFW Window if the `GLFW_SCALE_TO_MONITOR` window hint is set, the default for which is off.

I meant that you should **NOT** set `glfwWindowHint(GLFW_SCALE_TO_MONITOR,TRUE);` ,i.e. remove that line of code.

However this will not change your application since after creating your window you call `glfwSetWindowMonitor` with a non `NULL` monitor which should create a fullscreen window.

As to why your images are now shown with 300% scale I can’t tell from your code since you are not showing the image display code. If your image is X pixels by Y pixels in size and you render it that size you should get the same size of image no matter what the Windows scale and layout is.

---

<div class="post-metadata">

**Author:** ![RuiJing](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@RuiJing](https://discourse.glfw.org/u/RuiJing)\
**Post date:** [April 7, 2023, 12:51pm UTC](https://discourse.glfw.org/t/how-to-get-the-ratio-of-display-scale-and-layout/2348/5 "2023-04-07T12:51:18Z")

</div>

I find the bug now. I mistakenly acquired size (in pixel) from video mode:  
moninfo[1].height\_pixel = mode-\>height  
The correct way is to use glfwGetFrameBufferSize.
