title: How to Practically Ship GLSL Shaders with your C++ Software
body: <p>During OpenGL initialization, the program is supposed to do something like:</p>
  
  <pre class="lang-none prettyprint-override"><code>&lt;Get Shader Source Code&gt;
  &lt;Create Shader&gt;
  &lt;Attach Source Code To Shader&gt;
  &lt;Compile Shader&gt;
  </code></pre>
  
  <p>Getting source code could be as simple as putting it in a string like:
  (Example taken from <a href="http://www.openglsuperbible.com/" rel="noreferrer"><strong>SuperBible, 6th Edition</strong></a>)</p>
  
  <pre class="lang-cxx prettyprint-override"><code>static const char * vs_source[] =
  {
      "#version 420 core                             \n"
      "                                              \n"
      "void main(void)                               \n"
      "{                                             \n"
      "    gl_Position = vec4(0.0, 0.0, 0.0, 1.0);   \n"
      "}                                             \n"
  };
  </code></pre>
  
  <p>The problem is that it is hard to edit, debug and maintain GLSL shaders directly in a string. So getting the source code in a string from a file is easier for development:</p>
  
  <pre class="lang-cxx prettyprint-override"><code>std::ifstream vertexShaderFile("vertex.glsl");
  std::ostringstream vertexBuffer;
  vertexBuffer &lt;&lt; vertexShaderFile.rdbuf();
  std::string vertexBufferStr = vertexBuffer.str();
  // Warning: safe only until vertexBufferStr is destroyed or modified
  const GLchar *vertexSource = vertexBufferStr.c_str();
  </code></pre>
  
  <p>The problem now is how to ship the shaders with your program? Indeed, shipping source code with your application may be a problem. OpenGL supports "pre-compiled binary shaders" but the <a href="http://www.opengl.org/wiki/Shader_Compilation#Binary_limitations" rel="noreferrer"><strong>Open Wiki</strong></a> states that:</p>
  
  <blockquote>
    <p>Program binary formats are not intended to be
    transmitted. It is not reasonable to expect different hardware vendors
    to accept the same binary formats. It is not reasonable to expect
    different hardware from the same vendor to accept the same binary
    formats. [...]</p>
  </blockquote>
  
  <p><strong>How to practically ship GLSL shaders with your C++ software?</strong></p>