Advertisement
Kirabo

Untitled

Nov 1st, 2017
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. const char* read_from_file(const GLchar* shader_path)
  2. {
  3.     std::string shader_code;
  4.     std::ifstream shader_file;
  5.  
  6.     shader_file.exceptions (std::ifstream::failbit | std::ifstream::badbit);
  7.  
  8.     try
  9.     {
  10.         // open files
  11.         shader_file.open(shader_path);
  12.         std::stringstream shader_stream;
  13.  
  14.         // read file's buffer contents into streams
  15.         shader_stream << shader_file.rdbuf();
  16.  
  17.         shader_file.close();
  18.  
  19.         // convert stream into string
  20.         shader_code = shader_stream.str();
  21.     }
  22.     catch(std::ifstream::failure &e)
  23.     {
  24.         std::cout << "ERROR: Shader file not succesfully read. Check path to shader source file!" << std::endl;
  25.     };
  26.  
  27.     const char* final_shader_code = shader_code.c_str();
  28.  
  29.     return final_shader_code;
  30. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement