Exponent/src/main.cc

62 lines
1.6 KiB
C++
Raw Normal View History

2024-04-08 20:08:39 +00:00
#define GLAD_GL_IMPLEMENTATION
#include "glad/gl.h"
#define GLFW_INCLUDE_NONE
#include "GLFW/glfw3.h"
2024-04-19 21:54:25 +00:00
//http://seshbot.com/blog/2015/05/05/an-introduction-to-opengl-getting-started/
static void key_callback(GLFWwindow *w, int key, int scancode, int action, int mods) {
2024-04-08 20:08:39 +00:00
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(w, GL_TRUE);
2024-04-08 20:08:39 +00:00
}
}
int main() {
// Initialise GLFW
2024-04-08 20:08:39 +00:00
if (!glfwInit()) {
exit(EXIT_FAILURE);
2024-04-08 20:08:39 +00:00
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
// Create our context
GLFWwindow *w = glfwCreateWindow(640, 480, "Test", NULL, NULL);
2024-04-08 20:08:39 +00:00
if (!w) {
glfwTerminate();
exit(EXIT_FAILURE);
2024-04-08 20:08:39 +00:00
}
glfwMakeContextCurrent(w);
glfwSwapInterval(1); // Essentially vsync
gladLoadGL(glfwGetProcAddress); // Load openGL using glfw
2024-04-08 20:08:39 +00:00
// Set up the key handler
glfwSetKeyCallback(w, key_callback);
2024-04-08 20:08:39 +00:00
// Configure the context's capabilities
glClearColor(1.0, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND); // Maybe this allows transparency?
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2024-04-08 20:08:39 +00:00
// TODO: Actually make some opengl shit happen
// Main Loop
2024-04-08 20:08:39 +00:00
while(!glfwWindowShouldClose(w)) {
/*
int width, height;
2024-04-08 20:08:39 +00:00
glfwGetFramebufferSize(w, &width, &height);
2024-04-08 20:08:39 +00:00
glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT);
*/
// TODO Draw primitives
2024-04-08 20:08:39 +00:00
glfwSwapBuffers(w);
glfwPollEvents();
}
glfwDestroyWindow(w);
glfwTerminate();
exit(EXIT_SUCCESS);
2024-04-08 20:08:39 +00:00
}