blob: 894a42b17e8fa4be200bee7e2dca62e1c42b5e2b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "window.h"
#include "glad/glad.h"
#include "config.h"
#include <stdio.h>
int window_init(struct window* window) {
SDL_Init(SDL_INIT_VIDEO);
// This will call SDL_GL_LoadLibrary so you don't need glad to do anything
window->window = SDL_CreateWindow("Junkcraft", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL);
SDL_GLContext* ctx = SDL_GL_CreateContext(window->window);
// Let GLAD use the SDL GetProcAddress loader instead of using its own
int version = gladLoadGLLoader(SDL_GL_GetProcAddress);
if (version == 0) {
printf("Failed to initialize OpenGL context\n");
return -1;
}
printf("Loaded OpenGL %s\n", glGetString(GL_VERSION));
printf("System: %s\n", glGetString(GL_RENDERER));
if (window == NULL) {
perror("Failed to create window!");
SDL_DestroyWindow(window->window);
SDL_Quit();
return -1;
}
window->renderer = SDL_CreateRenderer(window->window, -1, SDL_RENDERER_ACCELERATED);
if (window->renderer == NULL) {
perror("Failed to create renderer!");
SDL_DestroyWindow(window->window);
SDL_Quit();
return -1;
}
SDL_ShowWindow(window->window);
return 0;
}
void window_cleanup(struct window* window) {
SDL_DestroyWindow(window->window);
SDL_Quit();
}
|