我在其他地方看到过类似的问题,但没有人回答或解决我的问题。
我已经正确启动了GLEW ,就在创建上下文之后但在我打电话之前glfwMakeContextCurrent()
启动后我尝试使用glGenBuffers()
但它不起作用。引发错误。
我的 OpenGL 版本是 3.2,所以根据我的阅读,我可以在我的程序中使用这个功能。如果我不能,请让我知道。我将尝试找出一种不同的方法来做到这一点。
我正在使用Windows 7和VS2012,似乎一切都正确链接。希望我提供了我需要的所有信息。
#include <stdlib.h>
#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <thread>
int main(){
//Initialize GLFW
if(!glfwInit()){
printf("GLFW was not initialized successfully!\n");
std::this_thread::sleep_for(std::chrono::seconds(5));
exit(EXIT_FAILURE);
}
else{
printf("GLFW was initialized successfully!\n");
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(800, 600, "PONG!", nullptr, nullptr); // Windowed
glewExperimental = GL_TRUE;
if(!glewInit()){
printf("GLEW was not initialized successfully!\n");
std::this_thread::sleep_for(std::chrono::seconds(5));
exit(EXIT_FAILURE);
}
else{
printf("GLEW was initialized successfully!\n");
}
glfwMakeContextCurrent(window);
GLuint vertexbuffer;
glGenBuffers(1, &vertexbuffer);
printf("%u\n", vertexbuffer);
fprintf(
stdout,
"INFO: The OpenGL version is: %s\n",
glGetString(GL_VERSION)
);
fprintf(
stdout,
"INFO: The GLEW version is: %s\n",
glewGetString(GLEW_VERSION)
);
while(!glfwWindowShouldClose(window)){
glfwSwapBuffers(window);
glfwPollEvents();
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS){
glfwDestroyWindow(window);
window = glfwCreateWindow(800, 600, "PONG!", nullptr, nullptr);
}
else if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS){
glfwDestroyWindow(window);
window = glfwCreateWindow(800, 600, "PONG!", glfwGetPrimaryMonitor(), nullptr);
}
}
}