Include Base.h to include all the base\ headers in the project. These are the bare minimum functionality for the library which are to be included in each project.
For modules\ each file can be included individually into the program as a single module.
#include "Base.h"
#include "Window.h"
#include "OpenGL.h"
/* This is the output of the metaprogram that generates the forward declarations for everything.
So, in this codebase, we don't need to forward declare anything or do things in any specific order,
since the metaprogram generates headers automatically.
*/
#include "global_headers.h"
/* For enums to be forward declared, they have to be defined with the macro enum_type(name, type).
This is the only way to make the metaprogrma know what is the identifier and type that it should typedef this enum to.
*/
enum_type(My_Enum, u32)
{
My_Enum_None = 0,
My_Enum_One,
My_Enum_Two
};
global Window *gWindow = NULL;
global Arena *gArena = NULL;
global b8 gShouldQuit = false;
global u32 TriangleVAO = 0;
global u32 TriangleVBO = 0;
global u32 TriangleVSProgram = 0;
global u32 TriangleFSProgram = 0;
global u32 TrianglePipeline = 0;
// Opengl setup
global f32 vertices[] = {
// pos // color
0.0f, 0.7f, 1.0f, 0.0f, 0.0f,
-0.7f, -0.7f, 0.0f, 1.0f, 0.0f,
0.7f, -0.7f, 0.0f, 0.0f, 1.0f,
};
global const char *TriangleVS =
"#version 460 core \n"
"layout(location=0) in vec2 a_pos; \n"
"layout(location=1) in vec3 a_color; \n"
"out vec3 v_color; \n"
"out \n"
"gl_PerVertex \n"
"{ \n"
" vec4 gl_Position; \n"
"}; \n"
"void main() \n"
"{ \n"
" gl_Position = vec4(a_pos,0.0,1.0); \n"
" v_color = a_color; \n"
"} \n";
global const char *TriangleFS =
"#version 460 core \n"
"in vec3 v_color; \n"
"out vec4 frag_color; \n"
"void main() \n"
"{ \n"
" frag_color = vec4(v_color,1.0); \n"
"} \n";
function void
handle_input()
{
if (input_is_key_clicked(Keyboard_Key_ESCAPE))
{
gShouldQuit = true;
}
}
function void
metaprogram_entry_point(Arena* arena, Command_Line *command_line, String project_path)
{
}
function void
entry_point(Command_Line *command_line)
{
console_attach();
gWindow = window_create(NULL, S("OpenGL Example "), 600, 400, 30, 30);
opengl_init(gWindow);
// Opengl Setup
{
TriangleVSProgram = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &TriangleVS);
TriangleFSProgram = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &TriangleFS);
glCreateProgramPipelines(1, &TrianglePipeline);
glUseProgramStages(TrianglePipeline, GL_VERTEX_SHADER_BIT, TriangleVSProgram);
glUseProgramStages(TrianglePipeline, GL_FRAGMENT_SHADER_BIT, TriangleFSProgram);
glCreateBuffers(1, &TriangleVBO);
glNamedBufferStorage(TriangleVBO, sizeof(vertices), vertices, 0);
glCreateVertexArrays(1, &TriangleVAO);
glVertexArrayVertexBuffer(TriangleVAO, 0, TriangleVBO, 0, sizeof(f32)*5);
glEnableVertexArrayAttrib(TriangleVAO, 0);
glVertexArrayAttribFormat(TriangleVAO, 0, 2, GL_FLOAT, GL_FALSE, 0);
glVertexArrayAttribBinding(TriangleVAO, 0, 0);
glEnableVertexArrayAttrib(TriangleVAO, 1);
glVertexArrayAttribFormat(TriangleVAO, 1, 3, GL_FLOAT, GL_FALSE, sizeof(f32)*2);
glVertexArrayAttribBinding(TriangleVAO, 1, 0);
}
while (!gShouldQuit)
{
window_update_events();
handle_input();
// Opengl Draw
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0,0,gWindow->width,gWindow->height);
glClearColor(0.1f,0.1f,0.1f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBindProgramPipeline(TrianglePipeline);
glBindVertexArray(TriangleVAO);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
window_swap_buffers(gWindow);
clear_temporary_storage();
}
}base\: Core library.modules\: Opt-In modules provided by the library.Extern\: Opt-in external code imported into this library.
Opt-inmeans that it has to be explicitly included by the user
This codebase includes a default metaprogram that generates the headers and forward declarations for
enums, structs and functions. Additionally to the default metaprogram, you can implement the function metaprogram_entry_point
to implement a project specific metaprogram.
The base layer includes:
Math: Linear math functionsAllocators: Custom allocators- Arena Allocator
- Pool Allocator
- Scratch memory functions for short lived memory.
Context_Cracking: Parses platform (OS, Compiler, CPU Arch ... ) into macros.Core: Defines data types and some helper macrosOs: Operating system specific core functionsCustom_Entry_Point: Defines the entry_point function that has to be implemented by the user.Memory: OS Dependent implementation of memory functions (Reserve, Free, etc... ).String: Immutable count based strings.Thread_Context: Implementes a thread context that includes temporary memory.
OpenGL: Opengl macros, bindings and helpers.Platform: Generic platform functions.Window: Window and Input implementation.Art: Colors and color related functions.Camera2D: Implementation for 2D camera.Code_Generation: Code generation module that powers all.cgenfiles.String_Builder: String builderCommand_Line: Command line parserFiles: File related functionsLexer: Lexer implementationTiming: Timing functions