Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenGL对GenVertexArray的操作无效_C++_Opengl_Glfw - Fatal编程技术网

C++ OpenGL对GenVertexArray的操作无效

C++ OpenGL对GenVertexArray的操作无效,c++,opengl,glfw,C++,Opengl,Glfw,我正在opengl中创建一个网格,非常简单,但调用gl::GenVertexArray时出错。下面是代码。我正在使用glfw3 GLuint vao = 0; check_gl_error(); gl::GenVertexArrays(1, &vao); check_gl_error(); //the error is caught here and its a INVALID_OPERATION gl::BindVertexArray(vao); check_gl_error();

我正在opengl中创建一个网格,非常简单,但调用gl::GenVertexArray时出错。下面是代码。我正在使用glfw3

GLuint vao = 0;
check_gl_error();
gl::GenVertexArrays(1, &vao);
check_gl_error(); //the error is caught here and its a INVALID_OPERATION
gl::BindVertexArray(vao);
check_gl_error();
我对OpenGL没有太多的经验,但是我在使用glfw的同一台计算机上使用过OpenGL,并且有过使用GenVertexArray的项目

编辑:

我的程序是用

if (!glfwInit()) {
  std::cout << "Init GLFW failed" << std::endl;
  exit(EXIT_FAILURE);
}

GLFWwindow* window = glfwCreateWindow(800, 800, "My Title", NULL, NULL);    //glfwGetPrimaryMonitor() full screen
if (!window) {
  std::cout << "Init window failed" << std::endl;
  glfwTerminate();
  exit(EXIT_FAILURE);
}
gl::sys::LoadFunctions();

//check_gl_error();

glfwMakeContextCurrent(window);
check_gl_error();

glfwSwapInterval(1);
check_gl_error();

GLuint programID = gl::CreateProgram();
if(!glfwInit()){

std::cout是否使用GLEW或glLoadGen或其他东西?在将实际上下文设置为当前上下文后,需要告诉它再次更新其入口点

在Windows中,只有古老的OpenGL才可用,直到您将更现代的上下文设置为最新。只有这样,更高版本的入口点才可供GLEW/glLoadGen的代码查找


换句话说,所有这些OpenGL函数指针可能突然指向不同的代码,因为OpenGL版本发生了变化。这就是wgl的工作方式。

不要滥发
检查\u gl\u error
在任何地方,你都应该使用glfw提示设置调试上下文。你需要设置错误回调,错误将自动调用错误回调。您是否将上下文设置为当前上下文?。它几乎肯定是可用的,让驱动程序快速准确地验证内容并捕获错误非常有用。@doug65536我使用glfwMakeContextCurrent(窗口)将上下文设置为当前上下文。它类似于我程序中的第10行代码,出现在我上面发布的代码之前。根据
INVALID_操作,只有当count参数为负时才会抛出