<p>You might need to use a setting to tell Windows that your program is DPI-aware, meaning that it can adjust to very high-resolution screens like many current-gen laptops have.</p>
<p>Lots of older programs have trouble with such high resolutions, so without the DPI awareness flag, Windows will tell the program the resolution is lower, and then upscale the whole window. That looks like it might be what's happening to your OpenGL app.</p>
<p>The simplest way to do this is to add a call to <a href="https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiaware" rel="nofollow noreferrer"><code>SetProcessDPIAware()</code></a> during your program's startup, before creating the window. You might also want to increase the hard-coded width and height values.</p>
<p>The other way to do it is by adding an XML &quot;manifest&quot; file that gets linked into your app's .exe file, but it might be hard to get that working in Code::Blocks if it doesn't have it built in.</p>
<p>For more information: <a href="https://docs.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process" rel="nofollow noreferrer">Setting the default DPI awareness for a process</a></p>

CC BY-SA 4.0
2021-12-12T00:05:38.043Z
Wow ! Thank you very much ! That fixed it. I found the MS docs recommended using the manifest version as the in-program version can cause "unexpected behavior". Much as I don't want to potato my computer, I am also reluctant to face the learning curve of the "manifest". I also found that CodeBlocks objected to my use of the command SetProcessDPIAware(), warning that it was an implicit declaration of a function. I looked up various hacks for this, but none worked, so I will live with it. Interestingly it worked even before I included the winuser.h header file where the docs say it comes from.
Simon
CC BY-SA 4.0
2021-12-12T00:14:49.430Z
Glad it worked! Yeah, Microsoft recommends using the manifest, but I'm not very clear on why, or what "unexpected behavior" might mean. Bur if it works, don't fix it, I guess!
Nathan Reed
CC BY-SA 4.0
2021-12-12T00:19:24.227Z
My favourite maxim !! Especially since I am doing this for hobby / educational purposes, not with a view to creating a deployable app. I think I might now be enjoying a slightly lower frame rate with all my new pixels, so I am coding a frame rate counter to test that. The dpi on this screen turns out to be so high as to make me suppose that for many purposes, there would be no point in using multisampling.
Simon
CC BY-SA 4.0
2021-12-12T01:48:38.367Z
Update: If my frame rate counter can be trusted, then the higher DPI made no difference. I got about 60 fps consistently even while wildly rotating the scene, with or without the high DPI. Bearing in mind that my scene only has 16 (biggish) triangles !
Simon
CC BY-SA 4.0
2021-12-11T07:04:28.000Z
2021-12-11T07:04:28.000Z
Nathan Reed
<p>CodeBlocks offers an example program in C, that uses OpenGL. It draws a single multicoloured rotating triangle. I have been building on this example. I am a novice in C and in OpenGL. I believe that I am using an old style of OpenGL coding (possibly called &quot;Immediate Mode ?&quot;) and I am trying to keep things as simple as possible. For example, I am not, to my knowledge, using VBOs, nor VAOs, nor GLSL. I am also not, as far as I know, using any helper libraries (if that's a right way to say it), such as GLEW, GLFW, GLut, etc.</p>
<p>I notice that the sides of the triangles are more jagged than they need to be, given the resolution of my laptop screen. Even if no multisampling were used (and I am not yet trying to use it), much smaller &quot;jaggies&quot; could be achieved, if OpenGL's raster array really corresponded to the physical pixel array. I took a &quot;print screen&quot; and opened it in MS Paint, saving it as a .bmp. When I zoomed in, it seemed that multisampling <em>had</em> been used, but to smooth the edges of the large jaggies ! If you see what I mean.</p>
<p>EDIT:
Here is a picture:
<a href="https://i.sstatic.net/sa9SN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sa9SN.png" alt="Example" /></a></p>
<p>This shows that the text on the left (which is not from my OpenGL window) is rendered at a higher resolution than my triangley object on the right (which is in my OpenGL window).</p>
<p>My question is, how can I use the maximum resolution of the screen ?</p>
<p>Here are some excerpts from the code:</p>
<pre><code>#include &lt;windows.h&gt;
#include &lt;gl/gl.h&gt;
#include &lt;stdio.h&gt;

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;
    HWND hwnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;

    const int width = 768;
    const int height = 768;

    /* register window class */
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_OWNDC;
    wcex.lpfnWndProc = WindowProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = &quot;GLSample&quot;;
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;


    if (!RegisterClassEx(&amp;wcex))
        return 0;

    /* create main window */
    hwnd = CreateWindowEx(0,
                          &quot;GLSample&quot;,
                          &quot;OpenGL Sample&quot;,
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          width,
                          height,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hwnd, nCmdShow);

    /* enable OpenGL for the window */
    EnableOpenGL(hwnd, &amp;hDC, &amp;hRC);
    
    etc..
}
</code></pre>
<p>and the EnableOpenGL function:</p>
<pre><code>void EnableOpenGL(HWND hwnd, HDC* hDC, HGLRC* hRC)
{
    PIXELFORMATDESCRIPTOR pfd;

    int iFormat;

    /* get the device context (DC) */
    *hDC = GetDC(hwnd);

    /* set the pixel format for the DC */
    ZeroMemory(&amp;pfd, sizeof(pfd));

    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW |
                  PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;

    iFormat = ChoosePixelFormat(*hDC, &amp;pfd);

    SetPixelFormat(*hDC, iFormat, &amp;pfd);

    /* create and enable the render context (RC) */
    *hRC = wglCreateContext(*hDC);

    wglMakeCurrent(*hDC, *hRC);
}
</code></pre>

<opengl><rasterizer><pixels><raster-image>
How to use maximum resolution (pixel density) with OpenGL in MS Windows
Simon
# How to use maximum resolution (pixel density) with OpenGL in MS Windows

(Asked by: username_0 on 2021-12-10)

CodeBlocks offers an example program in C, that uses OpenGL. It draws a single multicoloured rotating triangle. I have been building on this example. I am a novice in C and in OpenGL. I believe that I am using an old style of OpenGL coding (possibly called "Immediate Mode ?") and I am trying to keep things as simple as possible. For example, I am not, to my knowledge, using VBOs, nor VAOs, nor GLSL. I am also not, as far as I know, using any helper libraries (if that's a right way to say it), such as GLEW, GLFW, GLut, etc.

I notice that the sides of the triangles are more jagged than they need to be, given the resolution of my laptop screen. Even if no multisampling were used (and I am not yet trying to use it), much smaller "jaggies" could be achieved, if OpenGL's raster array really corresponded to the physical pixel array. I took a "print screen" and opened it in MS Paint, saving it as a .bmp. When I zoomed in, it seemed that multisampling *had* been used, but to smooth the edges of the large jaggies ! If you see what I mean.

EDIT:
Here is a picture:
[![Example](https://i.sstatic.net/sa9SN.png)](https://i.sstatic.net/sa9SN.png)

This shows that the text on the left (which is not from my OpenGL window) is rendered at a higher resolution than my triangley object on the right (which is in my OpenGL window).

My question is, how can I use the maximum resolution of the screen ?

Here are some excerpts from the code:

```
#include <windows.h>
#include <gl/gl.h>
#include <stdio.h>

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;
    HWND hwnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;

    const int width = 768;
    const int height = 768;

    /* register window class */
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_OWNDC;
    wcex.lpfnWndProc = WindowProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = "GLSample";
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;

    if (!RegisterClassEx(&wcex))
        return 0;

    /* create main window */
    hwnd = CreateWindowEx(0,
                          "GLSample",
                          "OpenGL Sample",
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          width,
                          height,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hwnd, nCmdShow);

    /* enable OpenGL for the window */
    EnableOpenGL(hwnd, &hDC, &hRC);
    
    etc..
}

```

and the EnableOpenGL function:

```
void EnableOpenGL(HWND hwnd, HDC* hDC, HGLRC* hRC)
{
    PIXELFORMATDESCRIPTOR pfd;

    int iFormat;

    /* get the device context (DC) */
    *hDC = GetDC(hwnd);

    /* set the pixel format for the DC */
    ZeroMemory(&pfd, sizeof(pfd));

    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW |
                  PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;

    iFormat = ChoosePixelFormat(*hDC, &pfd);

    SetPixelFormat(*hDC, iFormat, &pfd);

    /* create and enable the render context (RC) */
    *hRC = wglCreateContext(*hDC);

    wglMakeCurrent(*hDC, *hRC);
}

```

**Tags:** opengl, rasterizer, pixels, raster-image


---

## 1 answers

### Answer by username_1 on 2021-12-11. Score: 2 | Accepted answer

You might need to use a setting to tell Windows that your program is DPI-aware, meaning that it can adjust to very high-resolution screens like many current-gen laptops have.

Lots of older programs have trouble with such high resolutions, so without the DPI awareness flag, Windows will tell the program the resolution is lower, and then upscale the whole window. That looks like it might be what's happening to your OpenGL app.

The simplest way to do this is to add a call to [`SetProcessDPIAware()`](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiaware) during your program's startup, before creating the window. You might also want to increase the hard-coded width and height values.

The other way to do it is by adding an XML "manifest" file that gets linked into your app's .exe file, but it might be hard to get that working in Code::Blocks if it doesn't have it built in.

For more information: [Setting the default DPI awareness for a process](https://docs.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process)

> **Comments:**
> **username_0**: Wow ! Thank you very much ! That fixed it. I found the MS docs recommended using the manifest version as the in-program version can cause "unexpected behavior". Much as I don't want to potato my computer, I am also reluctant to face the learning curve of the "manifest". I also found that CodeBlocks objected to my use of the command SetProcessDPIAware(), warning that it was an implicit declaration of a function. I looked up various hacks for this, but none worked, so I will live with it. Interestingly it worked even before I included the winuser.h header file where the docs say it comes from.  
> **username_1**: Glad it worked! Yeah, Microsoft recommends using the manifest, but I'm not very clear on why, or what "unexpected behavior" might mean. Bur if it works, don't fix it, I guess!  
> **username_0**: My favourite maxim !! Especially since I am doing this for hobby / educational purposes, not with a view to creating a deployable app. I think I might now be enjoying a slightly lower frame rate with all my new pixels, so I am coding a frame rate counter to test that. The dpi on this screen turns out to be so high as to make me suppose that for many purposes, there would be no point in using multisampling.  
> **username_0**: Update: If my frame rate counter can be trusted, then the higher DPI made no difference. I got about 60 fps consistently even while wildly rotating the scene, with or without the high DPI. Bearing in mind that my scene only has 16 (biggish) triangles !  

---

