feat: added SDL2_image
parent
5392fd0540
commit
d991db980f
|
@ -18,6 +18,8 @@ env = Environment(CCFLAGS=[
|
||||||
'-Wall', '-Wpedantic', '-Wextra', '-Werror',
|
'-Wall', '-Wpedantic', '-Wextra', '-Werror',
|
||||||
'-O0', '-g3', '-Isrc',
|
'-O0', '-g3', '-Isrc',
|
||||||
'-DPROJECTNAME=\\\"'+project+'\\\"'
|
'-DPROJECTNAME=\\\"'+project+'\\\"'
|
||||||
|
],
|
||||||
|
LINKFLAGS=[
|
||||||
|
'-lSDL2', '-lSDL2_image', '-lm',
|
||||||
])
|
])
|
||||||
env.ParseConfig('sdl2-config --static-libs')
|
|
||||||
env.Program(project, sources)
|
env.Program(project, sources)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <SDL2/SDL_error.h>
|
#include <SDL2/SDL_error.h>
|
||||||
#include <SDL2/SDL_events.h>
|
#include <SDL2/SDL_events.h>
|
||||||
#include <SDL2/SDL_keyboard.h>
|
#include <SDL2/SDL_keyboard.h>
|
||||||
|
#include <SDL2/SDL_image.h>
|
||||||
#include <SDL2/SDL_log.h>
|
#include <SDL2/SDL_log.h>
|
||||||
#include <SDL2/SDL_render.h>
|
#include <SDL2/SDL_render.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
|
@ -20,9 +21,15 @@ CanvasEngine::CanvasEngine() {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to initialize SDL, SDL error: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to initialize SDL, SDL error: %s", SDL_GetError());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(IMG_Init(IMG_INIT_PNG | IMG_INIT_JXL) == 0) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to initialize SDL_image, error: %s", IMG_GetError());
|
||||||
|
SDL_Quit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
this->window = SDL_CreateWindow(PROJECTNAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1000, 800, SDL_WINDOW_FULLSCREEN);
|
this->window = SDL_CreateWindow(PROJECTNAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1000, 800, SDL_WINDOW_FULLSCREEN);
|
||||||
if(this->window == nullptr) {
|
if(this->window == nullptr) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to create window, SDL error: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to create window, SDL error: %s", SDL_GetError());
|
||||||
|
IMG_Quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -30,10 +37,12 @@ CanvasEngine::CanvasEngine() {
|
||||||
if(this->render == nullptr) {
|
if(this->render == nullptr) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to initialize renderer, SDL error: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to initialize renderer, SDL error: %s", SDL_GetError());
|
||||||
SDL_DestroyWindow(this->window);
|
SDL_DestroyWindow(this->window);
|
||||||
|
IMG_Quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->stay_open = true;
|
this->stay_open = true;
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "CANVAS: initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
CanvasEngine::~CanvasEngine() {
|
CanvasEngine::~CanvasEngine() {
|
||||||
|
@ -49,6 +58,7 @@ void CanvasEngine::run() {
|
||||||
// start tracking time
|
// start tracking time
|
||||||
std::timespec_get(&this->startup_ts, TIME_UTC);
|
std::timespec_get(&this->startup_ts, TIME_UTC);
|
||||||
this->frame_start_ts = this->last_frame_start_ts = this->startup_ts;
|
this->frame_start_ts = this->last_frame_start_ts = this->startup_ts;
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "CANVAS: starting");
|
||||||
// main application loop
|
// main application loop
|
||||||
while(stay_open) {
|
while(stay_open) {
|
||||||
// track frame time
|
// track frame time
|
||||||
|
|
Loading…
Reference in New Issue