Normalize line endings
This commit is contained in:
parent
320ebaace2
commit
9e1e4c2c5c
248
build.bat
248
build.bat
@ -1,124 +1,124 @@
|
||||
@echo off
|
||||
setlocal
|
||||
cd /D "%~dp0"
|
||||
|
||||
:: -- Useage Notes (July 25th, 2024) ----------------------------------------------------------
|
||||
::
|
||||
:: 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
|
||||
:: arguments which controls (1) what compiler & linker is used, (2) what mode the the
|
||||
:: application is built in.
|
||||
::
|
||||
:: By default if no options are passed, everything is built in debug mode with the MSVC
|
||||
:: compiler
|
||||
::
|
||||
:: Possible ways to use:
|
||||
::
|
||||
:: `build debug`
|
||||
:: `build debug msvc`
|
||||
:: `build release clang`
|
||||
:: `build debug tracy`
|
||||
::
|
||||
|
||||
:: Unpack Arguments
|
||||
for %%a in (%*) do set "%%a=1"
|
||||
|
||||
if not "%msvc%"=="1" set msvc=1
|
||||
if not "%release%"=="1" set debug=1
|
||||
|
||||
if "%debug%"=="1" set release=0 && echo [debug mode]
|
||||
if "%release%"=="1" set debug=0 && echo [release mode]
|
||||
|
||||
if "%msvc%"=="1" set clang=0 && echo [msvc compile]
|
||||
if "%clang%"=="1" set msvc=0 && echo [clang compile]
|
||||
|
||||
:: Fix
|
||||
if "%~1"=="" echo [default mode] && set ragar=1
|
||||
if "%~1"=="release" if "%~2"=="" echo [default release mode] && set ragar=1
|
||||
|
||||
:: Unpack Command Line Build arguments
|
||||
set auto_compile_flags=
|
||||
if "%tracy%"=="1" set auto_compile_flags=%auto_compile_flags% /DTRACY_ENABLE && echo [tracy profiling enabled]
|
||||
|
||||
:: Third Party libraries
|
||||
set third_party_includes="%~dp0\third_party\\SDL2\\include"
|
||||
set third_party_lib="%~dp0\third_party\\SDL2\\lib\\x64"
|
||||
|
||||
:: MSVC
|
||||
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_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_out= /out:
|
||||
|
||||
:: Clang NOTE(tijani): Coming soon
|
||||
|
||||
:: Per-Build Setting
|
||||
|
||||
:: --- Per-Build Settings -----------------------------------------------------
|
||||
set link_dll=-DLL
|
||||
|
||||
:: MSVC
|
||||
if "%msvc%"=="1" set only_compile=/c
|
||||
if "%msvc%"=="1" set EHsc=/EHsc
|
||||
if "%msvc%"=="1" set no_aslr=/DYNAMICBASE:NO
|
||||
if "%msvc%"=="1" set rc=call rc
|
||||
|
||||
:: Clang
|
||||
if "%clang%"=="1" set only_compile=-c
|
||||
if "%clang%"=="1" set EHsc=
|
||||
if "%clang%"=="1" set no_aslr=-Wl,/DYNAMICBASE:NO
|
||||
if "%clang%"=="1" set rc=call llvm-rc
|
||||
|
||||
:: --- Choose Compile/Link Lines ----------------------------------------------
|
||||
if "%msvc%"=="1" set compile_debug=%cl_debug%
|
||||
if "%msvc%"=="1" set compile_release=%cl_release%
|
||||
if "%msvc%"=="1" set compile_link=%cl_link%
|
||||
if "%msvc%"=="1" set out=%cl_out%
|
||||
|
||||
rem if "%clang%"=="1" set compile_debug=%clang_debug%
|
||||
rem if "%clang%"=="1" set compile_release=%clang_release%
|
||||
rem if "%clang%"=="1" set compile_link=%clang_link%
|
||||
rem if "%clang%"=="1" set out=%clang_out%
|
||||
|
||||
if "%debug%"=="1" set compile=%compile_debug%
|
||||
if "%release%"=="1" set compile=%compile_release%
|
||||
|
||||
:: Prep Directory
|
||||
if not exist run_tree (
|
||||
mkdir run_tree
|
||||
echo "[WARNING] creating run_tree, data files may not exist."
|
||||
)
|
||||
|
||||
:: Process rc Files
|
||||
pushd run_tree
|
||||
%rc% /nologo /fo resource.res data\resource.rc || exit /b 1
|
||||
popd
|
||||
|
||||
:: Get Current SVN/Git Commit ID
|
||||
:: SVN
|
||||
:: for /f "tokens=2 delims==" %%i in ('svn info --show-item revision') do set compile=%compile% -DBUILD_SVN_REVISION=\"%%i\"
|
||||
:: Git
|
||||
:: for /f %%i in ('call git describe --always --dirty') do set compile=%compile% -DBUILD_GIT_HASH=\"%%i\"
|
||||
|
||||
:: Build
|
||||
pushd run_tree
|
||||
if "%ragar%"=="1" %compile% ..\src\ragar\ragar_main.c %compile_link% %out%ragar.exe /SUBSYSTEM:WINDOWS || exit /b 1
|
||||
popd
|
||||
|
||||
:: Unset
|
||||
for %%a in (%*) do set "%%a=0"
|
||||
set ragar=
|
||||
set compile=
|
||||
set compile_link=
|
||||
set out=
|
||||
set msvc=
|
||||
set debug=
|
||||
set release=
|
||||
|
||||
rem :: Warning
|
||||
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 exit /b 1
|
||||
rem )
|
||||
|
||||
@echo off
|
||||
setlocal
|
||||
cd /D "%~dp0"
|
||||
|
||||
:: -- Useage Notes (July 25th, 2024) ----------------------------------------------------------
|
||||
::
|
||||
:: 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
|
||||
:: arguments which controls (1) what compiler & linker is used, (2) what mode the the
|
||||
:: application is built in.
|
||||
::
|
||||
:: By default if no options are passed, everything is built in debug mode with the MSVC
|
||||
:: compiler
|
||||
::
|
||||
:: Possible ways to use:
|
||||
::
|
||||
:: `build debug`
|
||||
:: `build debug msvc`
|
||||
:: `build release clang`
|
||||
:: `build debug tracy`
|
||||
::
|
||||
|
||||
:: Unpack Arguments
|
||||
for %%a in (%*) do set "%%a=1"
|
||||
|
||||
if not "%msvc%"=="1" set msvc=1
|
||||
if not "%release%"=="1" set debug=1
|
||||
|
||||
if "%debug%"=="1" set release=0 && echo [debug mode]
|
||||
if "%release%"=="1" set debug=0 && echo [release mode]
|
||||
|
||||
if "%msvc%"=="1" set clang=0 && echo [msvc compile]
|
||||
if "%clang%"=="1" set msvc=0 && echo [clang compile]
|
||||
|
||||
:: Fix
|
||||
if "%~1"=="" echo [default mode] && set ragar=1
|
||||
if "%~1"=="release" if "%~2"=="" echo [default release mode] && set ragar=1
|
||||
|
||||
:: Unpack Command Line Build arguments
|
||||
set auto_compile_flags=
|
||||
if "%tracy%"=="1" set auto_compile_flags=%auto_compile_flags% /DTRACY_ENABLE && echo [tracy profiling enabled]
|
||||
|
||||
:: Third Party libraries
|
||||
set third_party_includes="%~dp0\third_party\\SDL2\\include"
|
||||
set third_party_lib="%~dp0\third_party\\SDL2\\lib\\x64"
|
||||
|
||||
:: MSVC
|
||||
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_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_out= /out:
|
||||
|
||||
:: Clang NOTE(tijani): Coming soon
|
||||
|
||||
:: Per-Build Setting
|
||||
|
||||
:: --- Per-Build Settings -----------------------------------------------------
|
||||
set link_dll=-DLL
|
||||
|
||||
:: MSVC
|
||||
if "%msvc%"=="1" set only_compile=/c
|
||||
if "%msvc%"=="1" set EHsc=/EHsc
|
||||
if "%msvc%"=="1" set no_aslr=/DYNAMICBASE:NO
|
||||
if "%msvc%"=="1" set rc=call rc
|
||||
|
||||
:: Clang
|
||||
if "%clang%"=="1" set only_compile=-c
|
||||
if "%clang%"=="1" set EHsc=
|
||||
if "%clang%"=="1" set no_aslr=-Wl,/DYNAMICBASE:NO
|
||||
if "%clang%"=="1" set rc=call llvm-rc
|
||||
|
||||
:: --- Choose Compile/Link Lines ----------------------------------------------
|
||||
if "%msvc%"=="1" set compile_debug=%cl_debug%
|
||||
if "%msvc%"=="1" set compile_release=%cl_release%
|
||||
if "%msvc%"=="1" set compile_link=%cl_link%
|
||||
if "%msvc%"=="1" set out=%cl_out%
|
||||
|
||||
rem if "%clang%"=="1" set compile_debug=%clang_debug%
|
||||
rem if "%clang%"=="1" set compile_release=%clang_release%
|
||||
rem if "%clang%"=="1" set compile_link=%clang_link%
|
||||
rem if "%clang%"=="1" set out=%clang_out%
|
||||
|
||||
if "%debug%"=="1" set compile=%compile_debug%
|
||||
if "%release%"=="1" set compile=%compile_release%
|
||||
|
||||
:: Prep Directory
|
||||
if not exist run_tree (
|
||||
mkdir run_tree
|
||||
echo "[WARNING] creating run_tree, data files may not exist."
|
||||
)
|
||||
|
||||
:: Process rc Files
|
||||
pushd run_tree
|
||||
%rc% /nologo /fo resource.res data\resource.rc || exit /b 1
|
||||
popd
|
||||
|
||||
:: Get Current SVN/Git Commit ID
|
||||
:: SVN
|
||||
:: for /f "tokens=2 delims==" %%i in ('svn info --show-item revision') do set compile=%compile% -DBUILD_SVN_REVISION=\"%%i\"
|
||||
:: Git
|
||||
:: for /f %%i in ('call git describe --always --dirty') do set compile=%compile% -DBUILD_GIT_HASH=\"%%i\"
|
||||
|
||||
:: Build
|
||||
pushd run_tree
|
||||
if "%ragar%"=="1" %compile% ..\src\ragar\ragar_main.c %compile_link% %out%ragar.exe /SUBSYSTEM:WINDOWS || exit /b 1
|
||||
popd
|
||||
|
||||
:: Unset
|
||||
for %%a in (%*) do set "%%a=0"
|
||||
set ragar=
|
||||
set compile=
|
||||
set compile_link=
|
||||
set out=
|
||||
set msvc=
|
||||
set debug=
|
||||
set release=
|
||||
|
||||
rem :: Warning
|
||||
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 exit /b 1
|
||||
rem )
|
||||
|
||||
|
@ -1,43 +1,43 @@
|
||||
#include "windows.h"
|
||||
#include "winver.h"
|
||||
|
||||
// Language
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
// Icon
|
||||
ICON DISCARDABLE "logo.ico"
|
||||
|
||||
// Version
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 0,0,0,1
|
||||
PRODUCTVERSION 0,0,0,1
|
||||
FILEFLAGSMASK 0x3fL
|
||||
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS VS_FF_DEBUG
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS VOS__WINDOWS32
|
||||
FILETYPE VFT_APP
|
||||
FILESUBTYPE VFT2_UNKNOWN
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904E4"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Tijani Lawal"
|
||||
VALUE "FileDescription", "Ragar: 3D Software Renderer"
|
||||
VALUE "FileVersion", "0.0.0.1"
|
||||
VALUE "InternalName", "Ragar"
|
||||
VALUE "LegalCopyright", "Copyright (C) Tijani Lawal. 2024"
|
||||
VALUE "OriginalFilename", "Ragar.exe"
|
||||
VALUE "ProductName", "Ragar: 3D Software Renderer"
|
||||
VALUE "ProductVersion", "0.0.0.1"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0409, 1252
|
||||
END
|
||||
END
|
||||
#include "windows.h"
|
||||
#include "winver.h"
|
||||
|
||||
// Language
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
// Icon
|
||||
ICON DISCARDABLE "logo.ico"
|
||||
|
||||
// Version
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 0,0,0,1
|
||||
PRODUCTVERSION 0,0,0,1
|
||||
FILEFLAGSMASK 0x3fL
|
||||
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS VS_FF_DEBUG
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS VOS__WINDOWS32
|
||||
FILETYPE VFT_APP
|
||||
FILESUBTYPE VFT2_UNKNOWN
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904E4"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Tijani Lawal"
|
||||
VALUE "FileDescription", "Ragar: 3D Software Renderer"
|
||||
VALUE "FileVersion", "0.0.0.1"
|
||||
VALUE "InternalName", "Ragar"
|
||||
VALUE "LegalCopyright", "Copyright (C) Tijani Lawal. 2024"
|
||||
VALUE "OriginalFilename", "Ragar.exe"
|
||||
VALUE "ProductName", "Ragar: 3D Software Renderer"
|
||||
VALUE "ProductVersion", "0.0.0.1"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0409, 1252
|
||||
END
|
||||
END
|
||||
|
117
src/base/base_context_switching.h
Normal file
117
src/base/base_context_switching.h
Normal 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
|
@ -1,39 +1,39 @@
|
||||
#ifndef BASE_TYPES_H
|
||||
#define BASE_TYPES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Keywords Macros
|
||||
#define internal static
|
||||
#define global static
|
||||
#define local static
|
||||
|
||||
// Base Types
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
typedef int8_t s8;
|
||||
typedef int16_t s16;
|
||||
typedef int32_t s32;
|
||||
typedef int64_t s64;
|
||||
|
||||
typedef s8 b8;
|
||||
typedef s16 b16;
|
||||
typedef s32 b32;
|
||||
typedef s64 b64;
|
||||
|
||||
typedef float f32;
|
||||
typedef double f64;
|
||||
|
||||
// Units
|
||||
#define KB(n) (((u64)(n)) << 10)
|
||||
#define MB(n) (((u64)(n)) << 20)
|
||||
#define GB(n) (((u64)(n)) << 30)
|
||||
#define TB(n) (((u64)(n)) << 40)
|
||||
#define Thousand(n) ((n) * 1000)
|
||||
#define Million(n) ((n) * 1000000)
|
||||
#define Billion(n) ((n) * 1000000000)
|
||||
|
||||
#endif // BASE_TYPES_H
|
||||
#ifndef BASE_TYPES_H
|
||||
#define BASE_TYPES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Keywords Macros
|
||||
#define internal static
|
||||
#define global static
|
||||
#define local static
|
||||
|
||||
// Base Types
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
typedef int8_t s8;
|
||||
typedef int16_t s16;
|
||||
typedef int32_t s32;
|
||||
typedef int64_t s64;
|
||||
|
||||
typedef s8 b8;
|
||||
typedef s16 b16;
|
||||
typedef s32 b32;
|
||||
typedef s64 b64;
|
||||
|
||||
typedef float f32;
|
||||
typedef double f64;
|
||||
|
||||
// Units
|
||||
#define KB(n) (((u64)(n)) << 10)
|
||||
#define MB(n) (((u64)(n)) << 20)
|
||||
#define GB(n) (((u64)(n)) << 30)
|
||||
#define TB(n) (((u64)(n)) << 40)
|
||||
#define Thousand(n) ((n) * 1000)
|
||||
#define Million(n) ((n) * 1000000)
|
||||
#define Billion(n) ((n) * 1000000000)
|
||||
|
||||
#endif // BASE_TYPES_H
|
||||
|
@ -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
|
@ -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
|
@ -1,113 +1,113 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "base/base_inc.h"
|
||||
#include "renderer/display.h"
|
||||
#include "renderer/vector.h"
|
||||
|
||||
#include "renderer/display.c"
|
||||
#include "renderer/vector.c"
|
||||
|
||||
#define POINTS (9 * 9 * 9)
|
||||
Vec3F32 cube_points[POINTS];
|
||||
Vec2F32 projected_points[POINTS];
|
||||
|
||||
int is_running;
|
||||
|
||||
void setup(void) {
|
||||
colour_buffer = (u32 *)malloc(sizeof(u32) * window_width * window_height);
|
||||
colour_buffer_texture =
|
||||
SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, window_width, window_height);
|
||||
|
||||
int point_count = 0;
|
||||
|
||||
// Start loading an array of vectors
|
||||
// from -1 to 1 (in the 9*9*9 cube)
|
||||
for (f32 x = -1; x < 1; x += 0.25) {
|
||||
for (f32 y = -1; y < 1; y += 0.25) {
|
||||
for (f32 z = -1; z < 1; z += 0.25) {
|
||||
Vec3F32 new_point = {.x = x, .y = y, .z = z};
|
||||
cube_points[point_count++] = new_point;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Orthographic projection
|
||||
// Vec2F32 project(Vec3F32 point) {
|
||||
// Vec2F32 projected_point = {.x = point.x, .y = point.y};
|
||||
// return projected_point;
|
||||
// }
|
||||
|
||||
void process_input(void) {
|
||||
SDL_Event event;
|
||||
SDL_PollEvent(&event);
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
is_running = false;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
is_running = false;
|
||||
} else if (event.key.keysym.sym == SDLK_q) {
|
||||
is_running = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert 3D projection -> 2D
|
||||
Vec2F32 project(Vec3F32 point) {
|
||||
Vec2F32 projected_point = {.x = point.x, .y = point.y};
|
||||
return projected_point;
|
||||
}
|
||||
|
||||
void update(void) {
|
||||
for (int i = 0; i < POINTS; ++i) {
|
||||
Vec3F32 point = cube_points[i];
|
||||
|
||||
// Project the current point
|
||||
Vec2F32 projected_point = project(point);
|
||||
|
||||
// save the projected 2D vector in the array of projected_points
|
||||
projected_points[i] = projected_point;
|
||||
}
|
||||
}
|
||||
|
||||
void render(void) {
|
||||
// FrameMarkStart("render");
|
||||
draw_grid(0xFFFFFFFF);
|
||||
|
||||
// Loop all projected points and render them
|
||||
for (int i = 0; i < POINTS; i++) {
|
||||
Vec2F32 projected_point = projected_points[i];
|
||||
draw_rect(projected_point.x, projected_point.y, 4, 4, 0xFFFFFF00);
|
||||
}
|
||||
|
||||
// SDL_SetRenderDrawColor(renderer, 28, 450, 560, 255);
|
||||
// SDL_RenderClear(renderer);
|
||||
|
||||
render_colour_buffer();
|
||||
// clear_colour_buffer(0xFF384893);
|
||||
clear_colour_buffer(0xFF000000);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
is_running = initialize_window();
|
||||
setup();
|
||||
|
||||
while (is_running) {
|
||||
process_input();
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
destroy_window();
|
||||
return 0;
|
||||
}
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "base/base_inc.h"
|
||||
#include "renderer/display.h"
|
||||
#include "renderer/vector.h"
|
||||
|
||||
#include "renderer/display.c"
|
||||
#include "renderer/vector.c"
|
||||
|
||||
#define POINTS (9 * 9 * 9)
|
||||
Vec3F32 cube_points[POINTS];
|
||||
Vec2F32 projected_points[POINTS];
|
||||
|
||||
int is_running;
|
||||
|
||||
void setup(void) {
|
||||
colour_buffer = (u32 *)malloc(sizeof(u32) * window_width * window_height);
|
||||
colour_buffer_texture =
|
||||
SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, window_width, window_height);
|
||||
|
||||
int point_count = 0;
|
||||
|
||||
// Start loading an array of vectors
|
||||
// from -1 to 1 (in the 9*9*9 cube)
|
||||
for (f32 x = -1; x < 1; x += 0.25) {
|
||||
for (f32 y = -1; y < 1; y += 0.25) {
|
||||
for (f32 z = -1; z < 1; z += 0.25) {
|
||||
Vec3F32 new_point = {.x = x, .y = y, .z = z};
|
||||
cube_points[point_count++] = new_point;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Orthographic projection
|
||||
// Vec2F32 project(Vec3F32 point) {
|
||||
// Vec2F32 projected_point = {.x = point.x, .y = point.y};
|
||||
// return projected_point;
|
||||
// }
|
||||
|
||||
void process_input(void) {
|
||||
SDL_Event event;
|
||||
SDL_PollEvent(&event);
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
is_running = false;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
is_running = false;
|
||||
} else if (event.key.keysym.sym == SDLK_q) {
|
||||
is_running = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert 3D projection -> 2D
|
||||
Vec2F32 project(Vec3F32 point) {
|
||||
Vec2F32 projected_point = {.x = point.x, .y = point.y};
|
||||
return projected_point;
|
||||
}
|
||||
|
||||
void update(void) {
|
||||
for (int i = 0; i < POINTS; ++i) {
|
||||
Vec3F32 point = cube_points[i];
|
||||
|
||||
// Project the current point
|
||||
Vec2F32 projected_point = project(point);
|
||||
|
||||
// save the projected 2D vector in the array of projected_points
|
||||
projected_points[i] = projected_point;
|
||||
}
|
||||
}
|
||||
|
||||
void render(void) {
|
||||
// FrameMarkStart("render");
|
||||
draw_grid(0xFFFFFFFF);
|
||||
|
||||
// Loop all projected points and render them
|
||||
for (int i = 0; i < POINTS; i++) {
|
||||
Vec2F32 projected_point = projected_points[i];
|
||||
draw_rect(projected_point.x, projected_point.y, 4, 4, 0xFFFFFF00);
|
||||
}
|
||||
|
||||
// SDL_SetRenderDrawColor(renderer, 28, 450, 560, 255);
|
||||
// SDL_RenderClear(renderer);
|
||||
|
||||
render_colour_buffer();
|
||||
// clear_colour_buffer(0xFF384893);
|
||||
clear_colour_buffer(0xFF000000);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
is_running = initialize_window();
|
||||
setup();
|
||||
|
||||
while (is_running) {
|
||||
process_input();
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
destroy_window();
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,82 +1,82 @@
|
||||
int initialize_window(void) {
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
||||
fprintf(stderr, "Error initializing SDL.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// NOTE(tijani): Query screen size for fullscreen
|
||||
// SDL_DisplayMode display_mode;
|
||||
// SDL_GetCurrentDisplayMode(0, &display_mode); // NOTE(tijani): second screen instead of main one
|
||||
// window_width = display_mode.w;
|
||||
// window_height = display_mode.h;
|
||||
|
||||
window = SDL_CreateWindow("Ragar: 3D Software Renderer", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width,
|
||||
window_height, 0);
|
||||
if (!window) {
|
||||
fprintf(stderr, "SDL could not create a window.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
fprintf(stderr, "SDL could not create a renderer.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void destroy_window(void) {
|
||||
free(colour_buffer);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void clear_colour_buffer(u32 colour) {
|
||||
for (int i = 0; i < window_height; i++) {
|
||||
for (int j = 0; j < window_width; j++) {
|
||||
colour_buffer[(window_width * i) + j] = colour;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void render_colour_buffer(void) {
|
||||
SDL_UpdateTexture(colour_buffer_texture, NULL, colour_buffer, (window_width * sizeof(u32)));
|
||||
SDL_RenderCopy(renderer, colour_buffer_texture, NULL, NULL);
|
||||
}
|
||||
|
||||
void draw_dots(u32 colour) {
|
||||
for (s32 column = 0; column < window_height; column += 10) {
|
||||
for (s32 row = 0; row < window_width; row += 10) {
|
||||
colour_buffer[(window_width * column) + row] = colour;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_grid(u32 colour) {
|
||||
for (s32 column = 0; column < window_height; column++) {
|
||||
for (s32 row = 0; row < window_width; row++) {
|
||||
if ((row % 10) == 0 || (column % 100) == 0) {
|
||||
colour_buffer[(window_width * column) + row] = colour;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_rect(s32 x, s32 y, s32 width, s32 height, s32 colour) {
|
||||
for (int row = 0; row < width; row++) {
|
||||
for (int column = 0; column < height; column++) {
|
||||
s32 l_row = row + x;
|
||||
s32 l_column = column + y;
|
||||
|
||||
draw_pixel(l_row, l_column, 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; }
|
||||
int initialize_window(void) {
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
||||
fprintf(stderr, "Error initializing SDL.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// NOTE(tijani): Query screen size for fullscreen
|
||||
// SDL_DisplayMode display_mode;
|
||||
// SDL_GetCurrentDisplayMode(0, &display_mode); // NOTE(tijani): second screen instead of main one
|
||||
// window_width = display_mode.w;
|
||||
// window_height = display_mode.h;
|
||||
|
||||
window = SDL_CreateWindow("Ragar: 3D Software Renderer", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width,
|
||||
window_height, 0);
|
||||
if (!window) {
|
||||
fprintf(stderr, "SDL could not create a window.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
fprintf(stderr, "SDL could not create a renderer.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void destroy_window(void) {
|
||||
free(colour_buffer);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void clear_colour_buffer(u32 colour) {
|
||||
for (int i = 0; i < window_height; i++) {
|
||||
for (int j = 0; j < window_width; j++) {
|
||||
colour_buffer[(window_width * i) + j] = colour;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void render_colour_buffer(void) {
|
||||
SDL_UpdateTexture(colour_buffer_texture, NULL, colour_buffer, (window_width * sizeof(u32)));
|
||||
SDL_RenderCopy(renderer, colour_buffer_texture, NULL, NULL);
|
||||
}
|
||||
|
||||
void draw_dots(u32 colour) {
|
||||
for (s32 column = 0; column < window_height; column += 10) {
|
||||
for (s32 row = 0; row < window_width; row += 10) {
|
||||
colour_buffer[(window_width * column) + row] = colour;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_grid(u32 colour) {
|
||||
for (s32 column = 0; column < window_height; column++) {
|
||||
for (s32 row = 0; row < window_width; row++) {
|
||||
if ((row % 10) == 0 || (column % 100) == 0) {
|
||||
colour_buffer[(window_width * column) + row] = colour;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_rect(s32 x, s32 y, s32 width, s32 height, s32 colour) {
|
||||
for (int row = 0; row < width; row++) {
|
||||
for (int column = 0; column < height; column++) {
|
||||
s32 l_row = row + x;
|
||||
s32 l_column = column + y;
|
||||
|
||||
draw_pixel(l_row, l_column, 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; }
|
||||
|
@ -1,25 +1,25 @@
|
||||
#ifndef RAGAR_DISPLAY_H
|
||||
#define RAGAR_DISPLAY_H
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *renderer = NULL;
|
||||
SDL_Texture *colour_buffer_texture = NULL;
|
||||
|
||||
u32 *colour_buffer;
|
||||
s32 window_width = 800;
|
||||
s32 window_height = 600;
|
||||
|
||||
int initialize_window(void);
|
||||
void destroy_window(void);
|
||||
void clear_colour_buffer(u32 colour);
|
||||
void render_colour_buffer(void);
|
||||
|
||||
void draw_pixel(u32 x, u32 y, u32 colour);
|
||||
|
||||
void draw_grid(u32 colour);
|
||||
void draw_dots(u32 colour);
|
||||
void draw_rect(s32 x, s32 y, s32 width, s32 height, s32 colour);
|
||||
|
||||
#endif // RAGAR_DISPLAY_H
|
||||
#ifndef RAGAR_DISPLAY_H
|
||||
#define RAGAR_DISPLAY_H
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *renderer = NULL;
|
||||
SDL_Texture *colour_buffer_texture = NULL;
|
||||
|
||||
u32 *colour_buffer;
|
||||
s32 window_width = 800;
|
||||
s32 window_height = 600;
|
||||
|
||||
int initialize_window(void);
|
||||
void destroy_window(void);
|
||||
void clear_colour_buffer(u32 colour);
|
||||
void render_colour_buffer(void);
|
||||
|
||||
void draw_pixel(u32 x, u32 y, u32 colour);
|
||||
|
||||
void draw_grid(u32 colour);
|
||||
void draw_dots(u32 colour);
|
||||
void draw_rect(s32 x, s32 y, s32 width, s32 height, s32 colour);
|
||||
|
||||
#endif // RAGAR_DISPLAY_H
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user