Various changes for the Graphics Labs.

This commit is contained in:
bartvbl
2016-09-20 15:17:19 +02:00
committed by Aleksander Rognhaugen
parent 080537f909
commit fd306e2e7d
6 changed files with 70 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
#version 400 core #version 430 core
out vec4 color; out vec4 color;

View File

@@ -1,4 +1,4 @@
#version 400 core #version 430 core
in vec3 position; in vec3 position;

View File

@@ -30,6 +30,13 @@ namespace Gloom
{ {
// Load GLSL Shader from source // Load GLSL Shader from source
std::ifstream fd(filename.c_str()); 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<char>(fd), auto src = std::string(std::istreambuf_iterator<char>(fd),
(std::istreambuf_iterator<char>())); (std::istreambuf_iterator<char>()));

View File

@@ -10,6 +10,13 @@
#include <cstdlib> #include <cstdlib>
// 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() GLFWwindow* initialise()
{ {
// Initialise GLFW // Initialise GLFW
@@ -21,10 +28,13 @@ GLFWwindow* initialise()
// Set core window options (adjust version numbers if needed) // Set core window options (adjust version numbers if needed)
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); 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_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// Enable the GLFW runtime error callback function defined previously.
glfwSetErrorCallback(glfwErrorCallback);
// Set additional window options // Set additional window options
glfwWindowHint(GLFW_RESIZABLE, mResizable); glfwWindowHint(GLFW_RESIZABLE, mResizable);
glfwWindowHint(GLFW_SAMPLES, mSamples); // MSAA glfwWindowHint(GLFW_SAMPLES, mSamples); // MSAA

View File

@@ -12,9 +12,14 @@ void runProgram(GLFWwindow* mWindow)
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS); glDepthFunc(GL_LESS);
// Configure miscellaneous OpenGL settings
glEnable(GL_CULL_FACE);
// Set default colour after clearing the colour buffer // Set default colour after clearing the colour buffer
glClearColor(0.3f, 0.3f, 0.4f, 1.0f); glClearColor(0.3f, 0.3f, 0.4f, 1.0f);
// Set up your scene here (create Vertex Array Objects, etc)
// Rendering Loop // Rendering Loop
while (!glfwWindowShouldClose(mWindow)) while (!glfwWindowShouldClose(mWindow))
{ {
@@ -24,6 +29,8 @@ void runProgram(GLFWwindow* mWindow)
// Handle other events // Handle other events
glfwPollEvents(); glfwPollEvents();
// Draw your scene here
// Flip buffers // Flip buffers
glfwSwapBuffers(mWindow); glfwSwapBuffers(mWindow);
} }

View File

@@ -2,15 +2,58 @@
#define PROGRAM_HPP #define PROGRAM_HPP
#pragma once #pragma once
// System headers // System headers
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <glad/glad.h>
#include <string>
// Main OpenGL program // Main OpenGL program
void runProgram(GLFWwindow* mWindow); void runProgram(GLFWwindow* mWindow);
// GLFW callback mechanisms // GLFW callback mechanisms
void keyboardCallback(GLFWwindow* window, int key, int scancode, void keyboardCallback(GLFWwindow* window, int key, int scancode,
int action, int mods); 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 #endif