text: // miniGraphics is distributed under the OSI-approved BSD 3-clause License.
  // See LICENSE.txt for details.
  //
  // Copyright (c) 2017
  // National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under
  // the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains
  // certain rights in this software.
  
  #include <stdio.h>
  #include <algorithm>
  #include <fstream>
  #include <iostream>
  #include <string>
  #include <vector>
  using namespace std;
  
  #include <stdlib.h>
  #include <string.h>
  
  #include <GL/glew.h>
  
  #include "shader.hpp"
  
  // Special C++11 trick to embed text files into strings at compile time.
  // See
  // https://stackoverflow.com/questions/410980/include-a-text-file-in-a-c-program-as-a-char#answer-25021520
  
  static const char* vertex_shader_source =
  #include "TransformVertexShader.vertexshader"
      ;
  
  static const char* fragment_shader_source =
  #include "ColorFragmentShader.fragmentshader"
      ;
  
  GLuint LoadShaders() {
    // Create the shaders
    GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
    GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
  
    GLint Result = GL_FALSE;
    int InfoLogLength;
  
    // Compile Vertex Shader
    glShaderSource(VertexShaderID, 1, &vertex_shader_source, NULL);
    glCompileShader(VertexShaderID);
  
    // Check Vertex Shader
    glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    if (InfoLogLength > 0) {
      std::vector<char> VertexShaderErrorMessage(InfoLogLength + 1);
      glGetShaderInfoLog(
          VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
      cout << &VertexShaderErrorMessage[0] << endl;
    }
  
    // Compile Fragment Shader
    glShaderSource(FragmentShaderID, 1, &fragment_shader_source, NULL);
    glCompileShader(FragmentShaderID);
  
    // Check Fragment Shader
    glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    if (InfoLogLength > 0) {
      std::vector<char> FragmentShaderErrorMessage(InfoLogLength + 1);
      glGetShaderInfoLog(
          FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
      cout << &FragmentShaderErrorMessage[0] << endl;
    }
  
    // Link the program
    //	printf("Linking program\n");
    GLuint ProgramID = glCreateProgram();
    glAttachShader(ProgramID, VertexShaderID);
    glAttachShader(ProgramID, FragmentShaderID);
    glLinkProgram(ProgramID);
  
    // Check the program
    glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
    glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    if (InfoLogLength > 0) {
      std::vector<char> ProgramErrorMessage(InfoLogLength + 1);
      glGetProgramInfoLog(
          ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
      //		printf("%s\n", &ProgramErrorMessage[0]);
    }
  
    glDetachShader(ProgramID, VertexShaderID);
    glDetachShader(ProgramID, FragmentShaderID);
  
    glDeleteShader(VertexShaderID);
    glDeleteShader(FragmentShaderID);
  
    return ProgramID;
  }
  