From 2759a3f45b5cd095bb79eff77b35978c8f8069c6 Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Sat, 10 Mar 2018 20:34:35 +0100 Subject: Prepare install script, and make shader loading work from PREFIX/share/... --- BuddhaTest/src/Helpers.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'BuddhaTest/src/Helpers.cpp') diff --git a/BuddhaTest/src/Helpers.cpp b/BuddhaTest/src/Helpers.cpp index 889db7e..cb48d94 100644 --- a/BuddhaTest/src/Helpers.cpp +++ b/BuddhaTest/src/Helpers.cpp @@ -11,7 +11,7 @@ namespace Helpers { - GLuint LoadShaders(const char * vertex_file_path, const char * fragment_file_path) { + GLuint LoadShaders(const std::string& vertex_file_path, const std::string& fragment_file_path) { // Create the shaders GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER); @@ -27,8 +27,7 @@ namespace Helpers VertexShaderStream.close(); } else { - printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", vertex_file_path); - getchar(); + std::cerr << "Failed to load vertex shader file from " << vertex_file_path << ". Is this installed correctly?" << std::endl; return 0; } @@ -41,12 +40,17 @@ namespace Helpers FragmentShaderCode = sstr.str(); FragmentShaderStream.close(); } + else + { + std::cerr << "Failed to load fragment shader file from " << fragment_file_path << ". Is this installed correctly?" << std::endl; + return 0; + } GLint Result = GL_FALSE; int InfoLogLength; // Compile Vertex Shader - printf("Compiling shader : %s\n", vertex_file_path); + std::cout << "Compiling shader : " << vertex_file_path << std::endl; char const * VertexSourcePointer = VertexShaderCode.c_str(); glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL); glCompileShader(VertexShaderID); @@ -62,7 +66,7 @@ namespace Helpers // Compile Fragment Shader - printf("Compiling shader : %s\n", fragment_file_path); + std::cout << "Compiling shader : " << fragment_file_path; char const * FragmentSourcePointer = FragmentShaderCode.c_str(); glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL); glCompileShader(FragmentShaderID); @@ -101,7 +105,7 @@ namespace Helpers return ProgramID; } - GLuint LoadComputeShader(const char* compute_file_path, unsigned int localSizeX, unsigned int localSizeY, unsigned int localSizeZ) + GLuint LoadComputeShader(const std::string& compute_file_path, unsigned int localSizeX, unsigned int localSizeY, unsigned int localSizeZ) { GLuint ComputeShaderID = glCreateShader(GL_COMPUTE_SHADER); // Read the compute shader @@ -119,6 +123,11 @@ namespace Helpers ComputeShaderCode = sstr.str(); ComputeShaderCodeStream.close(); } + else + { + std::cerr << "Failed to load compute shader file from " << compute_file_path << ". Is this installed correctly?" << std::endl; + return 0; + } } GLint Result = GL_FALSE; @@ -126,7 +135,7 @@ namespace Helpers { // Compile Compute Shader - printf("Compiling shader : %s\n", compute_file_path); + std::cout << "Compiling shader : " << compute_file_path << std::endl; char const * ComputeSourcePointer = ComputeShaderCode.c_str(); glShaderSource(ComputeShaderID, 1, &ComputeSourcePointer, NULL); glCompileShader(ComputeShaderID); @@ -335,8 +344,8 @@ namespace Helpers std::cout << "Draws a buddhabrot and iterates until the user closes the window. If a --output filename is given, a png file will afterwards be written there." <