64 lines
1.6 KiB
C
64 lines
1.6 KiB
C
|
#include <stdio.h>
|
||
|
#include <glad/gl.h>
|
||
|
#include <GLFW/glfw3.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
|
||
|
glViewport(0, 0, width, height);
|
||
|
}
|
||
|
|
||
|
void process_input(GLFWwindow *window) {
|
||
|
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||
|
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||
|
}
|
||
|
|
||
|
void init_glfw(int major, int minor) {
|
||
|
if(!glfwInit()) {
|
||
|
fprintf(stderr, "Failed to initialize GLFW\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
|
||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
|
||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
|
||
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||
|
}
|
||
|
|
||
|
GLFWwindow* create_window(int width, int height, const char* title) {
|
||
|
GLFWwindow* window = glfwCreateWindow(width, height, title, NULL, NULL);
|
||
|
if(!window) {
|
||
|
fprintf(stderr, "Failed to create GLFW window\n");
|
||
|
glfwTerminate();
|
||
|
exit(-1);
|
||
|
}
|
||
|
glfwMakeContextCurrent(window);
|
||
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||
|
|
||
|
if (!gladLoadGL((GLADloadfunc)glfwGetProcAddress)) {
|
||
|
fprintf(stderr, "Failed to initialize GLAD\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
|
||
|
glViewport(0, 0, width, height);
|
||
|
|
||
|
return window;
|
||
|
}
|
||
|
|
||
|
int main() {
|
||
|
init_glfw(4, 6);
|
||
|
GLFWwindow* window = create_window(800, 600, "gearlib");
|
||
|
|
||
|
while (!glfwWindowShouldClose(window)) {
|
||
|
process_input(window);
|
||
|
|
||
|
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||
|
|
||
|
glfwSwapBuffers(window);
|
||
|
glfwPollEvents();
|
||
|
}
|
||
|
|
||
|
glfwTerminate();
|
||
|
return 0;
|
||
|
}
|
||
|
|