我正在尝试构建一个 OpenGL 应用程序。首先,我使用旧的固定功能管道进行绘图。然后我注意到这已经过时并且想切换到可编程管道。为此,我使用了网络上的一些教程。更改代码后,我尝试编译它,但我的编译器找不到(核心配置文件?)函数,如 glShaderSource、glCompileShader、glCreateProgram、glAttachShader、glLinkProgram 等。我没有使用 GLFW 库进行窗口管理或类似的东西,而是使用 xlib。
信息 | grep OpenGL 正在打印以下内容:
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 675M/PCIe/SSE2
OpenGL core profile version string: 4.3.0 NVIDIA 331.113
OpenGL core profile shading language version string: 4.30 NVIDIA via Cg compiler
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.4.0 NVIDIA 331.113
OpenGL shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:
我尝试了专有的 Nvidia 驱动程序和开源驱动程序,但这并没有解决问题。
我通过以下方式包含 OpenGl 标头:
#include <GL/gl.h>
#include <GL/glx.h>
以下是一些编译错误输出:
In file included from main.cpp:1:0:
../../gui/iml/app.window.h: In constructor ‘gui::iml::AppWindow::AppWindow()’:
../../gui/iml/app.window.h:65:52: error: ‘glCreateShader’ was not declared in this scope
fragmentShader = glCreateShader(GL_VERTEX_SHADER);
^
../../gui/iml/app.window.h:66:47: error: ‘glShaderSource’ was not declared in this scope
glShaderSource(vertexShader,1,&vshader,NULL);
^
../../gui/iml/app.window.h:67:32: error: ‘glCompileShader’ was not declared in this scope
glCompileShader(vertexShader);
^
../../gui/iml/app.window.h:72:38: error: ‘glCreateProgram’ was not declared in this scope
GLuint sprogram = glCreateProgram();
^
../../gui/iml/app.window.h:73:50: error: ‘glAttachShader’ was not declared in this scope
glAttachShader(this->shaderProg,fragmentShader);
^
../../gui/iml/app.window.h:75:34: error: ‘glLinkProgram’ was not declared in this scope
glLinkProgram(this->shaderProg);
我编译了我为调试创建的测试程序,方法如下:
g++ -Wall -Winline -DDEBUG main.cpp -I ../../gui/ -o debug -lX11 -lGL -lGLU -pthread -std=c++11
我想我犯了一个简单而愚蠢的错误,但我不明白......
编辑:我查看了我的 gl.h 文件,发现它来自 Mesa 项目:
/*
* Mesa 3-D graphics library
*
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
* Copyright (C) 2009 VMware, Inc. All Rights Reserved.
*
这不应该是Nvidia驱动程序的头文件吗?
已解决:
我必须从这里下载 gl3.h 头文件:https ://www.khronos.org/registry/gles/api/old/3.0/gl3.h并将其移动到 /usr/include/GL/
然后我通过以下方式安装了 OpenEs 开发文件:
sudo apt-get install libgles2-mesa-dev
现在程序编译了!