OpenGL学习20250610
编程环境 Qt + msvc编译
20250610 16:00<公司电脑>
在 glfwCreateWindow 执行时返回0,然后程序退出
下方代码来自于
Documentation | GLFW
#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下的实现文档。