c++ - glew 和 glfw 的 opengl 初始化问题

标签 c++ opengl libraries glfw glew

我开始学习 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;
}

错误: THE ERROS DISPLAYED

最佳答案

链接 GLEW库正确,必须设置正确的预处理器定义。参见 GLEW - Installation :

[...] On Windows, you also need to define the GLEW_STATIC preprocessor token when building a static library or executable, and the GLEW_BUILD preprocessor token when building a dll [...]

关于c++ - glew 和 glfw 的 opengl 初始化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58017285/

相关文章:

javascript - JavaScript 日程安排日历的最佳实践或现有技术

c - 如何从c中的库传递数组

c++ - 使用迭代器访问数据。 boost 图

c++ - 在 C++ 中使用 GDI 在窗口屏幕上隐藏鼠标指针

c++ - 此 C++ 堆栈分配器的改进?

python - PyQt5 中包含的 3D 窗口

c++ - 我应该如何在 API 中替换 vector<uint8_t>::const_iterator?

c++ - 无法在屏幕上绘制正方形(相同的宽度和高度)

c - OpenGL:指定 UV 坐标时如何避免舍入错误

lua - Lua 有哪些很棒但鲜为人知的库?