first commit

This commit is contained in:
sam 2024-11-18 21:50:41 +13:00
commit 923787cf35
4 changed files with 127 additions and 0 deletions

25
.clang-format Normal file
View file

@ -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

9
.gitignore vendored Normal file
View file

@ -0,0 +1,9 @@
# Xmake cache
.xmake/
build/
# MacOS Cache
.DS_Store
.cache
compile_commands.json

84
src/main.c Normal file
View file

@ -0,0 +1,84 @@
#include <SDL2/SDL.h>
#include <glad/glad.h>
#include <stdbool.h>
#include <stdio.h>
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;
}

9
xmake.lua Normal file
View file

@ -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")