gpt4 book ai didi

opengl - 无法使用 OpenGL 中的某些函数 (glGenBuffers)

转载 作者:行者123 更新时间:2023-12-02 05:48:44 26 4
gpt4 key购买 nike

我在其他地方看到过与我类似的问题,但没有人回答或解决我的问题。

在创建Context之后、调用glfwMakeContextCurrent()之前,我已经正确启动了GLEW

启动后,我尝试使用 glGenBuffers() 但它不起作用。抛出错误。

我的 OpenGL 版本是 3.2,因此根据我的阅读,我可以在我的程序中使用此功能。如果我不能的话,请告诉我。我会尝试找出一种不同的方法来做到这一点。

我正在使用Windows 7VS2012,并且似乎一切都正确链接。希望我提供了我需要的所有信息。

#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);
}
}
}

最佳答案

I have GLEW initiated properly, right after the Context creation but before I call glfwMakeContextCurrent()

好吧,这就是你的问题 right there :

Successful creation does not change which context is current. Before you can use the newly created context, you need to make it current using glfwMakeContextCurrent.

调用glewInit()之后glfwMakeContextCurrent()

关于opengl - 无法使用 OpenGL 中的某些函数 (glGenBuffers),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19798750/

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