diff --git a/gloom/shaders/simple.frag b/gloom/shaders/simple.frag index 821f772..91f8fff 100644 --- a/gloom/shaders/simple.frag +++ b/gloom/shaders/simple.frag @@ -1,4 +1,4 @@ -#version 400 core +#version 430 core out vec4 color; diff --git a/gloom/shaders/simple.vert b/gloom/shaders/simple.vert index 3a63f22..1178ec6 100644 --- a/gloom/shaders/simple.vert +++ b/gloom/shaders/simple.vert @@ -1,4 +1,4 @@ -#version 400 core +#version 430 core in vec3 position; diff --git a/gloom/src/gloom/shader.hpp b/gloom/src/gloom/shader.hpp index dcca511..71461eb 100644 --- a/gloom/src/gloom/shader.hpp +++ b/gloom/src/gloom/shader.hpp @@ -30,6 +30,13 @@ namespace Gloom { // Load GLSL Shader from source std::ifstream fd(filename.c_str()); + if(fd.fail()) { + fprintf(stderr, + "Something went wrong when attaching the Shader file at \"%s\".\n" + "The file may not exist or is currently inaccessible.\n", + filename.c_str()); + return; + } auto src = std::string(std::istreambuf_iterator(fd), (std::istreambuf_iterator())); diff --git a/gloom/src/main.cpp b/gloom/src/main.cpp index e156420..03d636c 100644 --- a/gloom/src/main.cpp +++ b/gloom/src/main.cpp @@ -10,6 +10,13 @@ #include +// A callback which allows GLFW to report errors whenever they occur. +static void glfwErrorCallback(int error, const char *description) +{ + fprintf(stderr, "GLFW returned an error:\n\t%s (%i)\n", description, error); +} + + GLFWwindow* initialise() { // Initialise GLFW @@ -21,10 +28,13 @@ GLFWwindow* initialise() // Set core window options (adjust version numbers if needed) glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + // Enable the GLFW runtime error callback function defined previously. + glfwSetErrorCallback(glfwErrorCallback); + // Set additional window options glfwWindowHint(GLFW_RESIZABLE, mResizable); glfwWindowHint(GLFW_SAMPLES, mSamples); // MSAA diff --git a/gloom/src/program.cpp b/gloom/src/program.cpp index e17db86..e8fa889 100644 --- a/gloom/src/program.cpp +++ b/gloom/src/program.cpp @@ -12,9 +12,14 @@ void runProgram(GLFWwindow* mWindow) glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); + // Configure miscellaneous OpenGL settings + glEnable(GL_CULL_FACE); + // Set default colour after clearing the colour buffer glClearColor(0.3f, 0.3f, 0.4f, 1.0f); + // Set up your scene here (create Vertex Array Objects, etc) + // Rendering Loop while (!glfwWindowShouldClose(mWindow)) { @@ -24,6 +29,8 @@ void runProgram(GLFWwindow* mWindow) // Handle other events glfwPollEvents(); + // Draw your scene here + // Flip buffers glfwSwapBuffers(mWindow); } diff --git a/gloom/src/program.hpp b/gloom/src/program.hpp index 5c4bc53..1660f68 100644 --- a/gloom/src/program.hpp +++ b/gloom/src/program.hpp @@ -2,15 +2,58 @@ #define PROGRAM_HPP #pragma once + // System headers #include +#include +#include // Main OpenGL program void runProgram(GLFWwindow* mWindow); + // GLFW callback mechanisms void keyboardCallback(GLFWwindow* window, int key, int scancode, int action, int mods); + +// Checks for whether an OpenGL error occurred. If one did, +// it prints out the error type and ID +inline void printGLError() { + int errorID = glGetError(); + + if(errorID != GL_NO_ERROR) { + std::string errorString; + + switch(errorID) { + case GL_INVALID_ENUM: + errorString = "GL_INVALID_ENUM"; + break; + case GL_INVALID_OPERATION: + errorString = "GL_INVALID_OPERATION"; + break; + case GL_INVALID_FRAMEBUFFER_OPERATION: + errorString = "GL_INVALID_FRAMEBUFFER_OPERATION"; + break; + case GL_OUT_OF_MEMORY: + errorString = "GL_OUT_OF_MEMORY"; + break; + case GL_STACK_UNDERFLOW: + errorString = "GL_STACK_UNDERFLOW"; + break; + case GL_STACK_OVERFLOW: + errorString = "GL_STACK_OVERFLOW"; + break; + default: + errorString = "[Unknown error ID]"; + break; + } + + fprintf(stderr, "An OpenGL error occurred (%i): %s.\n", + errorID, errorString.c_str()); + } +} + + #endif