44 lines
1.1 KiB
C
44 lines
1.1 KiB
C
|
#include <init.h>
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <events.h>
|
||
|
|
||
|
#include <opengl.h>
|
||
|
|
||
|
void init_gl(int major, int minor) {
|
||
|
if(!glfwInit()) {
|
||
|
printf("[GLFW] Failed to initialize\n");
|
||
|
exit(-1);
|
||
|
} else {
|
||
|
printf("[GLFW] Initialized successfully\n");
|
||
|
}
|
||
|
|
||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
|
||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
|
||
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||
|
}
|
||
|
|
||
|
Window create_window(int width, int height, const char* title) {
|
||
|
Window window = glfwCreateWindow(width, height, title, NULL, NULL);
|
||
|
if(!window) {
|
||
|
printf("[GLFW] Failed to create window\n");
|
||
|
glfwTerminate();
|
||
|
exit(-1);
|
||
|
} else {
|
||
|
printf("[GLFW] Window created successfully\n");
|
||
|
}
|
||
|
glfwMakeContextCurrent(window);
|
||
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||
|
|
||
|
if (!gladLoadGL((GLADloadfunc)glfwGetProcAddress)) {
|
||
|
printf("[GLAD] Failed to initialize\n");
|
||
|
exit(-1);
|
||
|
} else {
|
||
|
printf("[GLAD] Initialized successfully\n");
|
||
|
}
|
||
|
|
||
|
glViewport(0, 0, width, height);
|
||
|
|
||
|
return window;
|
||
|
}
|