basic sdl init graphics and engine implementaiton
This commit is contained in:
parent
db1adbb838
commit
685364929b
18 changed files with 257 additions and 7 deletions
0
include/arc/engine/ecs.h
Normal file
0
include/arc/engine/ecs.h
Normal file
27
include/arc/engine/engine.h
Normal file
27
include/arc/engine/engine.h
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef ARC_ENGINE_H_
|
||||||
|
#define ARC_ENGINE_H_
|
||||||
|
|
||||||
|
#include "arc/graphics/window.h"
|
||||||
|
#include "arc/graphics/renderer.h"
|
||||||
|
|
||||||
|
typedef struct ARC_EngineData {
|
||||||
|
ARC_Window *window;
|
||||||
|
ARC_Renderer *renderer;
|
||||||
|
|
||||||
|
} ARC_EngineData;
|
||||||
|
|
||||||
|
//NOTE: most work below is temp, and will change once I figure out a better way to write this header
|
||||||
|
|
||||||
|
void ARC_EngineData_Create(ARC_EngineData **data);
|
||||||
|
void ARC_EngineData_Destroy(ARC_EngineData *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief runs ARC_Engine
|
||||||
|
*
|
||||||
|
* @param data engine data that will be used
|
||||||
|
* data must be created before this function
|
||||||
|
* and must be destroyed after this function
|
||||||
|
*/
|
||||||
|
void ARC_Engine_Run(ARC_EngineData *data);
|
||||||
|
|
||||||
|
#endif // !ARC_ENGINE_H_
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
|
|
||||||
#ifndef ARC_GRAPHICS_DATA_H_
|
|
||||||
#define ARC_GRAPHICS_DATA_H_
|
|
||||||
|
|
||||||
#endif //ARC_GRAPHICS_DATA_H_
|
|
||||||
24
include/arc/graphics/renderer.h
Normal file
24
include/arc/graphics/renderer.h
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef ARC_GRAPHICS_RENDERER_H_
|
||||||
|
#define ARC_GRAPHICS_RENDERER_H_
|
||||||
|
|
||||||
|
typedef struct ARC_Renderer ARC_Renderer;
|
||||||
|
|
||||||
|
typedef struct ARC_RenderInfo ARC_RenderInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief creates ARC_Renderer type
|
||||||
|
*
|
||||||
|
* @note the parameter data is determined by which graphics library you are using
|
||||||
|
* please refer to the graphics library section to see what needs to be passed
|
||||||
|
*
|
||||||
|
* @param renderer ARC_Window to initialize
|
||||||
|
* @param data Data to create ARC_Window
|
||||||
|
*/
|
||||||
|
void ARC_Renderer_Create(ARC_Renderer **renderer, void *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief destroys ARC_Renderer type
|
||||||
|
*/
|
||||||
|
void ARC_Renderer_Destroy(ARC_Renderer *renderer);
|
||||||
|
|
||||||
|
#endif // !ARC_GRAPHICS_RENDERER_H_
|
||||||
22
include/arc/graphics/sdl/renderer.h
Normal file
22
include/arc/graphics/sdl/renderer.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef ARC_SDL_RENDERER_H_
|
||||||
|
#define ARC_SDL_RENDERER_H_
|
||||||
|
|
||||||
|
#ifdef ARC_SDL
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief struct for info needed to create SDL_Renderer
|
||||||
|
*
|
||||||
|
* @note this is what needs to be passed into the data parameter for ARC_Renderer_Create
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct ARC_RenderInfo {
|
||||||
|
ARC_Window *window;
|
||||||
|
int index;
|
||||||
|
Uint32 flags;
|
||||||
|
} ARC_RenderInfo;
|
||||||
|
|
||||||
|
#endif // ARC_SDL
|
||||||
|
|
||||||
|
#endif // ARC_SDL_RENDERER_H_
|
||||||
25
include/arc/graphics/sdl/window.h
Normal file
25
include/arc/graphics/sdl/window.h
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef ARC_SDL_RENDERER_H_
|
||||||
|
#define ARC_SDL_RENDERER_H_
|
||||||
|
|
||||||
|
#ifdef ARC_SDL
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief struct for info needed to create SDL_Window
|
||||||
|
*
|
||||||
|
* @note this is what needs to be passed into the data parameter for ARC_Window_Create
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct ARC_WindowInfo {
|
||||||
|
char *title;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
Uint32 flags;
|
||||||
|
} ARC_WindowInfo;
|
||||||
|
|
||||||
|
#endif // ARC_SDL
|
||||||
|
|
||||||
|
#endif // ARC_SDL_RENDERER_H_
|
||||||
24
include/arc/graphics/window.h
Normal file
24
include/arc/graphics/window.h
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef ARC_GRAPHICS_WINDOW_H_
|
||||||
|
#define ARC_GRAPHICS_WINDOW_H_
|
||||||
|
|
||||||
|
typedef struct ARC_Window ARC_Window;
|
||||||
|
|
||||||
|
typedef struct ARC_WindowInfo ARC_WindowInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief creates ARC_Window type
|
||||||
|
*
|
||||||
|
* @note the parameter data is determined by which graphics library you are using
|
||||||
|
* please refer to the graphics library section to see what needs to be passed
|
||||||
|
*
|
||||||
|
* @param window ARC_Window to initialize
|
||||||
|
* @param data Data to create ARC_Window
|
||||||
|
*/
|
||||||
|
void ARC_Window_Create(ARC_Window **window, void *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief destroys ARC_Window type
|
||||||
|
*/
|
||||||
|
void ARC_Window_Destroy(ARC_Window *window);
|
||||||
|
|
||||||
|
#endif // !ARC_GRAPHICS_WINDOW_H_
|
||||||
0
include/arc/math/rectangle.h
Normal file
0
include/arc/math/rectangle.h
Normal file
30
include/arc/math/vector2.h
Normal file
30
include/arc/math/vector2.h
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef ARC_MATH_VECTOR2_H_
|
||||||
|
#define ARC_MATH_VECTOR2_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct ARC_Vector2 {
|
||||||
|
int32_t x, y;
|
||||||
|
} ARC_Vector2;
|
||||||
|
|
||||||
|
typedef struct ARC_UVector2 {
|
||||||
|
uint32_t x, y;
|
||||||
|
} ARC_UVector2;
|
||||||
|
|
||||||
|
typedef struct ARC_FVector2 {
|
||||||
|
float x, y;
|
||||||
|
} ARC_FVector2;
|
||||||
|
|
||||||
|
typedef struct ARC_DVector2 {
|
||||||
|
double x, y;
|
||||||
|
} ARC_DVector2;
|
||||||
|
|
||||||
|
typedef struct ARC_LVector2 {
|
||||||
|
int64_t x, y;
|
||||||
|
} ARC_LVector2;
|
||||||
|
|
||||||
|
typedef struct ARC_ULVector2 {
|
||||||
|
uint64_t x, y;
|
||||||
|
} ARC_ULVector2;
|
||||||
|
|
||||||
|
#endif // ARC_MATH_VECTOR2_H_
|
||||||
0
include/arc/math/vector3.h
Normal file
0
include/arc/math/vector3.h
Normal file
|
|
@ -138,4 +138,4 @@ void *ARC_Config_GetReference(ARC_Config *config, char *data, ARC_StringSubstr *
|
||||||
|
|
||||||
#ifdef ARC_DEFAULT_CONFIG
|
#ifdef ARC_DEFAULT_CONFIG
|
||||||
#include "defaults/config.h"
|
#include "defaults/config.h"
|
||||||
#endif //ARC_DEFAULT_CONFIG
|
#endif //ARC_DEFAULT_CONFIG
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,10 @@ extern "C" {
|
||||||
#ifdef ARC_DEBUG
|
#ifdef ARC_DEBUG
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# define ARC_DEBUG_LOG(ERR, STR, ...) printf("[ERROR %d] " STR "\n", ERR, __VA_ARGS__)
|
# define ARC_DEBUG_LOG(ERR, STR, ...) printf("[ERROR %d] " STR "\n", ERR, __VA_ARGS__)
|
||||||
|
# define ARC_DEBUG_ERR(STR) printf("[ERROR %d]" STR "\n", ERR)
|
||||||
#else
|
#else
|
||||||
# define ARC_DEBUG_LOG(ERR, STR, ...)
|
# define ARC_DEBUG_LOG(ERR, STR, ...)
|
||||||
|
# define ARC_DEBUG_ERR(STR)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ARC_ERR_CHECK(FUNC) FUNC; if(arc_errno){ ARC_DEBUG_LOG(arc_errno, "%s", #FUNC); return; }
|
#define ARC_ERR_CHECK(FUNC) FUNC; if(arc_errno){ ARC_DEBUG_LOG(arc_errno, "%s", #FUNC); return; }
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ typedef int8_t (* ARC_Vector_CompareDataFn)(void *a, void *b);
|
||||||
/**
|
/**
|
||||||
* @brief creates ARC_Vector type
|
* @brief creates ARC_Vector type
|
||||||
*
|
*
|
||||||
* @param config ARC_Vector to initialize
|
* @param vector ARC_Vector to initialize
|
||||||
|
* @param dataSize size of type the vector will store
|
||||||
*/
|
*/
|
||||||
void ARC_Vector_Create(ARC_Vector **vector, uint32_t dataSize);
|
void ARC_Vector_Create(ARC_Vector **vector, uint32_t dataSize);
|
||||||
|
|
||||||
|
|
|
||||||
0
src/engine/ecs.c
Normal file
0
src/engine/ecs.c
Normal file
43
src/engine/engine.c
Normal file
43
src/engine/engine.c
Normal 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){
|
||||||
|
}
|
||||||
29
src/graphics/sdl/renderer.c
Normal file
29
src/graphics/sdl/renderer.c
Normal 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
28
src/graphics/sdl/window.c
Normal 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
|
||||||
0
tests/vector_test.c
Normal file
0
tests/vector_test.c
Normal file
Loading…
Add table
Add a link
Reference in a new issue