gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 04:10:01 34 4
gpt4 key购买 nike

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

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com