C++ 如何";“升级”;到Ubuntu 18.04.3上的OpenGL 3.3

C++ 如何";“升级”;到Ubuntu 18.04.3上的OpenGL 3.3,c++,opengl,opengl-3,C++,Opengl,Opengl 3,我已经读了很多关于这方面的书,但还没有解决任何问题。我试图用OpenGL3绘制彩色三角形,但出现以下错误: 抛出“std::runtime_error”what():顶点着色器的编译错误(来自文件。/TP1/shaders/triangle.vs.glsl):0:1(10):错误:不支持glsl 3.30。支持的版本有:1.10、1.20、1.30、1.00 ES、3.00 ES、3.10 ES和3.20 ES 当我运行glxinfo | grep-I opengl时,我得到: OpenGL v

我已经读了很多关于这方面的书,但还没有解决任何问题。我试图用OpenGL3绘制彩色三角形,但出现以下错误:

抛出“std::runtime_error”what():顶点着色器的编译错误(来自文件。/TP1/shaders/triangle.vs.glsl):0:1(10):错误:不支持glsl 3.30。支持的版本有:1.10、1.20、1.30、1.00 ES、3.00 ES、3.10 ES和3.20 ES

当我运行glxinfo | grep-I opengl时,我得到:

OpenGL vendor string: Intel Open Source Technology Center 
OpenGL renderer string: Mesa DRI Intel(R) HD Graphics 6000 (Broadwell GT3)  
OpenGL core profile version string: 3.3 (Core Profile) Mesa 19.0.8 
OpenGL core profile shading language version string: 4.50 
OpenGL core profile context flags: (none) 
OpenGL core profile profile mask: core profile 
OpenGL version string: 3.0 Mesa 19.0.8
OpenGL shading language version string: 4.50 
OpenGL context flags: (none) 
OpenGL profile mask: compatibility profile 
OpenGL extensions: 
OpenGL ES profile version string: 
OpenGL ES 3.1 Mesa 19.0.8 
OpenGL ES profile shading language version string:
OpenGL ES GLSL ES 3.10 
OpenGL ES profile extensions:
我尝试了导出MESA\u GL\u VERSION\u OVERRIDE=3.3,这使我能够执行代码,但我得到了一个奇怪的三角形,而不是一个漂亮的等边多色三角形。 以下是我的完整代码:

#include <glimac/SDLWindowManager.hpp>
#include <GL/glew.h>
#include <iostream>
#include <glimac/Program.hpp>
#include <glimac/FilePath.hpp>

using namespace glimac;

int main(int argc, char** argv) {

    // Initialize SDL and open a window
    SDLWindowManager windowManager(800, 600, "GLImac");

    // Initialize glew for OpenGL3+ support
    GLenum glewInitError = glewInit();
    if(GLEW_OK != glewInitError) {
        std::cerr << glewGetErrorString(glewInitError) << std::endl;
        return EXIT_FAILURE;
    }

    std::cout << "OpenGL Version : " << glGetString(GL_VERSION) << std::endl;
    std::cout << "GLEW Version : " << glewGetString(GLEW_VERSION) << std::endl;

    //load shaders and tell OpenGL to use them
    FilePath applicationPath(argv[0]);
    Program program = loadProgram(applicationPath.dirPath() + "shaders/triangle.vs.glsl",
                                    applicationPath.dirPath() + "shaders/triangle.fs.glsl");
    program.use();

    GLuint vbo;
    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo); 

    //triangle data
    GLfloat vertices[] = { -0.5f, -0.5f, 1.f, 0.f, 0.f, //2 coordinates + 1 0 0 color
                         0.5f, -0.5f, 0.f, 1.f, 0.f,
                         0.0f, 0.5f, 0.f, 0.f, 1.f };

    glBufferData(GL_ARRAY_BUFFER, (15*(sizeof(float))), vertices, GL_STATIC_DRAW);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    GLuint vao;
    glGenVertexArrays(1, &vao); 
    glBindVertexArray(vao);
    const GLuint VERTEX_ATTR_POSITION = 3;
    const GLuint VERTEX_ATTR_COLOR = 8;
    glEnableVertexAttribArray(VERTEX_ATTR_POSITION);
    glEnableVertexAttribArray(VERTEX_ATTR_COLOR);

    const GLvoid* bouche;
    glVertexAttribPointer(VERTEX_ATTR_POSITION, 2, GL_FLOAT, GL_FALSE, (0*sizeof(GL_FLOAT)), bouche);
    glVertexAttribPointer(VERTEX_ATTR_COLOR, 3, GL_FLOAT, GL_FALSE, (2*sizeof(GL_FLOAT)), bouche);

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glVertexAttribPointer(VERTEX_ATTR_POSITION, 2, GL_FLOAT, GL_FALSE, (2*sizeof(GL_FLOAT)), 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glBindVertexArray(0);


    // Application loop:
    bool done = false;
    while(!done) {
        // Event loop:
        SDL_Event e;
        while(windowManager.pollEvent(e)) {
            if(e.type == SDL_QUIT) {
                done = true; // Leave the loop after this iteration
            }
        }

        //clean window
        glClear(GL_COLOR_BUFFER_BIT);
        glBindVertexArray(vao);
        glDrawArrays(GL_TRIANGLES, 0, 3);
        glBindVertexArray(0);

        // Update the display
        windowManager.swapBuffers();
    }

    //liberate allocated memory on GPU (the vbo and vao)
    glDeleteBuffers(1, &vbo);
    glDeleteVertexArrays(1, &vao);
    return EXIT_SUCCESS;
}
#包括
#包括
#包括
#包括
#包括
使用glimac;
int main(int argc,字符**argv){
//初始化SDL并打开一个窗口
SDLWindowManager windowManager(800600,“GLImac”);
//为OpenGL3+支持初始化glew
GLenum Glewiniter错误=glewInit();
如果(GLEW_OK!=glewInitError){

std::cerr使用glew时,通过
glewExperimental=GL\u TRUE;
启用其他扩展。请参阅说明:

GLEW从图形驱动程序获取有关受支持扩展的信息。但是,实验或预发布驱动程序可能不会通过标准机制报告每个可用扩展,在这种情况下,GLEW将报告它不受支持。为了避免这种情况,可以通过s打开
glewExperimental
全局开关在调用
glewInit()
之前将其设置为
GL\u TRUE
,这将确保所有具有有效入口点的扩展都将被公开

glewExperimental=GL\u TRUE;
GLenum Glewiniter错误=glewInit();
如果(GLEW_OK!=glewInitError){

你为什么会出错?我以为你得到的是“一个奇怪的三角形,不是一个漂亮的等边多色三角形”。的答案可能会有所帮助。我得到的错误与我段落开头所述的相同:错误:GLSL 3.30不受支持。如果我再次执行导出MESA_GL_VERSION_OVERRIDE=3.3命令,经过您对代码的修改,我不会得到任何三角形。@Monica
glewExperimental=GL_TRUE;
缺失。我已扩展了answ呃,看第一段。