编程环境 Qt 5.14.1(+) + msvc2017编译
为什么Windows下 NVDIA GeForce RTX 3050 Ti Laptop GPU 不支持OpenGL库
官方截图<证明英伟达显卡不支持OpenGL,网上回答是驱动问题,请别继续误导网民了>
20250610 16:00<公司电脑>
在 glfwCreateWindow 执行时返回0,然后程序退出
下方代码来自于
#include <GLFW/glfw3.h>
#include <iostream>
int main() {
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW!" << std::endl;
return -1;
}
GLFWwindow* window = glfwCreateWindow(800, 600, "GLFW + Qt Test", NULL, NULL);
if (!window) {
//打印错误码 ,这个分支是自己加的
unsigned int error = glGetError();
const char* errbuf;
int ret = glfwGetError(&errbuf);
std::cout << error << ret << std::endl;
std::cout << errbuf << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
std::cout << "OpenGL Version: " << glGetString(GL_VERSION) << std::endl;
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
glfwSwapBuffers(window);
}
glfwTerminate();
return 0;
}
<公司电脑>报错如下
error = 1282(0x502)
glfwGetError= 65540(0x10004)
Context profiles are only defined for OpenGL version 3.2 and above
下载 OpenGL配置检测工具:
OpenGL Extension Viewerhttps://www.realtech-vr.com/home/?page_id=1402
下载上面工具后,发现OpenGL版本是1.1
但公司电脑上安装有NVDIA GeForce RTX 3050 Ti Laptop GPU 显卡
下载带WHQL版本的驱动尝试一下。
在NVIDIA控制面板->管理3D设置,可以看到OpenGL选项 ,(但OpenGL Extension Viewer无法检测到)
20250610 18:58<公司电脑>
在main.cpp加入如下头文件
#include <glad/glad.h>
程序报错0xc0000005错误
20250610 2235<第二天将在公司电脑上实现>
DDU显卡驱动卸载工具,使用这个工具将驱动删除后,重新安装驱动
20250611 0934 卸载重新安装驱动
卸载驱动后,重新安装新的官网驱动,使用OpenGL Extension Viewer软件检测, 发现OpenGL还是显示版本1.1,渲染器:GDI Generic 。 估计这公司笔记本电脑就是这样了,品牌是Victus。
NVIDIA控制面板显卡设置:OpenGL渲染GPU为 “NVDIA GeForce RTX 3050 Ti Laptop GPU 显卡”。
同时将其他显卡驱动删除,发现ps软件点击菜单时再也不飘走了。<收获?>
20250610 2202<使用家里电脑可获取OpenGL版本>
家里显卡名称:Intel(R) Iris(R) Xe Graphics
工具D:\Program Files\RealTech VR\GLview Extensions Viewer 7.3\openglex.exe
如图所示OpenGL 是4.6版本 GLES是3.1版本的
20250610 2302<家里电脑>
遇到 找不到 glGetError 函数时,pro文件中加入下面库
LIBS += -lopengl32
LIBS += -luser32
20250610 2308<家里电脑>
成功编译后,程序输出如图所示<家里的电脑能够成功显示>
公司电脑结果继续跟进 ...
20250611 1023
网上资料如下
可以利用Windows提供的OpenGL兼容层,将OpenGL的绘图指令转换为GDI的指令,从而实现OpenGL和GDI的兼容性。具体实现方法可以参考Microsoft提供的OpenGL在Windows下的实现文档。
20250611 1438<公司电脑>
目前判断认为NVDIA GeForce RTX 3050 Ti Laptop GPU 不zhichiOpenGL库,去下载openGL的转换层
Mesa3D驱动程序Windows版
Downloading and Unpacking — The Mesa 3D Graphics Library latest documentation (下载主页,注意选择https,选择ftp可能需另外设置)
下载使用 Index of / (下载网页)
该节内容忽略,如无时间和技术积累,请勿深入探索,听劝!!!
20250611 1753<公司电脑>
使用Everything搜索 mesa 发现在Qt\Qt5.14.2\Qt5.14.2\Src\qtwebengine\src\3rdparty\chromium\third_party\mesa_headers位置中的文件gl.h中有 Mesa 3-D GRAPHICS LIBRARY Version :7.6
Qt内部支持了Mesa,但版本可以用。
以下来自于Qt 网站:Qt OpenGL
Qt Quick is optimized for hardware-accelerated rendering. By default, it will be built on the low-level graphics API most appropriate for the target platform.
For instance, it will default to
Direct3D
on Windows, whereas on macOS, it will default toMetal
. But it is also possible to manually select OpenGL as the active graphics API on platforms where this is supported.
Qt Quick针对硬件加速渲染进行了优化。默认情况下,它将建立在最适合目标平台的低级别图形API上。
例如,它将在Windows上默认为Direct3D,而在macOS上,它将默认为Metal。但在支持OpenGL的平台上,也可以手动选择OpenGL作为活动图形API。
思考, Windows上有openGL支持,调用时是如何支持的?
后面是关于Qt6.0的支持
通过Qt渲染硬件接口进行渲染
从Qt 6.0开始,默认适配总是通过Qt GUI模块提供的图形抽象层Qt渲染硬件接口(RHI)进行渲染。这意味着,与Qt 5不同,场景图不会直接调用OpenGL。相反,它通过使用RHI API记录资源和绘制命令,然后将命令流转换为OpenGL、Vulkan、Metal或Direct 3D调用。着色器处理也通过编写一次着色器代码、编译为SPIR-V,然后翻译成适合各种图形API的语言来统一。
Qt Quick Scene Graph Default Renderer | Qt Quick | Qt 6.9.1 <点开看>
Applications wishing to always run with a single given graphics API, can request this via C++ as well. For example, the following call made early in main(), before constructing any QQuickWindow, forces the use of Vulkan (and will fail otherwise):
QQuickWindow::setGraphicsApi(QSGRendererInterface::Vulkan);