mirror of
https://github.com/thepigeongenerator/sdl_template.git
synced 2025-12-17 05:55:47 +01:00
implement rendering
This commit is contained in:
@@ -4,12 +4,12 @@
|
||||
|
||||
void game_init(game_data* dat) {
|
||||
(void)dat;
|
||||
error(STATUS_ERROR, "function not defined");
|
||||
//error(STATUS_ERROR, "function not defined");
|
||||
}
|
||||
|
||||
void game_update(game_data* dat) {
|
||||
(void)dat;
|
||||
error(STATUS_ERROR, "function not defined");
|
||||
//error(STATUS_ERROR, "function not defined");
|
||||
}
|
||||
|
||||
void game_free(game_data* dat) {
|
||||
|
||||
@@ -1,19 +1,42 @@
|
||||
#include "render.h"
|
||||
|
||||
#include <SDL_error.h>
|
||||
#include <SDL_render.h>
|
||||
#include <SDL_video.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include "../error.h"
|
||||
#include "../game/game.h"
|
||||
#include "colour/colour32.h"
|
||||
|
||||
void render_init(render_data* const rdat, game_data const* const gdat) {
|
||||
(void)rdat, (void)gdat;
|
||||
error(STATUS_ERROR, "function not implemented");
|
||||
SDL_Window* const window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 100, 100, SDL_WINDOW_SHOWN);
|
||||
if (window == NULL)
|
||||
error(ERROR_SDL_RENDERING_INIT, "failed to create a window. SDL Error: %s", SDL_GetError());
|
||||
|
||||
// rendere using vsync to limit updates to the refresh rate of the monitor
|
||||
SDL_Renderer* const renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
||||
if (renderer == NULL)
|
||||
error(ERROR_SDL_RENDERING_INIT, "failed to create a renderer. SDL Error: %s", SDL_GetError());
|
||||
|
||||
*rdat = (render_data){
|
||||
window,
|
||||
renderer,
|
||||
gdat,
|
||||
};
|
||||
}
|
||||
|
||||
void render_update(render_data const* const rdat) {
|
||||
(void)rdat;
|
||||
error(STATUS_ERROR, "function not implemented");
|
||||
set_colour32(rdat->renderer, COLOUR32_BLACK);
|
||||
SDL_RenderClear(rdat->renderer);
|
||||
|
||||
// present the renderer
|
||||
SDL_RenderPresent(rdat->renderer);
|
||||
}
|
||||
|
||||
void render_free(render_data* const rdat) {
|
||||
(void)rdat;
|
||||
error(STATUS_ERROR, "function not implemented");
|
||||
error(STATUS_ERROR, "function render_free(render_data*) not implemented");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user