OpenGL Shader Loader in C++
for (auto info : shader_info) -&gt; for (auto const&amp; info : shader_info) to avoid a string copy.

Reading the source file into a string should probably be a separate function.

We should throw an error if the file fails to open. (tellg will return -1 in that case).

I find it's often helpful to output more than one shader object log before stopping compilation (for example, if we have a minor error in the vertex shader, and another one in the fragment shader, we can see and fix both at once, rather than only having the vertex shader error in the log).


e.g.:
GLuint LoadShaders(const std::vector&lt;ShaderInfo&gt;&amp; shader_info) {
    // ...
    bool compiled = true; // flag to indicate overall compile status

    for (auto const&amp; info : shader_info) {
        // ... read file and compile shader

        GLint status;
        glGetShaderiv(shader, GL_COMPILE_STATUS, &amp;status);

        if (status == GL_FALSE) {
            // ... get log string
            
            // log the error (if you have an existing logging system, or print to std::cerr)
            LogError(&quot;glCompileShader() failed for shader object: &quot; + info.file);
            LogError(log);
            
            compiled = false; // set the overall flag to false
        }
    }
    
    // and now we throw!
    if (!compiled) {
        glDeleteProgram(program);
        throw std::runtime_error(&quot;Shader compilation failed!&quot;);
    }

    // ... link program etc. as before
}