basic sdl init graphics and engine implementaiton

This commit is contained in:
herbglitch 2022-10-29 00:22:23 -06:00
parent db1adbb838
commit 685364929b
18 changed files with 257 additions and 7 deletions

0
src/engine/ecs.c Normal file
View file

43
src/engine/engine.c Normal file
View file

@ -0,0 +1,43 @@
#include "arc/engine/engine.h"
#include <stdlib.h>
//NOTE: this is very temp, mostly to get smthn running so I can test out different ideas
#ifdef ARC_SDL
#include <SDL.h>
#include "arc/graphics/sdl/rerderer.h"
#endif
void ARC_EngineData_Create(ARC_EngineData **data){
*data = (ARC_EngineData *)malloc(sizeof(ARC_EngineData));
(*data)->window = NULL;
(*data)->renderer = NULL;
ARC_WindowInfo windowInfo;
ARC_RenderInfo renderInfo;
#ifdef ARC_SDL
if(SDL_Init(SDL_INIT_VIDEO) < 0){
printf("Error: initializing SDL\nSDL Error: ", SDL_GetError());
free(*data);
return;
}
windowInfo = { "title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920, 1080, 0 };
renderInfo = { (*data)->window, -1, SDL_RENDERER_ACCELERATED }
#endif // ARC_SDL
ARC_Window_Create(&((*data)->window), &windowInfo);
//TODO: handle arc_errno errors here
ARC_Renderer_Create(&((*data)->renderer), &renderInfo);
//TODO: handle arc_errno errors here
}
void ARC_EngineData_Destroy(ARC_EngineData *data){
#ifdef ARC_SDL
ARC_Renderer_Destroy(data->renderer);
ARC_Renderer_Destroy(data->window);
#endif // ARC_SDL
}
void ARC_Engine_Run(ARC_EngineData *data){
}

View file

@ -0,0 +1,29 @@
#ifdef ARC_SDL
#include "arc/graphics/renderer.h"
#include "arc/graphics/window.h"
#include "arc/std/errno.h"
typedef SDL_Renderer ARC_Renderer;
ARC_Renderer_Create(ARC_Renderer **renderer, void *data){
if(!data){
arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR(arc_errno, "ARC_Renderer_Create(**renderer, NULL)");
return;
}
ARC_RenderInfo *info = (ARC_RenderInfo *)data;
*renderer = SDL_CreateRenderer(info->window, info->index, info->flags);
if(!renderer){
arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_LOG(arc_errno, "SDL_CreateRenderer(%p, %d, %u);", info->window, info->index, info->flags);
}
}
void ARC_Renderer_Destroy(ARC_Renderer *renderer){
SDL_DestroyRenderer((SDL_Renderer *) renderer);
}
#endif //ARC_SDL

28
src/graphics/sdl/window.c Normal file
View file

@ -0,0 +1,28 @@
#ifdef ARC_SDL
#include "arc/graphics/window.h"
#include "arc/std/errno.h"
typedef SDL_Window ARC_Window;
void ARC_Window_Create(ARC_Window **window, void *data){
if(!data){
arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_ERR(arc_errno, "ARC_Window_Create(**window, NULL)");
return;
}
ARC_WindowInfo *info = (ARC_WindowInfo *)data;
*window = SDL_CreateWindow((const char *)info->title, info->x, info->y, info->w, info->h, info->flags);
if(!window){
arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_LOG(arc_errno, "SDL_CreateWindow(%s, %d, %d, %d, %d, %x);", info->title, info->x, info->y, info->w, info->h, info->flags);
}
}
void ARC_Window_Destroy(ARC_Window *window){
SDL_DestroyWindow((SDL_Window *) window);
}
#endif //ARC_SDL