How to check OpenGL version on Windows 7kl

I am using Windows 7. I am programming using OpenGL. But I found that there are some features that I can use. Therefore, I want to check the version of OpenGL on my system. I use the code below to check it out

const char* version = (const char*)glGetString(GL_VERSION); 

But I get a null pointer. And if I want to update OpenGL, what should I do?

+4
source share
4 answers

You need GL context current before you can find out which version you have.

So, first create a context, call wglMakeCurrent on it, and after that you can call glGetString.

The reported version comes from the driver you installed. The version of OpenGL that your hardware can support is not in itself โ€œupdatedโ€ (because some hardware features will be missing to support the latest and greatest).

Thus, you can best update your driver, but do not rely on high results, this will lead to the creation of a new OpenGL.

+6
source

The easiest and fastest way is to use a diagnostic tool, such as a GPU image viewer .

You can also use glGetString(GL_VERSION) , but remember that the version you want to display is the version of this OpenGL context, which is not always the highest that your GPU can do. However, if you create a context with default settings, you will probably get the maximum possible OpenGL context in the compatibility profile, so yes, this method can be useful.

In addition, since glGetString(GL_VERSION) refers to this OpenGL context, you need to create it in advance. In fact, calling the any gl* function requires a GL context.


Indeed, updating the drivers may give you a higher version of GL, but it is unlikely that the main version will change. For example, if you have GL 3.1 support, it is very likely that the latest drivers will give you GL 3.3, but not GL 4.0.

+5
source

try using the following code, it works for me:

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

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

0
source

Before calling glGetString (GL_VERSION), you need to create an OpenGL context (WGL):

 #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
source

All Articles