mirror of
https://github.com/brammie15/VoxelRenderer.git
synced 2025-12-18 18:49:20 +01:00
Various changes for the Graphics Labs.
This commit is contained in:
committed by
Aleksander Rognhaugen
parent
080537f909
commit
fd306e2e7d
@@ -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<char>(fd),
|
||||
(std::istreambuf_iterator<char>()));
|
||||
|
||||
|
||||
@@ -10,6 +10,13 @@
|
||||
#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()
|
||||
{
|
||||
// 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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -2,15 +2,58 @@
|
||||
#define PROGRAM_HPP
|
||||
#pragma once
|
||||
|
||||
|
||||
// System headers
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/glad.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user