【问题标题】:OpenGL exception when using glCreateVertexArrays使用 glCreateVertexArrays 时的 OpenGL 异常
【发布时间】:2016-07-29 02:31:05
【问题描述】:

我试图通过OpenGL API 为这个application 类编译这个程序:

#include "sb7.h"

using namespace sb7;
class my_application : public application
{
public:

    void startup()
    {
        render_program = compile_shaders();
        glCreateVertexArrays(1, &vertex_array_object);    // <--
        glBindVertexArray(vertex_array_object);
    } 
    void shutdown()
    {
        glDeleteProgram(render_program);
        glDeleteVertexArrays(1, &vertex_array_object);
        glDeleteProgram(render_program);
    }

    void render(double currentTime)
    {
        const GLfloat color[] = {  0.0f, 2.0f, 0.0f, 1.0f };
        glClearBufferfv(GL_COLOR, 0, color);

        glUseProgram(render_program);

        glDrawArrays(GL_TRIANGLES, 0, 3);   
    }
private:
    GLuint render_program;
    GLuint vertex_array_object;
};

DECLARE_MAIN(my_application);  

但是,我遇到了以下例外情况:

startup()函数中这行代码有问题:

void startup()
{
    render_program = compile_shaders();
    glCreateVertexArrays(1, &vertex_array_object);    // <--
    glBindVertexArray(vertex_array_object);
} 

我尝试过使用glGenVertexArrays,但还是没有编译成功。

【问题讨论】:

    标签: c++ opengl exception


    【解决方案1】:

    glCreateVertexArrays 是 OpenGL 4.5 中的一个函数。如果是NULL,那很可能意味着您的程序中当前的 OpenGL 上下文不支持它。

    你确定:

    • 您拥有支持 OpenGL 4.5 的显卡
    • 您的显卡是否有支持 OpenGL 4.5 的驱动程序
    • 您正在使用的框架初始化 OpenGL 4.5 上下文?

    【讨论】:

    • 谢谢!实际上 glGenVertexArrays 工作。此外,GLSL 程序应使用 400 版进行编译。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    • 2017-06-03
    • 2014-11-08
    相关资源
    最近更新 更多