diff --git a/gloom/src/gloom/camera.hpp b/gloom/src/gloom/camera.hpp index 203d4ec..fde98c6 100644 --- a/gloom/src/gloom/camera.hpp +++ b/gloom/src/gloom/camera.hpp @@ -14,54 +14,22 @@ namespace Gloom class Camera { public: - Camera(GLfloat aspect, // aspect = mWidth / mHeight - glm::vec3 position = glm::vec3(0.0f, 0.0f, 2.0f), - GLfloat fov = 45.0f, - GLfloat nearClip = 0.1f, - GLfloat farClip = 1000.0f, - GLfloat movementSpeed = 5.0f, - GLfloat mouseSensitivity = 0.005f) + Camera(glm::vec3 position = glm::vec3(0.0f, 0.0f, 2.0f), + GLfloat movementSpeed = 5.0f, + GLfloat mouseSensitivity = 0.005f) { - cAspect = aspect; cPosition = position; - cFov = fov; - cNearClip = nearClip; - cFarClip = farClip; cMovementSpeed = movementSpeed; cMouseSensitivity = mouseSensitivity; - // Set up default model and projection matrices - matProj = glm::perspective(cFov, cAspect, cNearClip, cFarClip); - matModel = glm::mat4(1.0f); - // Set up the initial view matrix updateViewMatrix(); } // Public member functions - /* Getter for the model, view, and projection matrices */ - void getMVP(glm::mat4 &proj, glm::mat4 &view, glm::mat4 &model) - { - proj = getProjectionMatrix(); - view = getViewMatrix(); - model = getModelMatrix(); - } - - - /* Getters for transformation matrices */ - glm::mat4 getProjectionMatrix() { return matProj; } - glm::mat4 getViewMatrix() { return matView; } - glm::mat4 getModelMatrix() { return matModel; } - - - /* Setter for new aspect ratio */ - void setAspect(GLfloat aspect) { - cAspect = aspect; - - // Update perspective matrix - matProj = glm::perspective(cFov, cAspect, cNearClip, cFarClip); - } + /* Getter for the view matrix */ + glm::mat4 getViewMatrix() { return matView; } /* Handle keyboard inputs from a callback mechanism */ @@ -222,16 +190,9 @@ namespace Gloom // Camera settings GLfloat cMovementSpeed; GLfloat cMouseSensitivity; - GLfloat cFov; - GLfloat cAspect; - GLfloat cNearClip; - GLfloat cFarClip; - // Transformation matrices - glm::mat4 matProj; + // View matrix glm::mat4 matView; - glm::mat4 matModel; - }; } diff --git a/gloom/src/gloom/gloom.hpp b/gloom/src/gloom/gloom.hpp index b718817..a2eccbf 100644 --- a/gloom/src/gloom/gloom.hpp +++ b/gloom/src/gloom/gloom.hpp @@ -10,10 +10,10 @@ #include // Constants -const int mWidth = 1024; -const int mHeight = 768; -const std::string mTitle = "OpenGL"; -const GLint mResizable = GL_FALSE; -const int mSamples = 4; +const int windowWidth = 1024; +const int windowHeight = 768; +const std::string windowTitle = "OpenGL"; +const GLint windowResizable = GL_FALSE; +const int windowSamples = 4; #endif diff --git a/gloom/src/gloom/shader.hpp b/gloom/src/gloom/shader.hpp index 71461eb..bd722be 100644 --- a/gloom/src/gloom/shader.hpp +++ b/gloom/src/gloom/shader.hpp @@ -30,10 +30,11 @@ namespace Gloom { // Load GLSL Shader from source std::ifstream fd(filename.c_str()); - if(fd.fail()) { - fprintf(stderr, + 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", + "The file may not exist or is currently inaccessible.\n", filename.c_str()); return; } diff --git a/gloom/src/main.cpp b/gloom/src/main.cpp index 03d636c..2ee46a2 100644 --- a/gloom/src/main.cpp +++ b/gloom/src/main.cpp @@ -10,7 +10,7 @@ #include -// A callback which allows GLFW to report errors whenever they occur. +// 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); @@ -30,24 +30,23 @@ GLFWwindow* initialise() glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); 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 + glfwWindowHint(GLFW_RESIZABLE, windowResizable); + glfwWindowHint(GLFW_SAMPLES, windowSamples); // MSAA // Create window using GLFW - GLFWwindow* mWindow = glfwCreateWindow(mWidth, - mHeight, - mTitle.c_str(), - nullptr, - nullptr); + GLFWwindow* window = glfwCreateWindow(windowWidth, + windowHeight, + windowTitle.c_str(), + nullptr, + nullptr); // Ensure the window is set up correctly - if (!mWindow) + if (!window) { fprintf(stderr, "Could not open GLFW window\n"); glfwTerminate(); @@ -55,7 +54,7 @@ GLFWwindow* initialise() } // Let the window be the current OpenGL context and initialise glad - glfwMakeContextCurrent(mWindow); + glfwMakeContextCurrent(window); gladLoadGL(); // Print various OpenGL information to stdout @@ -64,17 +63,17 @@ GLFWwindow* initialise() printf("OpenGL\t %s\n", glGetString(GL_VERSION)); printf("GLSL\t %s\n\n", glGetString(GL_SHADING_LANGUAGE_VERSION)); - return mWindow; + return window; } int main(int argc, char* argb[]) { // Initialise window using GLFW - GLFWwindow* mWindow = initialise(); + GLFWwindow* window = initialise(); // Run an OpenGL application using this window - runProgram(mWindow); + runProgram(window); // Terminate GLFW (no need to call glfwDestroyWindow) glfwTerminate(); diff --git a/gloom/src/program.cpp b/gloom/src/program.cpp index e8fa889..259077d 100644 --- a/gloom/src/program.cpp +++ b/gloom/src/program.cpp @@ -3,36 +3,36 @@ #include "gloom/gloom.hpp" -void runProgram(GLFWwindow* mWindow) +void runProgram(GLFWwindow* window) { // Set GLFW callback mechanism(s) - glfwSetKeyCallback(mWindow, keyboardCallback); + glfwSetKeyCallback(window, keyboardCallback); // Enable depth (Z) buffer (accept "closest" fragment) glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); - // Configure miscellaneous OpenGL settings + // 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) + // Set up your scene here (create Vertex Array Objects, etc.) // Rendering Loop - while (!glfwWindowShouldClose(mWindow)) + while (!glfwWindowShouldClose(window)) { // Clear colour and depth buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + // Draw your scene here + // Handle other events glfwPollEvents(); - // Draw your scene here - // Flip buffers - glfwSwapBuffers(mWindow); + glfwSwapBuffers(window); } } diff --git a/gloom/src/program.hpp b/gloom/src/program.hpp index 1660f68..a978e07 100644 --- a/gloom/src/program.hpp +++ b/gloom/src/program.hpp @@ -10,7 +10,7 @@ // Main OpenGL program -void runProgram(GLFWwindow* mWindow); +void runProgram(GLFWwindow* window); // GLFW callback mechanisms @@ -28,29 +28,29 @@ inline void printGLError() { switch(errorID) { case GL_INVALID_ENUM: - errorString = "GL_INVALID_ENUM"; + errorString = "GL_INVALID_ENUM"; break; case GL_INVALID_OPERATION: - errorString = "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"; + errorString = "GL_OUT_OF_MEMORY"; break; case GL_STACK_UNDERFLOW: - errorString = "GL_STACK_UNDERFLOW"; + errorString = "GL_STACK_UNDERFLOW"; break; case GL_STACK_OVERFLOW: - errorString = "GL_STACK_OVERFLOW"; + errorString = "GL_STACK_OVERFLOW"; break; default: - errorString = "[Unknown error ID]"; + errorString = "[Unknown error ID]"; break; } - fprintf(stderr, "An OpenGL error occurred (%i): %s.\n", + fprintf(stderr, "An OpenGL error occurred (%i): %s.\n", errorID, errorString.c_str()); } }