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/
|
|
|
|
|
2024-04-19 21:35:25 +00:00
|
|
|
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) {
|
2024-04-19 21:35:25 +00:00
|
|
|
glfwSetWindowShouldClose(w, GL_TRUE);
|
2024-04-08 20:08:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-19 21:35:25 +00:00
|
|
|
int main() {
|
|
|
|
// Initialise GLFW
|
2024-04-08 20:08:39 +00:00
|
|
|
if (!glfwInit()) {
|
2024-04-19 21:35:25 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2024-04-08 20:08:39 +00:00
|
|
|
}
|
|
|
|
|
2024-04-19 21:35:25 +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();
|
2024-04-19 21:35:25 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2024-04-08 20:08:39 +00:00
|
|
|
}
|
|
|
|
glfwMakeContextCurrent(w);
|
2024-04-19 21:35:25 +00:00
|
|
|
glfwSwapInterval(1); // Essentially vsync
|
|
|
|
gladLoadGL(glfwGetProcAddress); // Load openGL using glfw
|
2024-04-08 20:08:39 +00:00
|
|
|
|
2024-04-19 21:35:25 +00:00
|
|
|
// Set up the key handler
|
|
|
|
glfwSetKeyCallback(w, key_callback);
|
2024-04-08 20:08:39 +00:00
|
|
|
|
2024-04-19 21:35:25 +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
|
|
|
|
2024-04-19 21:35:25 +00:00
|
|
|
// TODO: Actually make some opengl shit happen
|
|
|
|
|
|
|
|
// Main Loop
|
2024-04-08 20:08:39 +00:00
|
|
|
while(!glfwWindowShouldClose(w)) {
|
2024-04-19 21:35:25 +00:00
|
|
|
/*
|
|
|
|
int width, height;
|
2024-04-08 20:08:39 +00:00
|
|
|
glfwGetFramebufferSize(w, &width, &height);
|
2024-04-19 21:35:25 +00:00
|
|
|
|
2024-04-08 20:08:39 +00:00
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2024-04-19 21:35:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// TODO Draw primitives
|
|
|
|
|
2024-04-08 20:08:39 +00:00
|
|
|
glfwSwapBuffers(w);
|
|
|
|
glfwPollEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
glfwDestroyWindow(w);
|
|
|
|
glfwTerminate();
|
2024-04-19 21:35:25 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2024-04-08 20:08:39 +00:00
|
|
|
}
|