This commit is contained in:
2025-08-11 13:29:29 -05:00
parent 26ecf67472
commit e9d2f4904a
39 changed files with 569 additions and 829 deletions

View File

@@ -0,0 +1,13 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
render.c
)
# Subdirs
# add_subdirectory(draw)

View File

@@ -0,0 +1,83 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "render.h"
#include "assert/assert.h"
SDL_Window *RENDER_WINDOW;
SDL_Renderer *RENDER_RENDERER;
bool_t RENDER_RUNNING;
errorret_t renderInit(void) {
if(SDL_Init(SDL_INIT_VIDEO) != 0) {
errorThrow(
"SDL Failed to Initialize: %s",
SDL_GetError()
);
}
RENDER_WINDOW = SDL_CreateWindow(
"DuskSDL2",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
RENDER_WINDOW_WIDTH_DEFAULT,
RENDER_WINDOW_HEIGHT_DEFAULT,
SDL_WINDOW_SHOWN
);
#if RENDER_USE_FRAMEBUFFER
printf("Using framebuffer for rendering\n");
#else
printf("Using window for rendering\n");
#endif
RENDER_RENDERER = SDL_CreateRenderer(
RENDER_WINDOW,
-1,
SDL_RENDERER_ACCELERATED
);
if(!RENDER_RENDERER) {
errorThrow("SDL_CreateRenderer failed: %s", SDL_GetError());
}
RENDER_RUNNING = true;
errorOk();
}
errorret_t renderDraw(void) {
SDL_Event event;
while(SDL_PollEvent(&event)) {
if(event.type == SDL_QUIT) {
RENDER_RUNNING = false;
}
}
SDL_SetRenderDrawColor(RENDER_RENDERER, 0, 0, 0, 255);
SDL_RenderClear(RENDER_RENDERER);
// Draw red triangle
SDL_SetRenderDrawColor(RENDER_RENDERER, 255, 0, 0, 255);
SDL_RenderDrawLine(RENDER_RENDERER, 100, 100, 200, 100);
SDL_RenderDrawLine(RENDER_RENDERER, 200, 100, 150, 50);
SDL_RenderDrawLine(RENDER_RENDERER, 150, 50, 100, 100);
SDL_RenderPresent(RENDER_RENDERER);
RENDER_FRAME++;
errorOk();
}
errorret_t renderDispose(void) {
SDL_DestroyRenderer(RENDER_RENDERER);
SDL_DestroyWindow(RENDER_WINDOW);
SDL_Quit();
errorOk();
}

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusksdl2.h"
#include "display/renderbase.h"
#ifndef RENDER_WINDOW_WIDTH_DEFAULT
#define RENDER_WINDOW_WIDTH_DEFAULT RENDER_WIDTH * 3
#endif
#ifndef RENDER_WINDOW_HEIGHT_DEFAULT
#define RENDER_WINDOW_HEIGHT_DEFAULT RENDER_HEIGHT * 3
#endif
#if RENDER_WIDTH == RENDER_WINDOW_WIDTH_DEFAULT && RENDER_HEIGHT == RENDER_WINDOW_HEIGHT_DEFAULT
#define RENDER_USE_FRAMEBUFFER 0
#else
#define RENDER_USE_FRAMEBUFFER 1
#endif
extern SDL_Window *RENDER_WINDOW;
extern SDL_Renderer *RENDER_RENDERER;
extern bool_t RENDER_RUNNING;

View File

@@ -0,0 +1,35 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "renderbackbuffer.h"
#if RENDER_USE_FRAMEBUFFER
SDL_Texture *RENDER_BACKBUFFER;
#else
#endif
void renderBackBufferInit(void) {
#if RENDER_USE_FRAMEBUFFER
RENDER_BACKBUFFER = SDL_CreateTexture(
RENDER_RENDERER,
SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET,
RENDER_WINDOW_WIDTH_DEFAULT,
RENDER_WINDOW_HEIGHT_DEFAULT
);
if(!RENDER_BACKBUFFER) {
assertUnreachable("SDL_CreateTexture failed\n");
return;
}
#else
// No back buffer needed for window rendering
#endif
}

View File

@@ -0,0 +1,9 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusksdl2.h"