initial commit with demo in main.c
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define WINDOW_WIDTH 1280
|
||||
#define WINDOW_HEIGHT 720
|
||||
#define DEFAULT_WINDOW_NAME "SDL Playground"
|
||||
#define WINDOW_NAME_LENGTH 128
|
||||
#define TARGET_FRAME 1.0 / 60.0
|
||||
|
||||
typedef struct {
|
||||
char window_name[WINDOW_NAME_LENGTH];
|
||||
uint16_t width, height;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *texture;
|
||||
} engine_sdl_state_t;
|
||||
|
||||
typedef struct {
|
||||
/**
|
||||
* this function runs inside of the SDL_PollEvent loop
|
||||
* useful for user input, quitting the program and so on
|
||||
*/
|
||||
void (*engine_poll_events)(void);
|
||||
/**
|
||||
* meant as the "area" for manupulating the framebuffer;
|
||||
* after this is executed, the contents of
|
||||
* game_state->framebuffer get drawn
|
||||
*/
|
||||
void (*engine_update_framebuffer)(void);
|
||||
engine_sdl_state_t *sdl_state;
|
||||
} engine_internal_state_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t framebuffer[WINDOW_WIDTH * WINDOW_HEIGHT];
|
||||
SDL_Event event;
|
||||
bool is_running;
|
||||
uint16_t width, height;
|
||||
} game_state_t;
|
||||
|
||||
extern engine_internal_state_t *internal_state;
|
||||
extern game_state_t *game_state;
|
||||
|
||||
engine_sdl_state_t*
|
||||
engine_sdl_init();
|
||||
|
||||
void
|
||||
engine_sdl_destroy(
|
||||
engine_sdl_state_t *state
|
||||
);
|
||||
|
||||
bool
|
||||
engine_init(
|
||||
void (*engine_poll_events)(void),
|
||||
void (*engine_update_framebuffer)(void)
|
||||
);
|
||||
|
||||
void
|
||||
engine_start();
|
||||
|
||||
void
|
||||
engine_stop();
|
||||
|
||||
void
|
||||
put_pixel(
|
||||
unsigned int x,
|
||||
unsigned int y,
|
||||
uint32_t color
|
||||
);
|
||||
|
||||
void
|
||||
clear_framebuffer(
|
||||
uint32_t color
|
||||
);
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define eprintf(fmt, ...) \
|
||||
fprintf(stderr, "[ERROR] " fmt "\n", ##__VA_ARGS__)
|
||||
|
||||
#define RCODE_FAILURE false
|
||||
#define RCODE_SUCCESS true
|
||||
Reference in New Issue
Block a user