How to check the Version of the OpenGL on Windows 7kl

后端 未结 4 637
傲寒
傲寒 2021-01-03 05:42

I am using the Windows 7. I am programming using the OpenGL on it. But I found that there are some features I can use. So I want to check the version of the OpenGL on my sys

相关标签:
4条回答
  • 2021-01-03 06:25

    You need a GL context current before you can ask which version you have.

    So first, create a context, call wglMakeCurrent on it, and you should be able to call glGetString after that.

    The version that gets reported is coming from the driver that you have installed. The OpenGL version that your hardware can support is not itself "upgradable" (because some hardware features will be missing to support the latest and greatest).

    So the best you can do is upgrade your driver, but don't get your hopes to high it will result in a newer OpenGL.

    0 讨论(0)
  • 2021-01-03 06:28

    You need to create OpenGL Context (WGL) before calling glGetString(GL_VERSION) :

    #include <windows.h>
    #include <GL/GL.h>
    
    #pragma comment (lib, "opengl32.lib")
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    
    int WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
    {
            MSG msg          = {0};
            WNDCLASS wc      = {0}; 
            wc.lpfnWndProc   = WndProc;
            wc.hInstance     = hInstance;
            wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
            wc.lpszClassName = L"oglversionchecksample";
            wc.style = CS_OWNDC;
            if( !RegisterClass(&wc) )
                    return 1;
            CreateWindowW(wc.lpszClassName,L"openglversioncheck",WS_OVERLAPPEDWINDOW|WS_VISIBLE,0,0,640,480,0,0,hInstance,0);
    
            while( GetMessage( &msg, NULL, 0, 0 ) > 0 )
                    DispatchMessage( &msg );
    
            return 0;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
            switch(message)
            {
            case WM_CREATE:
                    {
                    PIXELFORMATDESCRIPTOR pfd =
                    {
                            sizeof(PIXELFORMATDESCRIPTOR),
                            1,
                            PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,    //Flags
                            PFD_TYPE_RGBA,            //The kind of framebuffer. RGBA or palette.
                            32,                        //Colordepth of the framebuffer.
                            0, 0, 0, 0, 0, 0,
                            0,
                            0,
                            0,
                            0, 0, 0, 0,
                            24,                        //Number of bits for the depthbuffer
                            8,                        //Number of bits for the stencilbuffer
                            0,                        //Number of Aux buffers in the framebuffer.
                            PFD_MAIN_PLANE,
                            0,
                            0, 0, 0
                    };
    
                    HDC ourWindowHandleToDeviceContext = GetDC(hWnd);
    
                    int  letWindowsChooseThisPixelFormat;
                    letWindowsChooseThisPixelFormat = ChoosePixelFormat(ourWindowHandleToDeviceContext, &pfd); 
                    SetPixelFormat(ourWindowHandleToDeviceContext,letWindowsChooseThisPixelFormat, &pfd);
    
                    HGLRC ourOpenGLRenderingContext = wglCreateContext(ourWindowHandleToDeviceContext);
                    wglMakeCurrent (ourWindowHandleToDeviceContext, ourOpenGLRenderingContext);
    
                    MessageBoxA(0,(char*)glGetString(GL_VERSION), "OPENGL VERSION",0);
    
                    wglDeleteContext(ourOpenGLRenderingContext);
                    PostQuitMessage(0);
                    }
                    break;
            default:
                    return DefWindowProc(hWnd, message, wParam, lParam);
            }
            return 0;
    
    } 
    
    0 讨论(0)
  • 2021-01-03 06:34

    The easiest and fastest way is to use a diagnostic tool like GPU Caps Viewer.

    You can also use glGetString(GL_VERSION) but remember that the version which you'll have displayed is the version of a given OpenGL context - which is not necessarily the highest your GPU can do. However, if you create the context with default settings, you'll probably get the highest possible OpenGL context in compatibility profile, so yes, this method can be useful.

    Also, as the glGetString(GL_VERSION) refers to a given OpenGL context, you need to have it created beforehand. Actually, a GL context is required to call any gl* function.


    Indeed, upgrading the drivers may give you a higher GL version, but it's unlikely that the major version would change. For example, if you'd find yourself having support for GL 3.1, it's very likely that the latest drivers will give you GL 3.3, but not GL 4.0.

    0 讨论(0)
  • 2021-01-03 06:39

    try to use the following code, it works for me:

    cout << "OpenGL Version : " << glGetString(GL_VERSION) << endl;  
    

    Make sure that you include string and iostream in your program.

    0 讨论(0)
提交回复
热议问题