【问题标题】:I cannot access some openGL functions我无法访问某些 openGL 功能
【发布时间】:2021-09-18 09:43:08
【问题描述】:

当我尝试通过执行 glGenBuffer() 函数来生成缓冲区时 - 找不到类似的函数。

一些功能仍在工作,从我看到的大部分工作来看,例如以下代码完美运行:

#include <iostream>
#include <GLFW/glfw3.h>
using namespace std;

class Window_Manager
{
public:
    GLFWwindow* window;

    int Create_Window(int width, int height, const char* title) {
        if (!glfwInit()) {
            return -1;
        }

        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
        glfwWindowHint(GLFW_FOCUSED, GL_TRUE);
        
        window = glfwCreateWindow(width, height, title, NULL, NULL);
        if (window == NULL) {
            cout << "Failed to create a window! Aborting early..." << endl;
            Terminate_Window(window);
            return -1;
        }
        glfwMakeContextCurrent(window);
        
        glViewport(0, 0, width, height); 
        
        return 1;
    }
    
    void Terminate_Window(GLFWwindow* window) {
        glfwSetWindowShouldClose(window, GL_TRUE);
        glfwTerminate();
    }
};

但这段代码没有:

#include <GLFW/glfw3.h>
#include <Engine_Manager.h>
#include <iostream>
using namespace std;
class Shape2D
{
    int VBO;
    int Setting_Up(){
            VBO = glGenBuffer();
            return 1;
    }
};

【问题讨论】:

  • 你的意思是glGenBuffers(复数)吗?
  • 您觉得还有哪些功能没有按预期工作?如果是这样,您可以使用 glGetError
  • 您使用的 C# 帮助程序库的 glGenBuffer() 是一个在内部使用 glGenBuffers() 的便利函数。将您对 glGenBuffer() 的调用替换为:glGenBuffers(1, &amp;BVO); 并研究该函数的文档。这种情况至少还有几个。
  • 除了 GLFW 之外,您可能还必须使用 GLEW。
  • 请编辑您的问题以提供可用于重现问题的minimal reproducible example

标签: c++ opengl glfw


【解决方案1】:

除了在 cmets 中提到的用 glGenBuffers(1, &amp;VBO) 替换 glGenBuffer 之外,OpenGL 是一个奇怪的库,因为您必须动态加载大部分函数。

具体细节因平台而异。例如,在 Windows 上,您可以使用 wglGetProcAddress 获取指向所需函数的指针。

GLEW 不是手动操作,而是一个出色的库,可以轻松获取 OpenGL 函数指针。 Other options are documented on the OpenGL wiki.

【讨论】:

  • OpenGL 不是库。这是一个规范。 API 由图形驱动程序实现。因此你需要一个装载机。
  • “奇怪的库”这个词很烦人。
猜你喜欢
  • 2012-05-31
  • 2020-08-19
  • 2022-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-23
  • 1970-01-01
  • 2014-08-18
相关资源
最近更新 更多