使用glCreateVertexArrays时的OpenGL异常

时间:2016-07-29 02:31:06

标签: c++ opengl exception

我试图通过OpenGL APIapplication课程编译此程序:

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

但是,我有以下例外情况: enter image description here

它表示startup()函数中的这行代码存在问题:

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

我尝试过使用glGenVertexArrays,但仍然无法成功编译。

1 个答案:

答案 0 :(得分:0)

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

你确定:

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