commit 923787cf35b0337f274a224c2a6600c03bbcffac Author: sam Date: Mon Nov 18 21:50:41 2024 +1300 first commit diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..c17e64a --- /dev/null +++ b/.clang-format @@ -0,0 +1,25 @@ +BasedOnStyle: WebKit +IndentWidth: 4 +TabWidth: 4 +UseTab: Never +AlignConsecutiveDeclarations: false +AlignConsecutiveAssignments: false +AlignTrailingComments: true +ColumnLimit: 105 +BreakBeforeBraces: Attach +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortLambdasOnASingleLine: false +PointerAlignment: Left +SpaceBeforeParens: Never +SpacesInParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpaceAfterCStyleCast: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeSquareBrackets: false +SpacesBeforeTrailingComments: 2 +PenaltyBreakAssignment: 1000 +NamespaceIndentation: All + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f5a392a --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + +.cache +compile_commands.json diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..01c7f30 --- /dev/null +++ b/src/main.c @@ -0,0 +1,84 @@ +#include +#include +#include +#include + +int main(int argc, char** argv) { + if(SDL_Init(SDL_INIT_VIDEO) != 0) { + fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError()); + return -1; + } + + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 6); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + + SDL_Window* window = SDL_CreateWindow( + "brimstone", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL); + if(!window) { + fprintf(stderr, "Failed to create SDL window: %s\n", SDL_GetError()); + SDL_Quit(); + return -1; + } + + SDL_GLContext glContext = SDL_GL_CreateContext(window); + if(!glContext) { + fprintf(stderr, "Failed to create OpenGL context: %s\n", SDL_GetError()); + SDL_DestroyWindow(window); + SDL_Quit(); + return -1; + } + + if(!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress)) { + fprintf(stderr, "Failed to initialize Glad\n"); + SDL_GL_DeleteContext(glContext); + SDL_DestroyWindow(window); + SDL_Quit(); + return -1; + } + + float vertices[] = { -0.5f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f }; + + uint32_t vbo; + glCreateBuffers(1, &vbo); + glNamedBufferStorage(vbo, sizeof(vertices), vertices, GL_DYNAMIC_STORAGE_BIT); + + uint32_t vao; + glCreateVertexArrays(1, &vao); + + glVertexArrayVertexBuffer(vao, 0, vbo, 0, sizeof(float) * 3); + + glEnableVertexArrayAttrib(vao, 0); + glVertexArrayAttribFormat(vao, 0, 3, GL_FLOAT, GL_FALSE, 0); + glVertexArrayAttribBinding(vao, 0, 0); + + printf("Vendor: %s\n", glGetString(GL_VENDOR)); + printf("Renderer: %s\n", glGetString(GL_RENDERER)); + printf("Version: %s\n", glGetString(GL_VERSION)); + + bool running = true; + SDL_Event event; + while(running) { + while(SDL_PollEvent(&event)) { + if(event.type == SDL_QUIT) { + running = false; + } + } + + int w, h; + SDL_GetWindowSize(window, &w, &h); + glViewport(0, 0, w, h); + + glClearColor(0.0f, 0.5f, 1.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + SDL_GL_SwapWindow(window); + } + + SDL_GL_DeleteContext(glContext); + SDL_DestroyWindow(window); + SDL_Quit(); + + return 0; +} + diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..61fa7f2 --- /dev/null +++ b/xmake.lua @@ -0,0 +1,9 @@ +add_rules("mode.debug", "mode.release") + +add_requires("libsdl", { configs = { static = true } }) +add_requires("glad", { configs = { static = true, api = "gl=4.6", profile = "core" } }) + +target("brimstone") + set_kind("binary") + add_files("src/*.c") + add_packages("libsdl", "glad")