-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdl_context.cpp
More file actions
46 lines (39 loc) · 1.26 KB
/
sdl_context.cpp
File metadata and controls
46 lines (39 loc) · 1.26 KB
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
43
44
45
46
#include "sdl_context.h"
#include <SDL2/SDL_image.h>
#include <iostream>
bool initSDL(SDLContext& ctx, const Config& cfg) {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
std::cerr << "SDL_Init Error: " << SDL_GetError() << "\n";
return false;
}
int imgFlags = IMG_INIT_PNG;
if ((IMG_Init(imgFlags) & imgFlags) != imgFlags) {
std::cerr << "IMG_Init Error: " << IMG_GetError() << "\n";
return false;
}
ctx.window = SDL_CreateWindow(
"Raycaster", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
cfg.screenWidth, cfg.screenHeight, SDL_WINDOW_SHOWN);
if (!ctx.window) {
std::cerr << "SDL_CreateWindow Error: " << SDL_GetError() << "\n";
return false;
}
ctx.renderer = SDL_CreateRenderer(
ctx.window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!ctx.renderer) {
std::cerr << "SDL_CreateRenderer Error: " << SDL_GetError() << "\n";
return false;
}
SDL_SetRenderDrawBlendMode(ctx.renderer, SDL_BLENDMODE_BLEND);
return true;
}
void shutdownSDL(SDLContext& ctx) {
if (ctx.renderer) {
SDL_DestroyRenderer(ctx.renderer);
}
if (ctx.window) {
SDL_DestroyWindow(ctx.window);
}
IMG_Quit();
SDL_Quit();
}