代码之家  ›  专栏  ›  技术社区  ›  Primemaster

错误GLSL版本不正确450

  •  2
  • Primemaster  · 技术社区  · 8 年前

    我有一个OpenGL应用程序,我在过去编译过,但现在不能在同一台机器上。问题似乎在于片段着色器未正确编译。

    • Glfw 3.2.1

    此外,所有必要的上下文都是在程序开始时创建的。下面是我的程序创建函数的外观:

    std::string vSource, fSource;
    try 
    {
        vSource = getSource(vertexShader, "vert");
        fSource = getSource(fragmentShader, "frag");
    }
    catch (std::runtime_error& e)
    {
        std::cout << e.what() << std::endl;
    }
    
    GLuint vsID, fsID;
    try
    {
        vsID = compileShader(vSource.c_str(), GL_VERTEX_SHADER); //Source char* was checked and looking good
        fsID = compileShader(fSource.c_str(), GL_FRAGMENT_SHADER);
    }
    catch (std::runtime_error& e)
    {
        std::cout << e.what() << std::endl; //incorrect glsl version 450 thrown here
    }
    GLuint programID;
    try
    {
        programID = createProgram(vsID, fsID); //Debugging fails here
    }
    catch (std::runtime_error& e)
    {
        std::cout << e.what() << std::endl;
    }
    
    glDeleteShader(vsID);
    glDeleteShader(fsID);
    
    return programID;
    

    我的主要:

    /* ---------------------------- */
    /* OPENGL CONTEXT SET WITH GLEW */
    /* ---------------------------- */
    static bool contextFlag = initializer::createContext(vmath::uvec2(1280, 720), "mWs", window);
    std::thread* checkerThread = new std::thread(initializer::checkContext, contextFlag);
    
    /* --------------------------------- */
    /* STATIC STATE SINGLETON DEFINITION */
    /* --------------------------------- */
    Playing Playing::playingState; //Failing comes from here which tries to create a program
    
    
    
    /* ---- */
    /* MAIN */
    /* ---- */
    int main(int argc, char** argv)
    {
        checkerThread->join();
        delete checkerThread;
    
        Application* app = new Application();
        ...
        return 0;
    }
    

    #version 450 core
    
    out vec4 fColor;
    
    void main()
    {
        fColor = vec4(0.5, 0.4, 0.8, 1.0);
    }
    

    这就是我认为的错误:

    [Engine] Glew initialized! Using version: 2.1.0
    [CheckerThread] Glew state flagged as correct! Proceeding to mainthread!
    
    Error compiling shader: ERROR: 0:1: '' :  incorrect GLSL version: 450
    ERROR: 0:7: 'fColor' : undeclared identifier
    ERROR: 0:7: 'assign' :  cannot convert from 'const 4-component vector of float' to 'float'
    

    我的规格如下:

    • 英伟达GeForce 840M

    我将声明我之前在同一台机器中编译了着色器。磁盘格式化后,我再也做不到了。但是,每个驱动程序都会更新。

    1 回复  |  直到 8 年前
        1
  •  1
  •   Primemaster    8 年前

    如评论中所述,问题似乎在于使用选定的 graphics card

    推荐文章