DEV Community

Audi Nugraha
Audi Nugraha

Posted on

Minimal Game Window

#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/wglext.h>

void main() {
    // Create full screen window
    HWND wnd = CreateWindow("STATIC", 0, WS_POPUP | WS_MAXIMIZE | WS_VISIBLE, 0,  0,  0,  0,  0,  0,  0,  0);
    HDC dc = GetDC(wnd);

    // Set pixel format
    PIXELFORMATDESCRIPTOR pfd = { .dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER };
    SetPixelFormat(dc, ChoosePixelFormat(dc, &pfd), &pfd);

    // Intialize OpenGL context
    wglMakeCurrent(dc, wglCreateContext(dc));

    // Enable vsync
    ((PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress("wglSwapIntervalEXT"))(1);

    // More OpenGL initialization code here...

    while (TRUE) {
        // Process window message
        MSG msg;
        if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        // Break loop on ALT+F4
        if (GetAsyncKeyState(VK_MENU) && GetAsyncKeyState(VK_F4)) {
            break;
        }

        // Draw using OpenGL here...

        SwapBuffers(dc);
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)