Normalize line endings

This commit is contained in:
Tijani Lawal 2024-08-31 13:32:43 -05:00
parent 320ebaace2
commit 9e1e4c2c5c
11 changed files with 543 additions and 471 deletions

248
build.bat
View File

@ -1,124 +1,124 @@
@echo off @echo off
setlocal setlocal
cd /D "%~dp0" cd /D "%~dp0"
:: -- Useage Notes (July 25th, 2024) ---------------------------------------------------------- :: -- Useage Notes (July 25th, 2024) ----------------------------------------------------------
:: ::
:: This is a central build script for use in a windows development environment with support :: This is a central build script for use in a windows development environment with support
:: for msvc(default) and clang, specifically for C/C++ projects. It takes simple alphanumeric :: for msvc(default) and clang, specifically for C/C++ projects. It takes simple alphanumeric
:: arguments which controls (1) what compiler & linker is used, (2) what mode the the :: arguments which controls (1) what compiler & linker is used, (2) what mode the the
:: application is built in. :: application is built in.
:: ::
:: By default if no options are passed, everything is built in debug mode with the MSVC :: By default if no options are passed, everything is built in debug mode with the MSVC
:: compiler :: compiler
:: ::
:: Possible ways to use: :: Possible ways to use:
:: ::
:: `build debug` :: `build debug`
:: `build debug msvc` :: `build debug msvc`
:: `build release clang` :: `build release clang`
:: `build debug tracy` :: `build debug tracy`
:: ::
:: Unpack Arguments :: Unpack Arguments
for %%a in (%*) do set "%%a=1" for %%a in (%*) do set "%%a=1"
if not "%msvc%"=="1" set msvc=1 if not "%msvc%"=="1" set msvc=1
if not "%release%"=="1" set debug=1 if not "%release%"=="1" set debug=1
if "%debug%"=="1" set release=0 && echo [debug mode] if "%debug%"=="1" set release=0 && echo [debug mode]
if "%release%"=="1" set debug=0 && echo [release mode] if "%release%"=="1" set debug=0 && echo [release mode]
if "%msvc%"=="1" set clang=0 && echo [msvc compile] if "%msvc%"=="1" set clang=0 && echo [msvc compile]
if "%clang%"=="1" set msvc=0 && echo [clang compile] if "%clang%"=="1" set msvc=0 && echo [clang compile]
:: Fix :: Fix
if "%~1"=="" echo [default mode] && set ragar=1 if "%~1"=="" echo [default mode] && set ragar=1
if "%~1"=="release" if "%~2"=="" echo [default release mode] && set ragar=1 if "%~1"=="release" if "%~2"=="" echo [default release mode] && set ragar=1
:: Unpack Command Line Build arguments :: Unpack Command Line Build arguments
set auto_compile_flags= set auto_compile_flags=
if "%tracy%"=="1" set auto_compile_flags=%auto_compile_flags% /DTRACY_ENABLE && echo [tracy profiling enabled] if "%tracy%"=="1" set auto_compile_flags=%auto_compile_flags% /DTRACY_ENABLE && echo [tracy profiling enabled]
:: Third Party libraries :: Third Party libraries
set third_party_includes="%~dp0\third_party\\SDL2\\include" set third_party_includes="%~dp0\third_party\\SDL2\\include"
set third_party_lib="%~dp0\third_party\\SDL2\\lib\\x64" set third_party_lib="%~dp0\third_party\\SDL2\\lib\\x64"
:: MSVC :: MSVC
set cl_common= /I..\src\ /nologo /FC /Z7 /I%third_party_includes% set cl_common= /I..\src\ /nologo /FC /Z7 /I%third_party_includes%
set cl_debug= call cl /Od /Ob1 /DBUILD_DEBUG=1 %cl_common% set cl_debug= call cl /Od /Ob1 /DBUILD_DEBUG=1 %cl_common%
set cl_release= call cl /O2 /DBUILD_DEBUG=0 %cl_common% set cl_release= call cl /O2 /DBUILD_DEBUG=0 %cl_common%
set cl_link= /link /INCREMENTAL:NO resource.res /LIBPATH:%third_party_lib% SDL2.lib SDL2main.lib shell32.lib set cl_link= /link /INCREMENTAL:NO resource.res /LIBPATH:%third_party_lib% SDL2.lib SDL2main.lib shell32.lib
set cl_out= /out: set cl_out= /out:
:: Clang NOTE(tijani): Coming soon :: Clang NOTE(tijani): Coming soon
:: Per-Build Setting :: Per-Build Setting
:: --- Per-Build Settings ----------------------------------------------------- :: --- Per-Build Settings -----------------------------------------------------
set link_dll=-DLL set link_dll=-DLL
:: MSVC :: MSVC
if "%msvc%"=="1" set only_compile=/c if "%msvc%"=="1" set only_compile=/c
if "%msvc%"=="1" set EHsc=/EHsc if "%msvc%"=="1" set EHsc=/EHsc
if "%msvc%"=="1" set no_aslr=/DYNAMICBASE:NO if "%msvc%"=="1" set no_aslr=/DYNAMICBASE:NO
if "%msvc%"=="1" set rc=call rc if "%msvc%"=="1" set rc=call rc
:: Clang :: Clang
if "%clang%"=="1" set only_compile=-c if "%clang%"=="1" set only_compile=-c
if "%clang%"=="1" set EHsc= if "%clang%"=="1" set EHsc=
if "%clang%"=="1" set no_aslr=-Wl,/DYNAMICBASE:NO if "%clang%"=="1" set no_aslr=-Wl,/DYNAMICBASE:NO
if "%clang%"=="1" set rc=call llvm-rc if "%clang%"=="1" set rc=call llvm-rc
:: --- Choose Compile/Link Lines ---------------------------------------------- :: --- Choose Compile/Link Lines ----------------------------------------------
if "%msvc%"=="1" set compile_debug=%cl_debug% if "%msvc%"=="1" set compile_debug=%cl_debug%
if "%msvc%"=="1" set compile_release=%cl_release% if "%msvc%"=="1" set compile_release=%cl_release%
if "%msvc%"=="1" set compile_link=%cl_link% if "%msvc%"=="1" set compile_link=%cl_link%
if "%msvc%"=="1" set out=%cl_out% if "%msvc%"=="1" set out=%cl_out%
rem if "%clang%"=="1" set compile_debug=%clang_debug% rem if "%clang%"=="1" set compile_debug=%clang_debug%
rem if "%clang%"=="1" set compile_release=%clang_release% rem if "%clang%"=="1" set compile_release=%clang_release%
rem if "%clang%"=="1" set compile_link=%clang_link% rem if "%clang%"=="1" set compile_link=%clang_link%
rem if "%clang%"=="1" set out=%clang_out% rem if "%clang%"=="1" set out=%clang_out%
if "%debug%"=="1" set compile=%compile_debug% if "%debug%"=="1" set compile=%compile_debug%
if "%release%"=="1" set compile=%compile_release% if "%release%"=="1" set compile=%compile_release%
:: Prep Directory :: Prep Directory
if not exist run_tree ( if not exist run_tree (
mkdir run_tree mkdir run_tree
echo "[WARNING] creating run_tree, data files may not exist." echo "[WARNING] creating run_tree, data files may not exist."
) )
:: Process rc Files :: Process rc Files
pushd run_tree pushd run_tree
%rc% /nologo /fo resource.res data\resource.rc || exit /b 1 %rc% /nologo /fo resource.res data\resource.rc || exit /b 1
popd popd
:: Get Current SVN/Git Commit ID :: Get Current SVN/Git Commit ID
:: SVN :: SVN
:: for /f "tokens=2 delims==" %%i in ('svn info --show-item revision') do set compile=%compile% -DBUILD_SVN_REVISION=\"%%i\" :: for /f "tokens=2 delims==" %%i in ('svn info --show-item revision') do set compile=%compile% -DBUILD_SVN_REVISION=\"%%i\"
:: Git :: Git
:: for /f %%i in ('call git describe --always --dirty') do set compile=%compile% -DBUILD_GIT_HASH=\"%%i\" :: for /f %%i in ('call git describe --always --dirty') do set compile=%compile% -DBUILD_GIT_HASH=\"%%i\"
:: Build :: Build
pushd run_tree pushd run_tree
if "%ragar%"=="1" %compile% ..\src\ragar\ragar_main.c %compile_link% %out%ragar.exe /SUBSYSTEM:WINDOWS || exit /b 1 if "%ragar%"=="1" %compile% ..\src\ragar\ragar_main.c %compile_link% %out%ragar.exe /SUBSYSTEM:WINDOWS || exit /b 1
popd popd
:: Unset :: Unset
for %%a in (%*) do set "%%a=0" for %%a in (%*) do set "%%a=0"
set ragar= set ragar=
set compile= set compile=
set compile_link= set compile_link=
set out= set out=
set msvc= set msvc=
set debug= set debug=
set release= set release=
rem :: Warning rem :: Warning
rem if "%didbuild%"=="" ( rem if "%didbuild%"=="" (
rem echo [WARNING] no valid build target specified; must use build target names as arguments to this script, like `build debug` or `build release`. rem echo [WARNING] no valid build target specified; must use build target names as arguments to this script, like `build debug` or `build release`.
rem exit /b 1 rem exit /b 1
rem ) rem )

View File

@ -1,43 +1,43 @@
#include "windows.h" #include "windows.h"
#include "winver.h" #include "winver.h"
// Language // Language
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
// Icon // Icon
ICON DISCARDABLE "logo.ico" ICON DISCARDABLE "logo.ico"
// Version // Version
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,0,1 FILEVERSION 0,0,0,1
PRODUCTVERSION 0,0,0,1 PRODUCTVERSION 0,0,0,1
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG FILEFLAGS VS_FF_DEBUG
#else #else
FILEFLAGS 0x0L FILEFLAGS 0x0L
#endif #endif
FILEOS VOS__WINDOWS32 FILEOS VOS__WINDOWS32
FILETYPE VFT_APP FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN FILESUBTYPE VFT2_UNKNOWN
BEGIN BEGIN
BLOCK "StringFileInfo" BLOCK "StringFileInfo"
BEGIN BEGIN
BLOCK "040904E4" BLOCK "040904E4"
BEGIN BEGIN
VALUE "CompanyName", "Tijani Lawal" VALUE "CompanyName", "Tijani Lawal"
VALUE "FileDescription", "Ragar: 3D Software Renderer" VALUE "FileDescription", "Ragar: 3D Software Renderer"
VALUE "FileVersion", "0.0.0.1" VALUE "FileVersion", "0.0.0.1"
VALUE "InternalName", "Ragar" VALUE "InternalName", "Ragar"
VALUE "LegalCopyright", "Copyright (C) Tijani Lawal. 2024" VALUE "LegalCopyright", "Copyright (C) Tijani Lawal. 2024"
VALUE "OriginalFilename", "Ragar.exe" VALUE "OriginalFilename", "Ragar.exe"
VALUE "ProductName", "Ragar: 3D Software Renderer" VALUE "ProductName", "Ragar: 3D Software Renderer"
VALUE "ProductVersion", "0.0.0.1" VALUE "ProductVersion", "0.0.0.1"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"
BEGIN BEGIN
VALUE "Translation", 0x0409, 1252 VALUE "Translation", 0x0409, 1252
END END
END END

View File

@ -0,0 +1,117 @@
#ifndef BASE_CONTEXT_SWITCHING_H
#define BASE_CONTEXT_SWITCHING_H
#if defined(_MSC_VER)
#define COMPILER_MSVC 1
#if defined(_WIN32)
#define OS_WINDOWS 1
#else
#error Compiler/OS combination is not supported.
#endif
#if defined(_M_AMD64)
#define ARCH_X64 1
#elif defined(_M_IX86)
#define ARCH_x86 1
#else
#error Architecture not supported.
#endif
#endif
// Architecture Context
#if defined(ARCH_X64)
#define ARCH_64BIT 1
#elif defined(ARCH_X86)
#define ARCH_32BIT 1
#endif
#if ARCH_X64 || ARCH_X86
#define ARCH_LITTLE_ENDIAN 1
#else
#error Endianess of this architecture is not supported.
#endif
// Language Context
#if defined(__cplusplus)
#define LANG_CPP 1
#else
#define LANG_C 1
#endif
//=================================
//~ tijani: Build Options
#if !defined(BUILD_DEBUG)
#define BUILD_DEBUG 1
#endif
#if !defined(BUILD_VERSION_MAJOR)
#define BUILD_VERSION_MAJOR 0
#endif
#if !defined(BUILD_VERSION_MINOR)
#define BUILD_VERSION_MINOR 0
#endif
#if !defined(BUILD_VERSION_PATCH)
#define BUILD_VERSION_PATCH 0
#endif
#define BUILD_VERSION_STRING_LITERAL \
Stringify(BUILD_VERSION_MAJOR) "." Stringify(BUILD_VERSION_MINOR) "." Stringify(BUILD_VERSION_PATCH)
#if BUILD_DEBUG
#define BUILD_MODE_STRING_LITERAL_APPEND " [Debug]"
#else
#define BUILD_MODE_STRING_LITERAL_APPEND ""
#endif
#if defined(BUILD_GIT_HASH)
#define BUILD_GIT_HASH_STRING_LITERAL_APPEND " [" BUILD_GIT_HASH "]"
#else
#define BUILD_GITH_HASH_STRING_LITERAL_APPEND ""
#endif
#if !defined(BUILD_TITLE)
#define BUILD_TITLE "Untitled"
#endif
#if !defined(BUILD_RELEASE_PHASE_STRING_LITERAL)
#define BUILD_RELEASE_PHASE_STRING_LITERAL "ALPHA"
#endif
#if !defined(BUILD_ISSUES_LINK_STRING_LITERAL)
#define BUILD_ISSUES_LINK_STRING_LITERAL ""
#endif
#define BUILD_TITLE_STRING_LITERAL \
BUILD_TITLE \
" (" BUILD_VERSION_STRING_LITERAL " " BUILD_RELEASE_PHASE_STRING_LITERAL ") - " __DATE__ \
"" BUILD_GIT_HASH_STRING_LITERAL_APPEND BUILD_MODE_STRING_LITERAL_APPEND
//=============================
//~ tijani: Zero Undefined Options
#if !defined(COMPILER_MSVC)
#define COMPILER_MSVC 0
#endif
#if !defined(OS_WINDOWS)
#define OS_WINDOWS 0
#endif
#if !defined(ARCH_X64)
#define ARCH_X64 0
#endif
#if !defined(ARCH_X86)
#define ARCH_X86 0
#endif
#if !defined(ARCH_32BIT)
#define ARCH_32BIT 0
#endif
#if !defined(ARCH_64BIT)
#define ARCH_64BIT 0
#endif
#if !defined(LANG_CPP)
#define LANG_CPP 0
#endif
#if !defined(LANG_C)
#define LANG_C 0
#endif
#endif // BASE_CONTEXT_SWITCHING_H

View File

@ -1,39 +1,39 @@
#ifndef BASE_TYPES_H #ifndef BASE_TYPES_H
#define BASE_TYPES_H #define BASE_TYPES_H
#include <stdint.h> #include <stdint.h>
// Keywords Macros // Keywords Macros
#define internal static #define internal static
#define global static #define global static
#define local static #define local static
// Base Types // Base Types
typedef uint8_t u8; typedef uint8_t u8;
typedef uint16_t u16; typedef uint16_t u16;
typedef uint32_t u32; typedef uint32_t u32;
typedef uint64_t u64; typedef uint64_t u64;
typedef int8_t s8; typedef int8_t s8;
typedef int16_t s16; typedef int16_t s16;
typedef int32_t s32; typedef int32_t s32;
typedef int64_t s64; typedef int64_t s64;
typedef s8 b8; typedef s8 b8;
typedef s16 b16; typedef s16 b16;
typedef s32 b32; typedef s32 b32;
typedef s64 b64; typedef s64 b64;
typedef float f32; typedef float f32;
typedef double f64; typedef double f64;
// Units // Units
#define KB(n) (((u64)(n)) << 10) #define KB(n) (((u64)(n)) << 10)
#define MB(n) (((u64)(n)) << 20) #define MB(n) (((u64)(n)) << 20)
#define GB(n) (((u64)(n)) << 30) #define GB(n) (((u64)(n)) << 30)
#define TB(n) (((u64)(n)) << 40) #define TB(n) (((u64)(n)) << 40)
#define Thousand(n) ((n) * 1000) #define Thousand(n) ((n) * 1000)
#define Million(n) ((n) * 1000000) #define Million(n) ((n) * 1000000)
#define Billion(n) ((n) * 1000000000) #define Billion(n) ((n) * 1000000000)
#endif // BASE_TYPES_H #endif // BASE_TYPES_H

View File

@ -1,11 +0,0 @@
#ifndef BASE_INC_H
#define BASE_INC_H
// clang-format off
// #include "base_context_switching.h"
#include "base_core.h"
// clang-format on
#endif // BASE_INC_H

View File

@ -1,17 +0,0 @@
#ifndef BASE_PROFILE_H
#define BASE_PROFILE_H
#if !defined(PROFILE_TRACY)
#define PROFILE_TRACY 0
#endif
// Third Party Includes
#if PROFILE_TRACY
#include "third_party/tracy/tracy/TracyC.h"
#endif
#if PROFILE_TRACY
#define FrameStart(...)
#endif
#endif // BASE_PROFILE_H

View File

@ -1,113 +1,113 @@
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include "base/base_inc.h" #include "base/base_inc.h"
#include "renderer/display.h" #include "renderer/display.h"
#include "renderer/vector.h" #include "renderer/vector.h"
#include "renderer/display.c" #include "renderer/display.c"
#include "renderer/vector.c" #include "renderer/vector.c"
#define POINTS (9 * 9 * 9) #define POINTS (9 * 9 * 9)
Vec3F32 cube_points[POINTS]; Vec3F32 cube_points[POINTS];
Vec2F32 projected_points[POINTS]; Vec2F32 projected_points[POINTS];
int is_running; int is_running;
void setup(void) { void setup(void) {
colour_buffer = (u32 *)malloc(sizeof(u32) * window_width * window_height); colour_buffer = (u32 *)malloc(sizeof(u32) * window_width * window_height);
colour_buffer_texture = colour_buffer_texture =
SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, window_width, window_height); SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, window_width, window_height);
int point_count = 0; int point_count = 0;
// Start loading an array of vectors // Start loading an array of vectors
// from -1 to 1 (in the 9*9*9 cube) // from -1 to 1 (in the 9*9*9 cube)
for (f32 x = -1; x < 1; x += 0.25) { for (f32 x = -1; x < 1; x += 0.25) {
for (f32 y = -1; y < 1; y += 0.25) { for (f32 y = -1; y < 1; y += 0.25) {
for (f32 z = -1; z < 1; z += 0.25) { for (f32 z = -1; z < 1; z += 0.25) {
Vec3F32 new_point = {.x = x, .y = y, .z = z}; Vec3F32 new_point = {.x = x, .y = y, .z = z};
cube_points[point_count++] = new_point; cube_points[point_count++] = new_point;
} }
} }
} }
} }
// Orthographic projection // Orthographic projection
// Vec2F32 project(Vec3F32 point) { // Vec2F32 project(Vec3F32 point) {
// Vec2F32 projected_point = {.x = point.x, .y = point.y}; // Vec2F32 projected_point = {.x = point.x, .y = point.y};
// return projected_point; // return projected_point;
// } // }
void process_input(void) { void process_input(void) {
SDL_Event event; SDL_Event event;
SDL_PollEvent(&event); SDL_PollEvent(&event);
switch (event.type) { switch (event.type) {
case SDL_QUIT: case SDL_QUIT:
is_running = false; is_running = false;
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE) { if (event.key.keysym.sym == SDLK_ESCAPE) {
is_running = false; is_running = false;
} else if (event.key.keysym.sym == SDLK_q) { } else if (event.key.keysym.sym == SDLK_q) {
is_running = false; is_running = false;
} }
break; break;
} }
} }
// Convert 3D projection -> 2D // Convert 3D projection -> 2D
Vec2F32 project(Vec3F32 point) { Vec2F32 project(Vec3F32 point) {
Vec2F32 projected_point = {.x = point.x, .y = point.y}; Vec2F32 projected_point = {.x = point.x, .y = point.y};
return projected_point; return projected_point;
} }
void update(void) { void update(void) {
for (int i = 0; i < POINTS; ++i) { for (int i = 0; i < POINTS; ++i) {
Vec3F32 point = cube_points[i]; Vec3F32 point = cube_points[i];
// Project the current point // Project the current point
Vec2F32 projected_point = project(point); Vec2F32 projected_point = project(point);
// save the projected 2D vector in the array of projected_points // save the projected 2D vector in the array of projected_points
projected_points[i] = projected_point; projected_points[i] = projected_point;
} }
} }
void render(void) { void render(void) {
// FrameMarkStart("render"); // FrameMarkStart("render");
draw_grid(0xFFFFFFFF); draw_grid(0xFFFFFFFF);
// Loop all projected points and render them // Loop all projected points and render them
for (int i = 0; i < POINTS; i++) { for (int i = 0; i < POINTS; i++) {
Vec2F32 projected_point = projected_points[i]; Vec2F32 projected_point = projected_points[i];
draw_rect(projected_point.x, projected_point.y, 4, 4, 0xFFFFFF00); draw_rect(projected_point.x, projected_point.y, 4, 4, 0xFFFFFF00);
} }
// SDL_SetRenderDrawColor(renderer, 28, 450, 560, 255); // SDL_SetRenderDrawColor(renderer, 28, 450, 560, 255);
// SDL_RenderClear(renderer); // SDL_RenderClear(renderer);
render_colour_buffer(); render_colour_buffer();
// clear_colour_buffer(0xFF384893); // clear_colour_buffer(0xFF384893);
clear_colour_buffer(0xFF000000); clear_colour_buffer(0xFF000000);
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
is_running = initialize_window(); is_running = initialize_window();
setup(); setup();
while (is_running) { while (is_running) {
process_input(); process_input();
update(); update();
render(); render();
} }
destroy_window(); destroy_window();
return 0; return 0;
} }

View File

@ -1,82 +1,82 @@
int initialize_window(void) { int initialize_window(void) {
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
fprintf(stderr, "Error initializing SDL.\n"); fprintf(stderr, "Error initializing SDL.\n");
return false; return false;
} }
// NOTE(tijani): Query screen size for fullscreen // NOTE(tijani): Query screen size for fullscreen
// SDL_DisplayMode display_mode; // SDL_DisplayMode display_mode;
// SDL_GetCurrentDisplayMode(0, &display_mode); // NOTE(tijani): second screen instead of main one // SDL_GetCurrentDisplayMode(0, &display_mode); // NOTE(tijani): second screen instead of main one
// window_width = display_mode.w; // window_width = display_mode.w;
// window_height = display_mode.h; // window_height = display_mode.h;
window = SDL_CreateWindow("Ragar: 3D Software Renderer", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width, window = SDL_CreateWindow("Ragar: 3D Software Renderer", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width,
window_height, 0); window_height, 0);
if (!window) { if (!window) {
fprintf(stderr, "SDL could not create a window.\n"); fprintf(stderr, "SDL could not create a window.\n");
return false; return false;
} }
renderer = SDL_CreateRenderer(window, -1, 0); renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) { if (!renderer) {
fprintf(stderr, "SDL could not create a renderer.\n"); fprintf(stderr, "SDL could not create a renderer.\n");
return false; return false;
} }
// SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN); // SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
return true; return true;
} }
void destroy_window(void) { void destroy_window(void) {
free(colour_buffer); free(colour_buffer);
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
SDL_Quit(); SDL_Quit();
} }
void clear_colour_buffer(u32 colour) { void clear_colour_buffer(u32 colour) {
for (int i = 0; i < window_height; i++) { for (int i = 0; i < window_height; i++) {
for (int j = 0; j < window_width; j++) { for (int j = 0; j < window_width; j++) {
colour_buffer[(window_width * i) + j] = colour; colour_buffer[(window_width * i) + j] = colour;
} }
} }
} }
void render_colour_buffer(void) { void render_colour_buffer(void) {
SDL_UpdateTexture(colour_buffer_texture, NULL, colour_buffer, (window_width * sizeof(u32))); SDL_UpdateTexture(colour_buffer_texture, NULL, colour_buffer, (window_width * sizeof(u32)));
SDL_RenderCopy(renderer, colour_buffer_texture, NULL, NULL); SDL_RenderCopy(renderer, colour_buffer_texture, NULL, NULL);
} }
void draw_dots(u32 colour) { void draw_dots(u32 colour) {
for (s32 column = 0; column < window_height; column += 10) { for (s32 column = 0; column < window_height; column += 10) {
for (s32 row = 0; row < window_width; row += 10) { for (s32 row = 0; row < window_width; row += 10) {
colour_buffer[(window_width * column) + row] = colour; colour_buffer[(window_width * column) + row] = colour;
} }
} }
} }
void draw_grid(u32 colour) { void draw_grid(u32 colour) {
for (s32 column = 0; column < window_height; column++) { for (s32 column = 0; column < window_height; column++) {
for (s32 row = 0; row < window_width; row++) { for (s32 row = 0; row < window_width; row++) {
if ((row % 10) == 0 || (column % 100) == 0) { if ((row % 10) == 0 || (column % 100) == 0) {
colour_buffer[(window_width * column) + row] = colour; colour_buffer[(window_width * column) + row] = colour;
} }
} }
} }
} }
void draw_rect(s32 x, s32 y, s32 width, s32 height, s32 colour) { void draw_rect(s32 x, s32 y, s32 width, s32 height, s32 colour) {
for (int row = 0; row < width; row++) { for (int row = 0; row < width; row++) {
for (int column = 0; column < height; column++) { for (int column = 0; column < height; column++) {
s32 l_row = row + x; s32 l_row = row + x;
s32 l_column = column + y; s32 l_column = column + y;
draw_pixel(l_row, l_column, colour); draw_pixel(l_row, l_column, colour);
// colour_buffer[(window_width * l_column) + l_row] = colour; // colour_buffer[(window_width * l_column) + l_row] = colour;
} }
} }
} }
void draw_pixel(u32 x, u32 y, u32 colour) { colour_buffer[(window_width * y) + x] = colour; } void draw_pixel(u32 x, u32 y, u32 colour) { colour_buffer[(window_width * y) + x] = colour; }

View File

@ -1,25 +1,25 @@
#ifndef RAGAR_DISPLAY_H #ifndef RAGAR_DISPLAY_H
#define RAGAR_DISPLAY_H #define RAGAR_DISPLAY_H
#include <SDL.h> #include <SDL.h>
SDL_Window *window = NULL; SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL; SDL_Renderer *renderer = NULL;
SDL_Texture *colour_buffer_texture = NULL; SDL_Texture *colour_buffer_texture = NULL;
u32 *colour_buffer; u32 *colour_buffer;
s32 window_width = 800; s32 window_width = 800;
s32 window_height = 600; s32 window_height = 600;
int initialize_window(void); int initialize_window(void);
void destroy_window(void); void destroy_window(void);
void clear_colour_buffer(u32 colour); void clear_colour_buffer(u32 colour);
void render_colour_buffer(void); void render_colour_buffer(void);
void draw_pixel(u32 x, u32 y, u32 colour); void draw_pixel(u32 x, u32 y, u32 colour);
void draw_grid(u32 colour); void draw_grid(u32 colour);
void draw_dots(u32 colour); void draw_dots(u32 colour);
void draw_rect(s32 x, s32 y, s32 width, s32 height, s32 colour); void draw_rect(s32 x, s32 y, s32 width, s32 height, s32 colour);
#endif // RAGAR_DISPLAY_H #endif // RAGAR_DISPLAY_H

View File

View File

@ -1,17 +0,0 @@
#ifndef VECTOR_H
#define VECTOR_H
typedef struct Vec2F32 Vec2F32;
struct Vec2F32 {
f32 x;
f32 y;
};
typedef struct Vec3F32 Vec3F32;
struct Vec3F32 {
f32 x;
f32 y;
f32 z;
};
#endif // VECTOR_H