title: How to use more than one shader program?
body: <p>Using one shader program my code looks something like this: </p>
  
  <pre><code>glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  InitFunctions();
  glUseProgram(ShaderProgram);
  
  //render objects
  
  glutSwapBuffers();
  </code></pre>
  
  <p>But I wanted to add another shader program but it seems to clear the screen. Even just putting this after rendering the objects clears the screen: </p>
  
  <pre><code>glUseProgram(ShaderProgramNew);
  </code></pre>
  
  <p>The only time the screen it doesn't clear the screen is when I use the same shader in both uses of glUseProgram()</p>
  
  <p>To load the shaders i use this function:</p>
  
  <pre><code>GLuint ShaderProgramManager::loadProgram(char* VertexShaderFileLocation, char*     FragmentShaderFileLocation){
  
  cout &lt;&lt; "Creating Shader...\n";
  cout &lt;&lt; "Initalizing Variables\n";
  GLuint ShaderProgram = glCreateProgram();
  GLuint VertexShader = glCreateShader(GL_VERTEX_SHADER);
  GLuint FragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
  
  string VString = loadShader(VertexShaderFileLocation);
  string FString = loadShader(FragmentShaderFileLocation);
  
  const GLchar* VText = (const GLchar*)VString.c_str();
  const GLchar* FText = (const GLchar*)FString.c_str();
  
  cout &lt;&lt; "Load VertexShader and FragmentShader\n";
  
  const GLchar* pp[1];
  pp[0] = FText;
  GLint Lengthss[1];
  Lengthss[0] = strlen(FText);
  glShaderSource(FragmentShader, 1, (const GLchar**)&amp;pp, Lengthss);
  glCompileShader(FragmentShader);
  
  const GLchar* p[1];
  p[0] = VText;
  GLint Lengths[1];
  Lengths[0] = strlen(VText);
  glShaderSource(VertexShader, 1, (const GLchar**)&amp;p, Lengths);
  glCompileShader(VertexShader);
  
  GLint success;
  glGetShaderiv(FragmentShader, GL_COMPILE_STATUS, &amp;success);
  if (!success) {
      GLchar InfoLog[1024];
      glGetShaderInfoLog(FragmentShader, sizeof(InfoLog), NULL, InfoLog);
      fprintf(stderr, "Error compiling shader type %d: '%s'\n", GL_FRAGMENT_SHADER, InfoLog);
  }
  
  
  glGetShaderiv(VertexShader, GL_COMPILE_STATUS, &amp;success);
  if (!success) {
      GLchar InfoLog[1024];
      glGetShaderInfoLog(VertexShader, sizeof(InfoLog), NULL, InfoLog);
      fprintf(stderr, "Error compiling shader type %d: '%s'\n", GL_VERTEX_SHADER, InfoLog);
  }
  
  cout &lt;&lt; "Shaders Compiled.\n";
  
  
  
  cout &lt;&lt; "Attach Shaders\n";
  glAttachShader(ShaderProgram, VertexShader);
  glAttachShader(ShaderProgram, FragmentShader);
  
  cout &lt;&lt; "Link Program\n";
  glLinkProgram(ShaderProgram);
  
  cout &lt;&lt; "Validate Program\n";
  glValidateProgram(ShaderProgram);
  cout &lt;&lt; "Complete.\n";
  return ShaderProgram;
  </code></pre>
  
  <p>}</p>
  
  <p>And this: </p>
  
  <pre><code>string ShaderProgramManager::loadShader(char* location){
  
  string textS = "";
  string line;
  ifstream myfile(location);
  
  cout &lt;&lt; "Start of shader tex:\n" &lt;&lt; "\n";
  
      while (getline(myfile, line))
      {
          //cout &lt;&lt; line &lt;&lt; "\n\n";
          textS = textS + line + "\n";
      }
  
      cout &lt;&lt; "End of shader text" &lt;&lt; "\n";
  
      //text = new char[sizeOfCharArray];
      //strcat(text, textS.c_str());
      myfile.close();
  
      cout &lt;&lt; "Shader Finished Loading.\n";
  
  
      return  textS;
  }
  </code></pre>
  
  <p>At the start of the program i run this</p>
  
  <pre><code>ShaderProgramManager spm;
  
      ShaderProgram = spm.loadProgram("data/Shaders/VertexShader.txt", "data/Shaders/FragmentShader.txt");
  
          gWorldLocation = glGetUniformLocation(ShaderProgram, "gWorld");
          rotmLocation = glGetUniformLocation(ShaderProgram, "rotm");
          PermLocation = glGetUniformLocation(ShaderProgram, "persm");
  </code></pre>