0
我創建了使用GLEW庫工作,我有下一段代碼:GLEW不會在自己的圖書館
// ShaderProgram.hpp
#include <GL.hpp>
#include <vector>
namespace LIBRARY {
class LIBRARY_API ShaderProgram {
public:
ShaderProgram() {
// If I uncomment the code will works, but why it doesn't work without because I already initialize GLEW in the main() function
// glewExperimental = GL_TRUE;
// std::cout << (glewInit() == GLEW_OK) << "\n"; // <- Outputs true
std::cout << (glCreateProgram) << "\n" // <- Null function!
m_program = glCreateProgram(); // <- Here crash when trying to call glCreateProgram(), I mean it can't find the function
}
};
}
這是我的代碼庫的一部分。然後,我創建了一個小的應用程序來測試它,我用SFML窗:
int main() {
...
sf::Window window(sf::VideoMode(800, 600, 32), "OpenGL", sf::Style::Titlebar | sf::Style::Close, settings);
window.setFramerateLimit(60);
window.setActive(true);
glewExperimental = GL_TRUE;
std::cout << (glewInit() == GLEW_OK) << "\n"; // <- Outputs true
std::cout << (glCreateProgram) << "\n" // <- Not null function adress, so it's good!
LIBRARY::ShaderProgram shaderProgram; // <- Here crash
...
因此,在main()的glCreateProgram不爲空,它可調用的函數,但在庫是空,我可以不明白爲什麼,因爲我在glew init之後調用庫代碼,因爲它可以在構建ShaderProgram的代碼中看到。
Thread 1 received signal SIGSEGV, Segmentation fault.
0x00000000 in ??()
(gdb) bt
#0 0x00000000 in ??()
#1 0x68a015a2 in LIBRARY::ShaderProgram::ShaderProgram()()
from path\to\my\library.dll
#2 0x00401843 in main()
我不明白爲什麼在應用程序GL工作,但在圖書館它沒有。
編輯:編輯代碼更好地說明這個問題。
在調試配置中編譯DLL + EXE,並用調試器啓動它。它可能馬上告訴你這個問題。 – Soonts
另外,您可能需要查看和/或重新使用我的這個項目:https://github.com/Const-me/GL3Windows(MIT許可證)。這是一個小而合理完整的現代OpenGL Windows樣本,包括GLEW,着色器和VBO。 – Soonts
在您的GL.hpp中使用[#include guards](https://en.wikipedia.org/wiki/Include_guard),看看它是否有幫助。 – Ripi2