Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6590265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:16:40+00:00 2026-05-25T17:16:40+00:00

I want to use the OpenGL library, GLFW, to render a window but also

  • 0

I want to use the OpenGL library, GLFW, to render a window but also want to use WinAPi to create controls and handle events. Is there any way to do this ?
I tried searching(googling) for “using glfw and winapi” but that did no yield any results.
The only page I found that did what I wanted was this but the page seems to be outdated as GLFW_WINPAR doesn’t exist. Is there any way to do what I want, or do I have to use “Vanilla” OpenGL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:16:42+00:00Added an answer on May 25, 2026 at 5:16 pm

    There’s not much benefit in using GLFW if you intend to use the native Win32 API as well. The whole point of GLFW is hiding the system APIs below.

    Creating a OpenGL window using the Win32 alone not that hard at all:

    #include <windows.h>
    #include <GL/gl.h>
    
    namespace viewwnd
    {
        HWND    hWnd;
        HDC     hDC;
        HGLRC   hRC;
    };
    
    namespace render
    {
        int win_width;
        int win_height;
    }
    
    typedef HGLRC (*wglprocCreateContextAttribsARB)(HDC, HGLRC, const int *);
    typedef BOOL (*wglprocChoosePixelFormatARB)(HDC, const int *, const FLOAT *, UINT,int *,UINT *);
    
    #define VIEWCLASS   "ViewWnd"
    #define VIEWSTYLE   WS_VISIBLE|WS_POPUP|WS_MAXIMIZE
    
    BOOL OpenGLWindowCreate()
    {
        srand((unsigned)time(NULL));
        using namespace viewwnd;
        {
            WNDCLASS wc;
            memset(&wc,0,sizeof(wc));
            wc.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
            wc.lpfnWndProc = ViewProc;
            wc.hInstance = GetModuleHandle(NULL);
            wc.lpszClassName = VIEWCLASS;
            RegisterClass(&wc);
        }
    
        /* Create a temporaray context to get address of wgl extensions. */
    
        HWND hTmpWnd= CreateWindowEx(   WS_EX_APPWINDOW,
                        VIEWCLASS,
                        "Simple",
                        VIEWSTYLE,
                        0,0,0,0,
                        NULL,NULL,
                        hInstance,
                        NULL);
        if(!hTmpWnd)
            return FALSE;
    
        HDC hTempDC = GetDC(hTempWnd);
        if(!hTempDC) {
            DestroyWindow(hTempWnd);
            return FALSE;
        }
    
        PIXELFORMATDESCRIPTOR pfd;
        memset(&pfd,0,sizeof(pfd));
        pfd.nSize = sizeof(pfd);
        pfd.nVersion = 1;
        pfd.dwFlags = PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;
        pfd.cColorBits = 24;
        pfd.cDepthBits = 24;
        pfd.iPixelType = PFD_TYPE_RGBA;
        pfd.iLayerType = PFD_MAIN_PLANE;
    
        int iPF;
        if( (!(iPF = ChoosePixelFormat(hTempDC, &pfd)) || !SetPixelFormat(hTempDC, iPF, &pfd)) ||
    
            (!(hTempRC = wglCreateContext(hTempDC)) || !wglMakeCurrent(hTempDC,hTempRC)) ) {
            ReleaseDC(hTempDC);
            DestroyWindow(hTempWnd);
            return FALSE;
        }
    
        /* Like all extensions in Win32, the function pointers returned by wglGetProcAddress are tied
         * to the render context they were obtained with. Since this is a temporary context, we
         * place those function pointers in automatic storage of the window and context creation function. */
        wglprocCreateContextAttribsARB wglCreateContextAttribsARB = (wglprocCreateContextAttribsARB) wglGetProcAddress("wglCreateContextAttribsARB");
        wglprocChoosePixelFormatARB wglChoosePixelFormatARB = (wglprocChoosePixelFormatARB)wglGetProcAddress("wglChoosePixelFormatARB");
    
        if( wglChoosePixelFormatARB && wglCreateContextAttribsARB ) {
            /* good we have access to extended pixelformat and context attributes */
            hWnd = CreateWindowEx(  WS_EX_APPWINDOW,
                        VIEWCLASS,
                        "Simple",
                        VIEWSTYLE,
                        0,0,0,0,
                        NULL,NULL,
                        hInstance,
                        NULL);
    
            if(!hWnd) {
                wglMakeCurrent(NULL, NULL);
                wglDeleteContext(hTempRC);
                ReleaseDC(hTempDC);
                DestroyWindow(hTempWnd);
    
                return FALSE;
            }
    
            hDC = GetDC(hWnd);
            if(!hDC) {
                    DestroyWindow(hWnd);
    
                wglMakeCurrent(NULL, NULL);
                wglDeleteContext(hTempRC);
                ReleaseDC(hTempDC);
                DestroyWindow(hTempWnd);
    
                return FALSE;
            }
    
            int attribs[] = {
                WGL_DRAW_TO_WINDOW_ARB, TRUE,
                WGL_DOUBLE_BUFFER_ARB, TRUE,
                WGL_SUPPORT_OPENGL_ARB, TRUE, 
                WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
                WGL_COLOR_BITS_ARB, 24,
                WGL_RED_BITS_ARB, 8,
                WGL_GREEN_BITS_ARB, 8,
                WGL_BLUE_BITS_ARB, 8,
                WGL_DEPTH_BITS_ARB, 24,
                WGL_STENCIL_BITS_ARB, 8,
                0, 0
            };
            UINT num_formats_choosen;
            BOOL choose_pf_success = wglChoosePixelFormatARB(
                hDC, 
                attribs, 
                NULL,
                1,
                &iPF,
                &num_formats_choosen);
    
            /* now this is a kludge; we need to pass something in the PIXELFORMATDESCRIPTOR 
             * to SetPixelFormat; it will be ignored, mostly. OTOH we want to send something
             * sane, we're nice people after all - it doesn't hurt if this fails. */
            DescribePixelFormat(hDC, iPF, sizeof(pfd), &pfd);
    
            if(!( choose_pf_success && 
                  num_formats_choosen >= 1 && 
                  SetPixelFormat(hDC, iPF, &pfd) )) {
                ReleaseDC(hDC);
                DestroyWindow(hWnd);
    
                wglMakeCurrent(NULL, NULL);
                wglDeleteContext(hTempRC);
                ReleaseDC(hTempDC);
                DestroyWindow(hTempWnd);
    
                return FALSE;
            }
    
            /* we request a OpenGL-3 compatibility profile */
                int context_attribs[] = {
                WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
                WGL_CONTEXT_MINOR_VERSION_ARB, 0,
                WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB | WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
                0, 0
            };
            hRC = wglCreateContextAttribARB(hDC, NULL, context_attribs);
            if(!hRC) {
                ReleaseDC(hDC);
                DestroyWindow(hWnd);
    
                wglMakeCurrent(NULL, NULL);
                wglDeleteContext(hTempRC);
                ReleaseDC(hTempDC);
                DestroyWindow(hTempWnd);
                return FALSE;
            }
            wglMakeCurrent(hDC, hRC);
    
            /* now that we've created the proper window, DC and RC
             * we can delete the temporaries */
            wglMakeCurrent(NULL, NULL);
            wglDeleteContext(hTempRC);
            ReleaseDC(hTempDC);
            DestroyWindow(hTempWnd);
    
        } else {
            /* extended pixelformats and context attributes not supported
             * => use temporary window and context as the proper ones */
            hWnd = hTempWnd;
            hDC = hTempDC;
            hRC = hTempRC;
        }
    
        ShowWindow(hWnd, SW_SHOW);
        UpdateWindow(hWnd);
    
        return TRUE;
    }
    
    void OnOpenGLWindowDestroy()
    {
        using namespace viewwnd;
        wglMakeCurrent(NULL,NULL);
        wglDeleteContext(hRC);
        ReleaseDC(hWnd,hDC);
        UnregisterClass(VIEWCLASS, GetModuleHandle(NULL));
        PostQuitMessage(0);
    }
    
    LRESULT CALLBACK ViewProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
        using namespace viewwnd;
        switch(uMsg)
        {
        case WM_DESTROY:
            OnOpenGLWindowDestroy();
            break;
        case WM_PAINT:
            display();
            break;
        case WM_SIZE:
            reshape(LOWORD(lParam),HIWORD(lParam));
            break;
        default:
            break;
        }
        return DefWindowProc(hWnd,uMsg,wParam,lParam);
    }
    
    
    void reshape(int w,int h)
    {
        win_width = w;
        win_height = h;
    }
    
    void display()
    {
        using namespace viewwnd;
        using namespace render;
    
        glViewport(0, 0, win_width, win_heighth);
    
        glClearColor(0., 0., 0., 1.);
        glClearDepth(1.);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45,ratio,0.1,100);
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    
        SwapBuffers(hDC);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use shading on my OpenGL objects but can't seem to access
I want to use OpenGL in my WndProc but I'm not sure how. I
In my project I want to use a freeglut library from the unofficial opengl
I have an android application. I want to use OpenGL to render my images
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want use a single php file to handle all of my voting requests.
I want use JQuery mobile for the front-end of my mobile application, but I
I'm fairly new to C so be gentle. I want to use the library
I know OpenCL has a C++ binder, but I use a third party library
I want to draw using OpenGL library a Ring with sectors, each one with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.