如何在 Windows 7kl 上检查 OpenGL 版本

发布于 2024-10-07 09:12:46 字数 221 浏览 2 评论 0原文

我使用的是 Windows 7。我正在其上使用 OpenGL 进行编程。但我发现有一些功能我可以使用。所以我想检查我系统上的 OpenGL 版本。 我使用下面的代码来检查它

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

但我得到一个空指针。如果我想升级我的 OpenGL,我该怎么办?

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 system.
I use the code below to check it

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

三生殊途 2024-10-14 09:12:46

在询问您拥有哪个版本之前,您需要当前的 GL 上下文。

因此,首先,创建一个上下文,对其调用 wglMakeCurrent,然后您应该能够调用 glGetString。

报告的版本来自您已安装的驱动程序。您的硬件可以支持的 OpenGL 版本本身并不是“可升级的”(因为某些硬件功能将无法支持最新和最好的版本)。

因此,您能做的最好的事情就是升级您的驱动程序,但不要寄希望于它会带来更新的 OpenGL。

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.

梦言归人 2024-10-14 09:12:46

最简单、最快的方法是使用诊断工具,例如 GPU Caps Viewer

您还可以使用glGetString(GL_VERSION),但请记住,您将显示的版本是给定OpenGL上下文的版本 - 这不一定是您的GPU可以执行的最高版本。
但是,如果您使用默认设置创建上下文,您可能会在兼容性配置文件中获得尽可能高的 OpenGL 上下文,所以是的,此方法可能很有用。

另外,由于 glGetString(GL_VERSION) 引用给定的 OpenGL 上下文,因此您需要预先创建它。实际上,调用任何 gl* 函数都需要 GL 上下文。


事实上,升级驱动程序可能会为您提供更高的 GL 版本,但主要版本不太可能发生变化。例如,如果您发现自己支持 GL 3.1,则最新的驱动程序很可能会为您提供 GL 3.3,而不是 GL 4.0。

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.

記憶穿過時間隧道 2024-10-14 09:12:46

在调用 glGetString(GL_VERSION) 之前,您需要创建 OpenGL 上下文 (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;

} 

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;

} 
沉睡月亮 2024-10-14 09:12:46

尝试使用以下代码,它对我有用:

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

确保您的程序中包含 string 和 iostream。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文