我开始学习 OpenGL 的东西,但不幸的是,我无法正确进行初始化。 我添加了 glfw 和 glew 库,这些函数给我一个奇怪的错误, 我怎样才能让它发挥作用?
代码:
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
{
std::cout << "GLFW initialization failed.\n";
return -1;
}
if (glewInit()!=GLEW_OK)
{
std::cout << "GLEW initialization failed.\n";
return -1;
}
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
std::cout << "Wiondow failed.\n";
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
最佳答案
链接 GLEW库正确,必须设置正确的预处理器定义。参见 GLEW - Installation :
[...] On Windows, you also need to define the
GLEW_STATIC
preprocessor token when building a static library or executable, and theGLEW_BUILD
preprocessor token when building a dll [...]
关于c++ - glew 和 glfw 的 opengl 初始化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58017285/