diff options
-rw-r--r-- | code/amr_memory.c | 113 | ||||
-rw-r--r-- | code/amr_memory.h | 26 | ||||
-rw-r--r-- | code/game_main.h | 36 | ||||
-rw-r--r-- | code/gl_graphics.cpp | 46 | ||||
-rw-r--r-- | code/gl_graphics.h | 29 | ||||
-rw-r--r-- | code/math.h | 130 | ||||
-rw-r--r-- | code/win32_main.cpp | 205 | ||||
-rw-r--r-- | include/stb_rect_pack.h (renamed from code/stb_rect_pack.h) | 0 | ||||
-rw-r--r-- | include/stb_truetype.h (renamed from code/stb_truetype.h) | 0 |
9 files changed, 308 insertions, 277 deletions
diff --git a/code/amr_memory.c b/code/amr_memory.c new file mode 100644 index 0000000..f92f14a --- /dev/null +++ b/code/amr_memory.c @@ -0,0 +1,113 @@ +#include "amr_memory.h" + +bool amr_IsPowerOfTwo(uintptr_t x) +{ + return (x & (x-1)) == 0; +} + +uintptr_t amr_AlignForward(uintptr_t ptr, size_t align) +{ + uintptr_t p, a, modulo; + + assert(amr_IsPowerOfTwo(align)); + + p = ptr; + a = (uintptr_t)align; + modulo = p & (a-1); + + if (modulo != 0) + { + p += a - modulo; + } + return p; +} + +void *amr_ArenaAllocAlign(amr_DebugArena *Alloc, size_t Size, size_t Align) +{ + uintptr_t CurrOffset = (uintptr_t)Alloc->Buffer + (uintptr_t)Alloc->CurrOffset; + uintptr_t AlignedOffset = amr_AlignForward(CurrOffset, Align); + AlignedOffset -= (uintptr_t)(Alloc->Buffer); + + if (AlignedOffset + Size < Alloc->Size) + { + void *Ptr = &Alloc->Buffer[AlignedOffset]; + Alloc->PrevOffset = AlignedOffset; + Alloc->CurrOffset = AlignedOffset + Size; + + PlatformZeroMemory(Ptr, Size); + return Ptr; + } + return NULL; +} + +void amr_ArenaInit(amr_DebugArena *Alloc, void* BackingBuffer, size_t Size) +{ + Alloc->Buffer = (u8 *)BackingBuffer; + Alloc->Size = Size; + Alloc->CurrOffset = 0; + Alloc->PrevOffset = 0; +} + +void *amr_ArenaAlloc(amr_DebugArena *Alloc, size_t Size) +{ + return amr_ArenaAllocAlign(Alloc, Size, DEFAULT_ALIGNMENT); +} + +void amr_ArenaFree(amr_DebugArena *Alloc, void *Ptr) +{ + // @note: Arenas do not support freeing memory + // this is here to let me know I have not forgotten to implement it + return; +} + +void *amr_ArenaResizeAlign(amr_DebugArena *Alloc, void *OldMem, size_t OldSize, + size_t NewSize, size_t Align) +{ + assert(amr_IsPowerOfTwo(Align)); + if (OldMem == NULL || OldSize == 0) + { + return amr_ArenaAllocAlign(Alloc, NewSize, Align); + } + else if (Alloc->Buffer < OldMem && OldMem < Alloc->Buffer + Alloc->Size) + { + // check if old_memory falls on prev_offset + if (Alloc->Buffer + Alloc->PrevOffset == OldMem) + { + // re-use prev_offset and resize from there + size_t _CurrOffset = Alloc->CurrOffset; + Alloc->CurrOffset = Alloc->PrevOffset + NewSize; + if (NewSize > OldSize) + { + PlatformZeroMemory(&Alloc->Buffer[_CurrOffset], NewSize - OldSize); + } + return OldMem; + } + else + { + // generate new memory + // will have some fragmentation + void *NewMem = amr_ArenaAllocAlign(Alloc, NewSize, Align); + size_t CopySize = OldSize < NewSize ? OldSize : NewSize; + + // copy old memory to new memory location + PlatformCopyMemory(NewMem, OldMem, CopySize); + return NewMem; + } + } + else + { + assert(0 && "Memory is out of bounds of the buffer in this arena"); + return NULL; + } +} + +void *amr_ArenaResize(amr_DebugArena *Alloc, void *OldMem, size_t OldSize, size_t NewSize) +{ + return amr_ArenaResizeAlign(Alloc, OldMem, OldSize, NewSize, DEFAULT_ALIGNMENT); +} + +void amr_ArenaFreeAll(amr_DebugArena *Alloc) +{ + Alloc->CurrOffset = 0; + Alloc->PrevOffset = 0; +} diff --git a/code/amr_memory.h b/code/amr_memory.h new file mode 100644 index 0000000..f7638b3 --- /dev/null +++ b/code/amr_memory.h @@ -0,0 +1,26 @@ +#ifndef AMR_MEMORY_H +#define AMR_MEMORY_H + +#ifndef DEFAULT_ALIGNMENT +#define DEFAULT_ALIGNMENT (2*sizeof(void *)) +#endif + +typedef struct amr_DebugArena { + u8 *Buffer; + size_t Size; + size_t CurrOffset; + size_t PrevOffset; +} amr_DebugArena; + +bool amr_IsPowerOfTwo(uintptr_t x); +uintptr_t amr_AlignForward(uintptr_t ptr, size_t align); +void *amr_ArenaAllocAlign(amr_DebugArena *Alloc, size_t Size, size_t Align); +void amr_ArenaInit(amr_DebugArena *Alloc, void* BackingBuffer, size_t Size); +void *amr_ArenaAlloc(amr_DebugArena *Alloc, size_t Size); +void amr_ArenaFree(amr_DebugArena *Alloc, void *Ptr); +void *amr_ArenaResizeAlign(amr_DebugArena *Alloc, void *OldMem, size_t OldSize, + size_t NewSize, size_t Align); +void *amr_ArenaResize(amr_DebugArena *Alloc, void *OldMem, size_t OldSize, size_t NewSize); +void amr_ArenaFreeAll(amr_DebugArena *Alloc); + +#endif diff --git a/code/game_main.h b/code/game_main.h index 91c3054..2194e27 100644 --- a/code/game_main.h +++ b/code/game_main.h @@ -6,40 +6,26 @@ #define GB(b) (((u64)1024)*(MB(b))) typedef struct GameInput { - r32 LastMouseX; - r32 LastMouseY; - r64 MouseX; - r64 MouseY; - r32 Sensitivity; + f32 LastMouseX; + f32 LastMouseY; + f64 MouseX; + f64 MouseY; + f32 Sensitivity; } GameInput; typedef struct GameCamera { - r32 MoveSpeed; - r32 PitchAngle; - r32 YawAngle; + f32 MoveSpeed; + f32 PitchAngle; + f32 YawAngle; Vec3 Pos; Vec3 Front; Vec3 Up; } GameCamera; -typedef struct BufferO { - u32 VAO; // Vertex Array Object - u32 VBO; // Vertex Buffer Object - u32 EBO; // Element Buffer Object - u32 TexO; // Texture Buffer Object -} BufferO; - -typedef struct Texture2D { - i32 width; - i32 height; - i32 nrChannels; - unsigned char* data; -} Texture2D; - typedef struct GameMemory { void *PermanentStorage; u64 PermanentStorageSize; - DebugArena Arena; + amr_DebugArena Arena; } GameMemory; typedef struct Rect2 { @@ -52,8 +38,8 @@ typedef struct debug_font_details { i32 lsb; i32 x0, y0, x1, y1; i32 kern; - r32 lx; - r32 ly; + f32 lx; + f32 ly; i32 byte_offset; i32 baseline; } debug_font_details; diff --git a/code/gl_graphics.cpp b/code/gl_graphics.cpp index 91730ec..0c2aa62 100644 --- a/code/gl_graphics.cpp +++ b/code/gl_graphics.cpp @@ -9,7 +9,7 @@ void LoadUniformInt(u32 SP, const char *Uniform, i32 Val) glUniform1i(glGetUniformLocation(SP, Uniform), Val); } -void LoadUniformFloat(u32 SP, const char *Uniform, r32 Val) +void LoadUniformFloat(u32 SP, const char *Uniform, f32 Val) { glUniform1f(glGetUniformLocation(SP, Uniform), Val); } @@ -19,7 +19,7 @@ void LoadUniformVec3(u32 SP, const char *Uniform, Vec3 Val) glUniform3f(glGetUniformLocation(SP, Uniform), Val.x, Val.y, Val.z); } -void LoadUniformMat4(u32 SP, const char *Uniform, const r32 *Val) +void LoadUniformMat4(u32 SP, const char *Uniform, const f32 *Val) { glUniformMatrix4fv(glGetUniformLocation(SP, Uniform), 1, GL_TRUE, Val); } @@ -94,7 +94,7 @@ u32 CreateShaderProgram(unsigned int VertexShader, unsigned int FragmentShader) // --------------------------------------------------------------------------- -u32 CreateTriangle(r32 vertices[], i32 sz) +u32 CreateTriangle(f32 vertices[], i32 sz) { u32 VAO; glGenVertexArrays(1, &VAO); @@ -107,11 +107,11 @@ u32 CreateTriangle(r32 vertices[], i32 sz) glBufferData(GL_ARRAY_BUFFER, sz, vertices, GL_STATIC_DRAW); // position attribute - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(r32), (void*)0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(f32), (void*)0); glEnableVertexAttribArray(0); // color attribute - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(r32), (void*)(3*sizeof(r32))); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(f32), (void*)(3*sizeof(f32))); glEnableVertexAttribArray(1); // unbind post setup @@ -127,7 +127,7 @@ void DrawTriangle(u32 VAO) glBindVertexArray(0); } -u32 CreateRectangle(r32 vertices[], i32 v_sz, u32 indices[], i32 i_sz) +u32 CreateRectangle(f32 vertices[], i32 v_sz, u32 indices[], i32 i_sz) { u32 VAO; glGenVertexArrays(1, &VAO); @@ -145,11 +145,11 @@ u32 CreateRectangle(r32 vertices[], i32 v_sz, u32 indices[], i32 i_sz) glBufferData(GL_ELEMENT_ARRAY_BUFFER, i_sz, indices, GL_STATIC_DRAW); // position attribute - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(r32), (void*)0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(f32), (void*)0); glEnableVertexAttribArray(0); // color attribute - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(r32), (void*)(3*sizeof(float))); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(f32), (void*)(3*sizeof(float))); glEnableVertexAttribArray(1); // unbind post setup @@ -159,7 +159,7 @@ u32 CreateRectangle(r32 vertices[], i32 v_sz, u32 indices[], i32 i_sz) } -BufferO CreateRectangleTextured(r32 vertices[], i32 v_sz, u32 indices[], i32 i_sz, u32 attr) +BufferO CreateRectangleTextured(f32 vertices[], i32 v_sz, u32 indices[], i32 i_sz, u32 attr) { /* * This will setup options and buffer objects to create a rectangle based on a texture @@ -197,13 +197,13 @@ BufferO CreateRectangleTextured(r32 vertices[], i32 v_sz, u32 indices[], i32 i_s u8 attr_pos = 1; // position attribute - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, stride*sizeof(r32), (void*)0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, stride*sizeof(f32), (void*)0); glEnableVertexAttribArray(0); if (attr & ATTR_COLOR) { // color attribute - glVertexAttribPointer(attr_pos, 3, GL_FLOAT, GL_FALSE, stride*sizeof(r32), (void*)(color_offset*sizeof(r32))); + glVertexAttribPointer(attr_pos, 3, GL_FLOAT, GL_FALSE, stride*sizeof(f32), (void*)(color_offset*sizeof(f32))); glEnableVertexAttribArray(attr_pos); attr_pos += 1; } @@ -211,7 +211,7 @@ BufferO CreateRectangleTextured(r32 vertices[], i32 v_sz, u32 indices[], i32 i_s if (attr & ATTR_TEX) { // texture attribute - glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, stride*sizeof(r32), (void*)(tex_offset*sizeof(r32))); + glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, stride*sizeof(f32), (void*)(tex_offset*sizeof(f32))); glEnableVertexAttribArray(attr_pos); } @@ -226,7 +226,7 @@ BufferO CreateRectangleTextured(r32 vertices[], i32 v_sz, u32 indices[], i32 i_s return BO; } -void MakeRectangleTextured(BufferO *bo, r32 vertices[], i32 v_sz, u32 indices[], i32 i_sz, u32 attr) +void MakeRectangleTextured(BufferO *bo, f32 vertices[], i32 v_sz, u32 indices[], i32 i_sz, u32 attr) { /* * This will setup options and buffer objects to create a rectangle based on a texture @@ -260,13 +260,13 @@ void MakeRectangleTextured(BufferO *bo, r32 vertices[], i32 v_sz, u32 indices[], u8 attr_pos = 1; // position attribute - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, stride*sizeof(r32), (void*)0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, stride*sizeof(f32), (void*)0); glEnableVertexAttribArray(0); if (attr & ATTR_COLOR) { // color attribute - glVertexAttribPointer(attr_pos, 3, GL_FLOAT, GL_FALSE, stride*sizeof(r32), (void*)(color_offset*sizeof(r32))); + glVertexAttribPointer(attr_pos, 3, GL_FLOAT, GL_FALSE, stride*sizeof(f32), (void*)(color_offset*sizeof(f32))); glEnableVertexAttribArray(attr_pos); attr_pos += 1; } @@ -274,7 +274,7 @@ void MakeRectangleTextured(BufferO *bo, r32 vertices[], i32 v_sz, u32 indices[], if (attr & ATTR_TEX) { // texture attribute - glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, stride*sizeof(r32), (void*)(tex_offset*sizeof(r32))); + glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, stride*sizeof(f32), (void*)(tex_offset*sizeof(f32))); glEnableVertexAttribArray(attr_pos); } @@ -298,7 +298,7 @@ void DrawRectangleTextured(u32 VAO, u32 TexO) glBindTexture(GL_TEXTURE_2D, 0); } -BufferO CreateCube(r32 vertices[], i32 v_sz) +BufferO CreateCube(f32 vertices[], i32 v_sz) { u32 VAO; glGenVertexArrays(1, &VAO); @@ -311,11 +311,11 @@ BufferO CreateCube(r32 vertices[], i32 v_sz) glBufferData(GL_ARRAY_BUFFER, v_sz, vertices, GL_STATIC_DRAW); // position attribute - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(r32), (void*)0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(f32), (void*)0); glEnableVertexAttribArray(0); // normal attribute - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(r32), (void*)(3*sizeof(r32))); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(f32), (void*)(3*sizeof(f32))); glEnableVertexAttribArray(1); // unbind post setup @@ -328,7 +328,7 @@ BufferO CreateCube(r32 vertices[], i32 v_sz) return BO; } -BufferO CreateCubeTextured(r32 vertices[], i32 v_sz) +BufferO CreateCubeTextured(f32 vertices[], i32 v_sz) { /* * This will setup options and buffer objects to create a rectangle based on a texture @@ -345,15 +345,15 @@ BufferO CreateCubeTextured(r32 vertices[], i32 v_sz) glBufferData(GL_ARRAY_BUFFER, v_sz, vertices, GL_STATIC_DRAW); // position attribute - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8*sizeof(r32), (void*)0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8*sizeof(f32), (void*)0); glEnableVertexAttribArray(0); // normal attribute - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8*sizeof(r32), (void*)(3*sizeof(r32))); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8*sizeof(f32), (void*)(3*sizeof(f32))); glEnableVertexAttribArray(1); // texture attribute - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8*sizeof(r32), (void*)(6*sizeof(r32))); + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8*sizeof(f32), (void*)(6*sizeof(f32))); glEnableVertexAttribArray(2); // unbind post setup diff --git a/code/gl_graphics.h b/code/gl_graphics.h index d97d062..4f52035 100644 --- a/code/gl_graphics.h +++ b/code/gl_graphics.h @@ -1,18 +1,33 @@ #ifndef GL_GRAPHICS_H #define GL_GRAPHICS_H +typedef struct BufferO { + u32 VAO; // Vertex Array Object + u32 VBO; // Vertex Buffer Object + u32 EBO; // Element Buffer Object + u32 TexO; // Texture Buffer Object + u32 *TexArray; // Tex Object Array +} BufferO; + +typedef struct Texture2D { + i32 width; + i32 height; + i32 nrChannels; + unsigned char* data; +} Texture2D; + void LoadUniformInt(u32 SP, const char *Unifrom, i32 Val); -void LoadUniformFloat(u32 SP, const char *Uniform, r32 Val); +void LoadUniformFloat(u32 SP, const char *Uniform, f32 Val); void LoadUniformVec3(u32 SP, const char *Unifrom, Vec3 Val); void LoadUniformMat4(u32 SP, const char *Uniform, Mat4 Val); u32 CreateVertexShader(const char *VertexShaderSource); u32 CreateFragmentShader(const char *FragmentShaderSource); u32 CreateShaderProgram(unsigned int VertexShader, unsigned int FragmentShader); -u32 CreateTriangle(r32 vertices[], i32 sz); +u32 CreateTriangle(f32 vertices[], i32 sz); void DrawTriangle(u32 VAO); -u32 CreateRectangle(r32 vertices[], i32 v_sz, u32 indices[], i32 i_sz); +u32 CreateRectangle(f32 vertices[], i32 v_sz, u32 indices[], i32 i_sz); /** * @note: the texture functions for rectangle are more obtuse and less clear * they don't make as much sense. And they dont just create something. @@ -21,13 +36,13 @@ u32 CreateRectangle(r32 vertices[], i32 v_sz, u32 indices[], i32 i_sz); * * @todo: I need to probably add the examples to my utils file as notes * */ -BufferO CreateRectangleTextured(r32 vertices[], i32 v_sz, u32 indices[], i32 i_sz, u32 attr); -void MakeRectangleTextured(BufferO *bo, r32 vertices[], i32 v_sz, u32 indices[], i32 i_sz, u32 attr); +BufferO CreateRectangleTextured(f32 vertices[], i32 v_sz, u32 indices[], i32 i_sz, u32 attr); +void MakeRectangleTextured(BufferO *bo, f32 vertices[], i32 v_sz, u32 indices[], i32 i_sz, u32 attr); void DrawRectangle(u32 VAO); void DrawRectangleTextured(u32 VAO, u32 TexO); -BufferO CreateCube(r32 vertices[], i32 v_sz); -BufferO CreateCubeTextured(r32 vertices[], i32 v_sz); +BufferO CreateCube(f32 vertices[], i32 v_sz); +BufferO CreateCubeTextured(f32 vertices[], i32 v_sz); void DrawCube(u32 VAO); GLint GetColorAttrib(u32 nrChannels); diff --git a/code/math.h b/code/math.h index 7a64285..ca5e96e 100644 --- a/code/math.h +++ b/code/math.h @@ -12,8 +12,8 @@ #define PIVOT_Z 2 typedef struct Vec2 { - r32 x; - r32 y; + f32 x; + f32 y; Vec2 operator-(Vec2 S) { @@ -39,7 +39,7 @@ typedef struct Vec2 { return R; } - Vec2 operator/(r32 s) + Vec2 operator/(f32 s) { Vec2 R = {0}; R.x = x/2; @@ -57,9 +57,9 @@ typedef struct Vec2 { } Vec2; typedef struct Vec3 { - r32 x; - r32 y; - r32 z; + f32 x; + f32 y; + f32 z; Vec3 operator+(Vec3 S) { @@ -70,7 +70,7 @@ typedef struct Vec3 { return R; } - Vec3 operator+(r32 S) + Vec3 operator+(f32 S) { Vec3 R = {0}; R.x = x + S; @@ -79,7 +79,7 @@ typedef struct Vec3 { return R; } - Vec3 operator*(r32 S) + Vec3 operator*(f32 S) { Vec3 R; R.x = x * S; @@ -89,7 +89,7 @@ typedef struct Vec3 { return R; } - Vec3 operator/(r32 S) + Vec3 operator/(f32 S) { Vec3 R; R.x = x / S; @@ -101,68 +101,68 @@ typedef struct Vec3 { } Vec3; typedef struct Vec4 { - r32 x; - r32 y; - r32 z; - r32 w; + f32 x; + f32 y; + f32 z; + f32 w; } Vec4; typedef struct Mat4 { - r32 x0, x1, x2, x3; - r32 y0, y1, y2, y3; - r32 z0, z1, z2, z3; - r32 w0, w1, w2, w3; + f32 x0, x1, x2, x3; + f32 y0, y1, y2, y3; + f32 z0, z1, z2, z3; + f32 w0, w1, w2, w3; } Mat4; -Vec3 InitVec3(r32 Val); -Vec3 InitVec3(r32 x, r32 y, r32 z); -r32 LenVec3(Vec3 V); +Vec3 InitVec3(f32 Val); +Vec3 InitVec3(f32 x, f32 y, f32 z); +f32 LenVec3(Vec3 V); Vec3 UnitVec3(Vec3 V); -r32 DotProductVec3(Vec3 S, Vec3 K); +f32 DotProductVec3(Vec3 S, Vec3 K); Vec3 CrossProductVec3(Vec3 S, Vec3 K); -Vec4 InitVec4(r32 x, r32 y, r32 z, r32 w); -Vec4 ScalerAdd4(Vec4 Vec, r32 Scaler); -Vec4 ScalerMul4(Vec4 Vec, r32 Scaler); -Vec4 ScalerDiv4(Vec4 Vec, r32 Scaler); +Vec4 InitVec4(f32 x, f32 y, f32 z, f32 w); +Vec4 ScalerAdd4(Vec4 Vec, f32 Scaler); +Vec4 ScalerMul4(Vec4 Vec, f32 Scaler); +Vec4 ScalerDiv4(Vec4 Vec, f32 Scaler); Vec4 AddVec4(Vec4 V, Vec4 K); -r32 LenVec4(Vec4 V); +f32 LenVec4(Vec4 V); Vec4 UnitVec4(Vec4 V); -r32 DotProductVec4(Vec4 S, Vec4 K); +f32 DotProductVec4(Vec4 S, Vec4 K); Vec4 Mul_Mat4Vec4(Mat4 Matrix, Vec4 S); Mat4 IdentityMat(); Mat4 Mul_Mat4Mat4(Mat4 M1, Mat4 M2); Mat4 CreateTranslationMat(Vec4 S); Mat4 CreateScaleMat(Vec4 S); -Mat4 CreateRotationMat(r32 Theta, u8 Pivot); -Mat4 CreateFrustum(r32 left, r32 right, r32 bot, r32 top, r32 nearCam, r32 farCam); -Mat4 CreatePerspectiveUsingFrustum(r32 fov, r32 aspect, r32 nearCam, r32 farCam); -Mat4 CreateOrthographic(r32 left, r32 right, r32 bot, r32 top, r32 nearCam, r32 farCam); -Mat4 CreateOrthographicWithRatio(r32 scrWidth, r32 scrHeight, r32 nearCam, r32 farCam); +Mat4 CreateRotationMat(f32 Theta, u8 Pivot); +Mat4 CreateFrustum(f32 left, f32 right, f32 bot, f32 top, f32 nearCam, f32 farCam); +Mat4 CreatePerspectiveUsingFrustum(f32 fov, f32 aspect, f32 nearCam, f32 farCam); +Mat4 CreateOrthographic(f32 left, f32 right, f32 bot, f32 top, f32 nearCam, f32 farCam); +Mat4 CreateOrthographicWithRatio(f32 scrWidth, f32 scrHeight, f32 nearCam, f32 farCam); Mat4 CreateLookAtMat4(Vec3 CameraPos, Vec3 CameraTarget, Vec3 Up); -Vec3 InitVec3(r32 val) +Vec3 InitVec3(f32 val) { Vec3 R = Vec3{val,val,val}; return R; } -Vec3 InitVec3(r32 x, r32 y, r32 z) +Vec3 InitVec3(f32 x, f32 y, f32 z) { Vec3 R = Vec3{x,y,z}; return R; } -r32 LenVec3(Vec3 V) +f32 LenVec3(Vec3 V) { - r32 L = Sqrt(Sq(V.x) + Sq(V.y) + Sq(V.z)); + f32 L = Sqrt(Sq(V.x) + Sq(V.y) + Sq(V.z)); return L; } Vec3 UnitVec3(Vec3 V) { Vec3 R; - r32 L = LenVec3(V); + f32 L = LenVec3(V); R.x = V.x/L; R.y = V.y/L; R.z = V.z/L; @@ -170,14 +170,14 @@ Vec3 UnitVec3(Vec3 V) return R; } -r32 DotProductVec3(Vec3 S, Vec3 K) +f32 DotProductVec3(Vec3 S, Vec3 K) { Vec3 R; R.x = S.x*K.x; R.y = S.y*K.y; R.z = S.z*K.z; - r32 DotProd = R.x + R.y + R.z; + f32 DotProd = R.x + R.y + R.z; return DotProd; } @@ -194,7 +194,7 @@ Vec3 CrossProductVec3(Vec3 S, Vec3 K) // @note: I am creating vectors in many places so created a function to make initialising abit easier -Vec4 InitVec4(r32 x, r32 y, r32 z, r32 w) +Vec4 InitVec4(f32 x, f32 y, f32 z, f32 w) { Vec4 V = {0}; V.x = x; @@ -206,7 +206,7 @@ Vec4 InitVec4(r32 x, r32 y, r32 z, r32 w) } -Vec4 ScalerAdd4(Vec4 Vec, r32 Scaler) +Vec4 ScalerAdd4(Vec4 Vec, f32 Scaler) { Vec.x += Scaler; Vec.y += Scaler; @@ -216,7 +216,7 @@ Vec4 ScalerAdd4(Vec4 Vec, r32 Scaler) return Vec; } -Vec4 ScalerMul4(Vec4 Vec, r32 Scaler) +Vec4 ScalerMul4(Vec4 Vec, f32 Scaler) { Vec.x *= Scaler; Vec.y *= Scaler; @@ -226,7 +226,7 @@ Vec4 ScalerMul4(Vec4 Vec, r32 Scaler) return Vec; } -Vec4 ScalerDiv4(Vec4 Vec, r32 Scaler) +Vec4 ScalerDiv4(Vec4 Vec, f32 Scaler) { Vec.x = Vec.x/Scaler; Vec.y = Vec.y/Scaler; @@ -247,16 +247,16 @@ Vec4 AddVec4(Vec4 V, Vec4 K) return Res; } -r32 LenVec4(Vec4 V) +f32 LenVec4(Vec4 V) { - r32 L = Sqrt(Sq(V.x) + Sq(V.y) + Sq(V.z) +Sq(V.w)); + f32 L = Sqrt(Sq(V.x) + Sq(V.y) + Sq(V.z) +Sq(V.w)); return L; } Vec4 UnitVec4(Vec4 V) { Vec4 R = {0}; - r32 L = LenVec4(V); + f32 L = LenVec4(V); R.x = V.x/L; R.y = V.y/L; R.z = V.z/L; @@ -265,7 +265,7 @@ Vec4 UnitVec4(Vec4 V) return R; } -r32 DotProductVec4(Vec4 S, Vec4 K) +f32 DotProductVec4(Vec4 S, Vec4 K) { Vec4 R = {0}; R.x = S.x*K.x; @@ -273,7 +273,7 @@ r32 DotProductVec4(Vec4 S, Vec4 K) R.z = S.z*K.z; R.w = S.w*K.w; - r32 DotProd = R.x + R.y + R.z + R.w; + f32 DotProd = R.x + R.y + R.z + R.w; return DotProd; } @@ -352,10 +352,10 @@ Mat4 CreateScaleMat(Vec4 S) return SM; } -Mat4 CreateRotationMat(r32 Theta, u8 Pivot) +Mat4 CreateRotationMat(f32 Theta, u8 Pivot) { - r32 CosTheta = cos(Theta); - r32 SinTheta = sin(Theta); + f32 CosTheta = cos(Theta); + f32 SinTheta = sin(Theta); Mat4 RotMat = {0}; if (Pivot == PIVOT_X) @@ -383,7 +383,7 @@ Mat4 CreateRotationMat(r32 Theta, u8 Pivot) return RotMat; } -Mat4 CreateFrustum(r32 left, r32 right, r32 bot, r32 top, r32 nearCam, r32 farCam) +Mat4 CreateFrustum(f32 left, f32 right, f32 bot, f32 top, f32 nearCam, f32 farCam) { Mat4 F = {0}; F.x0 = 2.0f*nearCam/(right - left); @@ -398,17 +398,17 @@ Mat4 CreateFrustum(r32 left, r32 right, r32 bot, r32 top, r32 nearCam, r32 farCa return F; } -Mat4 CreatePerspectiveUsingFrustum(r32 fov, r32 aspect, r32 nearCam, r32 farCam) +Mat4 CreatePerspectiveUsingFrustum(f32 fov, f32 aspect, f32 nearCam, f32 farCam) { - r32 top = nearCam*tan(fov)/2; - r32 bot = -top; - r32 right = top*aspect; - r32 left = -right; + f32 top = nearCam*tan(fov)/2; + f32 bot = -top; + f32 right = top*aspect; + f32 left = -right; return CreateFrustum(left, right, bot, top, nearCam, farCam); } -Mat4 CreateOrthographic(r32 left, r32 right, r32 bot, r32 top, r32 nearCam, r32 farCam) +Mat4 CreateOrthographic(f32 left, f32 right, f32 bot, f32 top, f32 nearCam, f32 farCam) { Mat4 F = {0}; F.x0 = 2.0f/(right - left); @@ -425,15 +425,15 @@ Mat4 CreateOrthographic(r32 left, r32 right, r32 bot, r32 top, r32 nearCam, r32 return F; } -Mat4 CreateOrthographicWithRatio(r32 scrWidth, r32 scrHeight, r32 nearCam, r32 farCam) +Mat4 CreateOrthographicWithRatio(f32 scrWidth, f32 scrHeight, f32 nearCam, f32 farCam) { - r32 ratio_h = scrWidth/scrHeight; - r32 left = -ratio_h; - r32 right = ratio_h; + f32 ratio_h = scrWidth/scrHeight; + f32 left = -ratio_h; + f32 right = ratio_h; - r32 ratio_v = scrHeight/scrWidth; - r32 top = ratio_v; - r32 bot = -ratio_v; + f32 ratio_v = scrHeight/scrWidth; + f32 top = ratio_v; + f32 bot = -ratio_v; return CreateOrthographic(left, right, bot, top, nearCam, farCam); } diff --git a/code/win32_main.cpp b/code/win32_main.cpp index 4ea173d..208e85a 100644 --- a/code/win32_main.cpp +++ b/code/win32_main.cpp @@ -23,8 +23,8 @@ typedef u8 b8; typedef u16 b16; typedef u32 b32; -typedef float r32; -typedef double r64; +typedef float f32; +typedef double f64; #include "math.h" @@ -33,11 +33,10 @@ typedef double r64; #define internal static /** - * Text rendering todos: + * Font rendering todos: * - Look into font-packing, what is that? why is it needed? * - Look into generating a single bitmap and then extracting characters from the * bitmap as needed - * - Same thing as what I do now, but not using all the bitmaps * - SDF font rendering * */ internal i64 GlobalPerfCountFrequency; @@ -67,6 +66,16 @@ i8 PlatformDebugReadFile(char *FileName, void *FileBuffer, u32 MaxSize, LPDWORD } } +void PlatformCopyMemory(void *NewMem, void *OldMem, size_t CopySize) +{ + CopyMemory(NewMem, OldMem, CopySize); +} + +void PlatformZeroMemory(void *Ptr, size_t Size) +{ + ZeroMemory(Ptr, Size); +} + void framebuffer_size_callback(GLFWwindow *window, i32 width, i32 height) { glViewport(0, 0, width, height); @@ -81,143 +90,24 @@ Win32GetWallClock(void) return Result; } -inline r32 +inline f32 Win32GetSecondsElapsed(LARGE_INTEGER Start, LARGE_INTEGER End) { - r32 Result = (r32)(End.QuadPart - Start.QuadPart)/(r32)GlobalPerfCountFrequency; + f32 Result = (f32)(End.QuadPart - Start.QuadPart)/(f32)GlobalPerfCountFrequency; return(Result); } -#ifndef DEFAULT_ALIGNMENT -#define DEFAULT_ALIGNMENT (2*sizeof(void *)) -#endif - -typedef struct DebugArena { - u8 *Buffer; - size_t Size; - size_t CurrOffset; - size_t PrevOffset; -} DebugArena; - -bool IsPowerOfTwo(uintptr_t x) -{ - return (x & (x-1)) == 0; -} - -uintptr_t AlignForward(uintptr_t ptr, size_t align) -{ - uintptr_t p, a, modulo; - - assert(IsPowerOfTwo(align)); - p = ptr; - a = (uintptr_t)align; - modulo = p & (a-1); - - if (modulo != 0) - { - p += a - modulo; - } - return p; -} - -void *ArenaAllocAlign(DebugArena *Alloc, size_t Size, size_t Align) -{ - uintptr_t CurrOffset = (uintptr_t)Alloc->Buffer + (uintptr_t)Alloc->CurrOffset; - uintptr_t AlignedOffset = AlignForward(CurrOffset, Align); - AlignedOffset -= (uintptr_t)(Alloc->Buffer); - - if (AlignedOffset + Size < Alloc->Size) - { - void *Ptr = &Alloc->Buffer[AlignedOffset]; - Alloc->PrevOffset = AlignedOffset; - Alloc->CurrOffset = AlignedOffset + Size; - - ZeroMemory(Ptr, Size); - return Ptr; - } - return NULL; -} - -void ArenaInit(DebugArena *Alloc, void* BackingBuffer, size_t Size) -{ - Alloc->Buffer = (u8 *)BackingBuffer; - Alloc->Size = Size; - Alloc->CurrOffset = 0; - Alloc->PrevOffset = 0; -} - -void *ArenaAlloc(DebugArena *Alloc, size_t Size) -{ - return ArenaAllocAlign(Alloc, Size, DEFAULT_ALIGNMENT); -} - -void ArenaFree(DebugArena *Alloc, void *Ptr) -{ - // do nothing -} - -void *ArenaResizeAlign(DebugArena *Alloc, void *OldMem, size_t OldSize, - size_t NewSize, size_t Align) -{ - assert(IsPowerOfTwo(Align)); - if (OldMem == NULL || OldSize == 0) - { - return ArenaAllocAlign(Alloc, NewSize, Align); - } - else if (Alloc->Buffer < OldMem && OldMem < Alloc->Buffer + Alloc->Size) - { - // check if old_memory falls on prev_offset - if (Alloc->Buffer + Alloc->PrevOffset == OldMem) - { - // re-use prev_offset and resize from there - size_t _CurrOffset = Alloc->CurrOffset; - Alloc->CurrOffset = Alloc->PrevOffset + NewSize; - if (NewSize > OldSize) - { - ZeroMemory(&Alloc->Buffer[_CurrOffset], NewSize - OldSize); - } - return OldMem; - } - else - { - // generate new memory - // will have some fragmentation - void *NewMem = ArenaAllocAlign(Alloc, NewSize, Align); - size_t CopySize = OldSize < NewSize ? OldSize : NewSize; - - // copy old memory to new memory location - CopyMemory(NewMem, OldMem, CopySize); - return NewMem; - } - } - else - { - assert(0 && "Memory is out of bounds of the buffer in this arena"); - return NULL; - } -} - -void *ArenaResize(DebugArena *Alloc, void *OldMem, size_t OldSize, size_t NewSize) -{ - return ArenaResizeAlign(Alloc, OldMem, OldSize, NewSize, DEFAULT_ALIGNMENT); -} - -void ArenaFreeAll(DebugArena *Alloc) -{ - Alloc->CurrOffset = 0; - Alloc->PrevOffset = 0; -} - -#include "game_main.h" +#include "amr_memory.c" #include "gl_graphics.cpp" +#include "game_main.h" -typedef struct glyph_info { +typedef struct amr_glyph_info { u32 charset_start_index; u32 charset_end_index; -} glyph_info; +} amr_glyph_info; -u32 GetGlyphIdFromCodepoint(glyph_info glyph, u32 *GlyphIndexArray, u32 Codepoint) +u32 amr_GetGlyphIdFromCodepoint(amr_glyph_info glyph, u32 *GlyphIndexArray, u32 Codepoint) { u32 glyph_id = *(GlyphIndexArray + (Codepoint - glyph.charset_start_index)); return glyph_id; @@ -238,7 +128,7 @@ int main() // TODO(talha): how to use a library to query this i32 MonitorRefreshHz = 60; i32 GameUpdateHz = MonitorRefreshHz; - r32 TargetSecondsPerFrame = 1.0f / (r32)GameUpdateHz; + f32 TargetSecondsPerFrame = 1.0f / (f32)GameUpdateHz; GameState State = {0}; State.Input.LastMouseX = WIN_WIDTH/2.0f; @@ -288,19 +178,19 @@ int main() State.Memory.PermanentStorage = PermanentStorage; State.Memory.PermanentStorageSize = PermanentStorageSize; - ArenaInit(&State.Memory.Arena, State.Memory.PermanentStorage, State.Memory.PermanentStorageSize); + amr_ArenaInit(&State.Memory.Arena, State.Memory.PermanentStorage, State.Memory.PermanentStorageSize); // ======================= SHADER PROGRAM LOADING ======== DWORD BytesRead = 0; u32 max_fsz = MB((u64)5); - u8 *vs_file = (u8 *)ArenaAlloc(&State.Memory.Arena, max_fsz); + u8 *vs_file = (u8 *)amr_ArenaAlloc(&State.Memory.Arena, max_fsz); if (PlatformDebugReadFile("./code/shaders/text.vs.glsl", vs_file, max_fsz, &BytesRead) != 1) { printf("ERROR: failed to open text vertex shader"); return -1; } - u8 *fs_file = (u8 *)ArenaAlloc(&State.Memory.Arena, max_fsz); + u8 *fs_file = (u8 *)amr_ArenaAlloc(&State.Memory.Arena, max_fsz); if (PlatformDebugReadFile("./code/shaders/text.fs.glsl", fs_file, max_fsz, &BytesRead) != 1) { printf("ERROR: failed to open text vertex shader"); @@ -311,11 +201,11 @@ int main() u32 fs = CreateFragmentShader((char *)fs_file); u32 sp = CreateShaderProgram(vs, fs); - ArenaFreeAll(&State.Memory.Arena); + amr_ArenaFreeAll(&State.Memory.Arena); // =================== FONT RENDERING =================== u32 font_fz = MB(2); - u8 *ArialBuffer = (u8 *)ArenaAlloc(&State.Memory.Arena, font_fz); + u8 *ArialBuffer = (u8 *)amr_ArenaAlloc(&State.Memory.Arena, font_fz); // @todo: change to PlatformDebugFileRead fread(ArialBuffer, 1, font_fz, fopen("c:/windows/fonts/arial.ttf", "rb")); @@ -328,16 +218,16 @@ int main() } // get a SF (scale factor) - r32 SF = stbtt_ScaleForPixelHeight(&font_info, 32.0f); + f32 SF = stbtt_ScaleForPixelHeight(&font_info, 32.0f); // get vertical metrics i32 f_ascent, f_descent, f_line_gap; stbtt_GetFontVMetrics(&font_info, &f_ascent, &f_descent, &f_line_gap); // ========================= GLYPH AND FONT INFO STORAGE ================ - glyph_info latin_basic = {32, 126}; + amr_glyph_info latin_basic = {32, 126}; u32 glyph_count = latin_basic.charset_end_index - latin_basic.charset_start_index; - u32 *GlyphIndexArray = (u32 *)ArenaAlloc(&State.Memory.Arena, sizeof(glyph_count) * glyph_count); + u32 *GlyphIndexArray = (u32 *)amr_ArenaAlloc(&State.Memory.Arena, sizeof(glyph_count) * glyph_count); u32 *glyph_array_iter = GlyphIndexArray; for (u32 i = 0; i < glyph_count; i++) { @@ -350,10 +240,10 @@ int main() u32 fd_sz = sizeof(debug_font_details)*char_sz; - debug_font_details *fd_arr = (debug_font_details *)ArenaAlloc(&State.Memory.Arena, fd_sz); + debug_font_details *fd_arr = (debug_font_details *)amr_ArenaAlloc(&State.Memory.Arena, fd_sz); debug_font_details *_fi = fd_arr; - r32 lx = 0.0f, max_lx = 0.0f; + f32 lx = 0.0f, max_lx = 0.0f; i32 baseline = (i32)roundf(f_ascent * SF); // convert str to font for (i32 i = 0; i < char_sz; ++i) @@ -370,18 +260,19 @@ int main() continue; } - stbtt_GetGlyphHMetrics(&font_info, GetGlyphIdFromCodepoint(latin_basic, GlyphIndexArray, text[i]), &_fi->advance, &_fi->lsb); - stbtt_GetGlyphBitmapBox(&font_info, GetGlyphIdFromCodepoint(latin_basic, GlyphIndexArray, text[i]), SF, SF, &_fi->x0, &_fi->y0, &_fi->x1, &_fi->y1); + stbtt_GetGlyphHMetrics(&font_info, amr_GetGlyphIdFromCodepoint(latin_basic, GlyphIndexArray, text[i]), &_fi->advance, &_fi->lsb); + stbtt_GetGlyphBitmapBox(&font_info, amr_GetGlyphIdFromCodepoint(latin_basic, GlyphIndexArray, text[i]), SF, SF, &_fi->x0, &_fi->y0, &_fi->x1, &_fi->y1); - _fi->ly = (r32)(_fi->baseline + _fi->y0); + _fi->ly = (f32)(_fi->baseline + _fi->y0); lx += (_fi->advance * SF); i32 kern; if (i < char_sz - 1 && text[i+1] != '\n') { - kern = stbtt_GetGlyphKernAdvance(&font_info, GetGlyphIdFromCodepoint(latin_basic, GlyphIndexArray, text[i]), GetGlyphIdFromCodepoint(latin_basic, GlyphIndexArray, text[i])); + kern = stbtt_GetGlyphKernAdvance(&font_info, amr_GetGlyphIdFromCodepoint(latin_basic, GlyphIndexArray, text[i]), amr_GetGlyphIdFromCodepoint(latin_basic, GlyphIndexArray, text[i+1])); lx += roundf(kern * SF); } + if (lx > max_lx) { max_lx = lx; @@ -395,7 +286,7 @@ int main() u32 bitmap_height_from_text_info = (u32)(baseline - roundf(SF * f_descent)); i32 bmp_sz = sizeof(u8)*bitmap_width_from_text_info*bitmap_height_from_text_info; - u8 *Bitmap = (u8 *)ArenaAlloc(&State.Memory.Arena, bmp_sz); + u8 *Bitmap = (u8 *)amr_ArenaAlloc(&State.Memory.Arena, bmp_sz); _fi = fd_arr; for (int i=0; i<char_sz; i++) @@ -406,14 +297,14 @@ int main() } _fi->byte_offset = (i32)(_fi->lx + roundf(_fi->lsb * SF) + (_fi->ly * bitmap_width_from_text_info)) ; // store image data in bitmap - stbtt_MakeGlyphBitmap(&font_info, Bitmap + _fi->byte_offset, _fi->x1 - _fi->x0, _fi->y1 - _fi->y0, bitmap_width_from_text_info, SF, SF, GetGlyphIdFromCodepoint(latin_basic, GlyphIndexArray, text[i])); + stbtt_MakeGlyphBitmap(&font_info, Bitmap + _fi->byte_offset, _fi->x1 - _fi->x0, _fi->y1 - _fi->y0, bitmap_width_from_text_info, SF, SF, amr_GetGlyphIdFromCodepoint(latin_basic, GlyphIndexArray, text[i])); _fi++; } // ---------- prepare bitmap texture and buffer objects ----------- glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - r32 bmp_vertices[] = { + f32 bmp_vertices[] = { // positions // texture coords 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,// top right 1.0f, -1.0f, 0.0f, 1.0f, 0.0f,// bottom right @@ -482,12 +373,12 @@ int main() State.ScreenCoords.br = ScreenMidCoords + ScreenMidPx; // ====================== TEXT POSITIONING AND SCALING ====== - Vec2 text_dims = {((r32)bitmap_width_from_text_info)/2.0f, ((r32)bitmap_height_from_text_info)/2.0f}; + Vec2 text_dims = {((f32)bitmap_width_from_text_info)/2.0f, ((f32)bitmap_height_from_text_info)/2.0f}; Vec2 text_scaled_dims = State.px_ratio * text_dims; Vec2 text_scaled_mid = text_scaled_dims/2.0f; Vec2 text_pos = {0.0f, 0.0f}; - Vec2 text_offset = {text_dims.x/2.0f, (r32)fd_arr->baseline}; + Vec2 text_offset = {text_dims.x/2.0f, (f32)fd_arr->baseline}; text_pos = text_offset + text_pos; Vec2 text_scaled_pos = State.px_ratio*(State.ScreenCoords.tl + text_pos) + text_scaled_mid; @@ -502,9 +393,9 @@ int main() while (!glfwWindowShouldClose(Window)) { LARGE_INTEGER WorkCounter = Win32GetWallClock(); - r32 WorkSecondsElapsed = Win32GetSecondsElapsed(LastCounter, WorkCounter); + f32 WorkSecondsElapsed = Win32GetSecondsElapsed(LastCounter, WorkCounter); - r32 SecondsElapsedForFrame = WorkSecondsElapsed; + f32 SecondsElapsedForFrame = WorkSecondsElapsed; // @note: this caps the framerate // also prevents, for now, incorrect speeds based on timings // @todo: fix framerate capping and speed timings being affected by framerate @@ -560,11 +451,11 @@ int main() // far value is the max z-index value. Will be useful for layering textures Mat4 Projection = CreateOrthographicWithRatio(WIN_WIDTH, WIN_HEIGHT, -5.0f, 5.0f); - const r32 view[16] = {View.x0, View.x1, View.x2, View.x3, + const f32 view[16] = {View.x0, View.x1, View.x2, View.x3, View.y0, View.y1, View.y2, View.y3, View.z0, View.z1, View.z2, View.z3, View.w0, View.w1, View.w2, View.w3}; - const r32 projection[16] = {Projection.x0, Projection.x1, Projection.x2, Projection.x3, + const f32 projection[16] = {Projection.x0, Projection.x1, Projection.x2, Projection.x3, Projection.y0, Projection.y1, Projection.y2, Projection.y3, Projection.z0, Projection.z1, Projection.z2, Projection.z3, Projection.w0, Projection.w1, Projection.w2, Projection.w3}; @@ -587,7 +478,7 @@ int main() Mat4 Tx1 = CreateTranslationMat(InitVec4(container_pos.x, container_pos.y, -1.0f, 0)); Model = Mul_Mat4Mat4(Tx1, Model); - const r32 container_model[16] = {Model.x0, Model.x1, Model.x2, Model.x3, + const f32 container_model[16] = {Model.x0, Model.x1, Model.x2, Model.x3, Model.y0, Model.y1, Model.y2, Model.y3, Model.z0, Model.z1, Model.z2, Model.z3, Model.w0, Model.w1, Model.w2, Model.w3}; @@ -602,7 +493,7 @@ int main() Model = Mul_Mat4Mat4(Scale2, Model); Model = Mul_Mat4Mat4(Tx, Model); - const r32 field_model[16] = {Model.x0, Model.x1, Model.x2, Model.x3, + const f32 field_model[16] = {Model.x0, Model.x1, Model.x2, Model.x3, Model.y0, Model.y1, Model.y2, Model.y3, Model.z0, Model.z1, Model.z2, Model.z3, Model.w0, Model.w1, Model.w2, Model.w3}; @@ -618,7 +509,7 @@ int main() Mat4 Tx = CreateTranslationMat(InitVec4(text_scaled_pos.x, text_scaled_pos.y, 0, 0)); Model = Mul_Mat4Mat4(Tx, Model); - const r32 text_model[16] = {Model.x0, Model.x1, Model.x2, Model.x3, + const f32 text_model[16] = {Model.x0, Model.x1, Model.x2, Model.x3, Model.y0, Model.y1, Model.y2, Model.y3, Model.z0, Model.z1, Model.z2, Model.z3, Model.w0, Model.w1, Model.w2, Model.w3}; diff --git a/code/stb_rect_pack.h b/include/stb_rect_pack.h index 6a633ce..6a633ce 100644 --- a/code/stb_rect_pack.h +++ b/include/stb_rect_pack.h diff --git a/code/stb_truetype.h b/include/stb_truetype.h index bbf2284..bbf2284 100644 --- a/code/stb_truetype.h +++ b/include/stb_truetype.h |