Initial commit
This commit is contained in:
63
src/main.cpp
Normal file
63
src/main.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This template contains code for creating an empty
|
||||
* window in OpenGL.
|
||||
*/
|
||||
|
||||
#include "glad/glad.h"
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "classes/Classes.h"
|
||||
|
||||
// Prototypes.
|
||||
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
|
||||
void processInput(GLFWwindow *window);
|
||||
|
||||
// Constants.
|
||||
const unsigned int WINDOW_WIDTH = 800;
|
||||
const unsigned int WINDOW_HEIGHT = 600;
|
||||
|
||||
int main(void) {
|
||||
// Initialisation and configuration.
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
// Create window.
|
||||
GLFWwindow *window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "OpenGL_Project", NULL, NULL);
|
||||
if (window == NULL) {
|
||||
LogInfo("Failed to create GLFW window.");
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
LogInfo("Failed to initialise GLAD.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
processInput(window);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
void processInput(GLFWwindow *window) {
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user