繁体   English   中英

使用GLFW3创建OpenGL 4.3窗口失败

[英]Creating OpenGL 4.3 window fails with GLFW3

我设置了一个最小的应用程序,用GLFW3打开一个空白窗口:

#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>

void glfwErrorCallback(int error, const char *description)
{
   std::cerr << "GLFW error " << error << ": " << description << std::endl;
}

int main(int argc, char **argv)
{
   GLFWwindow* window;
   glfwSetErrorCallback(glfwErrorCallback);

   if(!glfwInit())
   {
      std::cerr << "Failed to initialize GLFW...\n";
      return -1;
   }

   glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
   glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
   glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

   window = glfwCreateWindow(1024, 768, "GLFW window", NULL, NULL);
   if(!window)
   {
      std::cerr << "Failed to open GLFW window...\n";
      glfwTerminate();
      return -1;
   }

   glewExperimental = GL_TRUE;
   if (glewInit())
   {
      std::cerr << "Failed to initialize GLEW...\n";
      glfwTerminate();
      return -1;
   }

   glfwMakeContextCurrent(window);

   while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && !glfwWindowShouldClose(window))
   {
      glfwSwapBuffers(window);
      glfwPollEvents();
   }

   glfwTerminate();
   return 0;
}

它会导致以下错误:

GLFW错误65540:仅对OpenGL版本3.2及更高版本存在上下文配置文件
无法打开GLFW窗口...

该应用程序在Linux上运行,使用Bumblebee的optirun 使用freeglut而不是GLFW时,代码可以正常工作。 导致错误的代码有什么问题?

这很简单:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); // Major = 4
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Major was 4, now it is 3.

// Minor = ???   [Something < 2]

你需要使用glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 3); 而是第二个提示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM