c++ - 如何在 openGL 中使用 GLFW?

标签 c++ linux opengl glfw

我正在尝试编译一个简短的 openGl 和 GLFW 代码,但我失败了...... 我像这样包含了所有的 .h :

#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glfw2.h>

我在 linux 上,所以我做了一个:

sudo zypper install libglfw2

当我这样编译时:

 g++ main.cpp -lGLU

我有:

main.cpp:14:22: fatal error: GL/glfw2.h:Any file or directory
 #include <GL/glfw2.h>
                      ^
compilation terminated.

我还尝试包括 #include <GL/glfw3.h>但没有成功。

这是我的完整代码:

#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glfw2.h>

int main()
{
      if (glfwInit() == false)
        {
          fprintf(stderr, "GLFW failed to initialise.\n");
          return (-1);
        }
      glfwWindowHint(GLFW_FSAA_SAMPLES, 4);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
      GLFWwindow* window;
      window = glfwCreateWindow(640, 480, "OPENGL", NULL, NULL);
      if (!window)
        {
          fprintf(stderr, "Window failed to create\n");
          glfwTerminate();
          return (-1);
        }
      glfwMakeContextCurrent(window);
      glewExperimental = true;
      if (glewInit() != GLEW_OK)
        {
          fprintf(stderr, "Failed to initialize GLEW\n");
          return (-1);
        }
    return (0);
}

有人可以知道我必须做什么来编译我的代码吗?

谢谢

最佳答案

没有 GL/glfw2.h,而且从来没有,上面的代码使用了 GLFW 3 API。参见 Renamed library and header file有关 header 路径的更多信息。

新项目没有理由使用 GLFW 2,所以我会避免使用 libglfw2 包。而是查看是否有 GLFW 3 包。

关于c++ - 如何在 openGL 中使用 GLFW?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36016172/

相关文章:

c++ - 使用 Boost 的 Linux 的 Visual Studio 2017 远程构建

C++ 升压 ASIO : how to read/write with a timeout?

linux - 调用多个 Bash 别名

linux - 在两个远程位置之间复制文件

c++ - OpenGL 索引缓冲生成正方形

opengl - 什么是顶点数组对象?

c++ - 逐行读取文件并存储值

C++在同一类的方法中返回对象类型

linux - x-www-browser GET 变量

c++ - 后处理窗口视频输出