init commit
This commit is contained in:
commit
6b979b4a86
9 changed files with 311 additions and 0 deletions
21
.clang-format
Normal file
21
.clang-format
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
BasedOnStyle: LLVM
|
||||
UseTab: ForIndentation
|
||||
IndentWidth: 8
|
||||
TabWidth: 8
|
||||
ContinuationIndentWidth: 8
|
||||
ColumnLimit: 80
|
||||
AlignConsecutiveDeclarations: AcrossComments
|
||||
AlignTrailingComments: true
|
||||
SpacesBeforeTrailingComments: 1
|
||||
PointerAlignment: Left
|
||||
SpaceBeforeParens: ControlStatements
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterStruct: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterControlStatement: false
|
||||
SortIncludes: true
|
||||
ReflowComments: true
|
||||
...
|
||||
21
.gitignore
vendored
Normal file
21
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
# have a top-level makefile
|
||||
# (will be overwritten by cmake .)
|
||||
#Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
CMakeUserPresets.json
|
||||
build/
|
||||
|
||||
.cache/
|
||||
scripts/glstri.c
|
||||
external/stb_image.h
|
||||
# do not track resources just yet
|
||||
res/
|
||||
8
.gitmodules
vendored
Normal file
8
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[submodule "external/cglm"]
|
||||
path = external/cglm
|
||||
url = https://github.com/recp/cglm
|
||||
branch = master
|
||||
[submodule "external/skr"]
|
||||
path = external/skr
|
||||
url = git@git.tavo.one:tavo/skr
|
||||
branch = main
|
||||
196
CMakeLists.txt
Normal file
196
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
project(carga-electrica C)
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
# set(CMAKE_C_EXTENSIONS OFF) # Change later after fixing errors
|
||||
set(CMAKE_C_STANDARD_REQUIRED True)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
set(BIN proyecto)
|
||||
|
||||
function(download_if_missing url output_path)
|
||||
if(NOT EXISTS ${output_path})
|
||||
message(STATUS "Downloading ${url} -> ${output_path}")
|
||||
file(DOWNLOAD
|
||||
${url}
|
||||
${output_path}
|
||||
SHOW_PROGRESS
|
||||
STATUS status
|
||||
LOG log
|
||||
)
|
||||
list(GET status 0 status_code)
|
||||
if(NOT status_code EQUAL 0)
|
||||
message(FATAL_ERROR "Failed to download ${url}:\n${log}")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Download external libraries
|
||||
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
||||
|
||||
download_if_missing(
|
||||
"https://raw.githubusercontent.com/nothings/stb/refs/heads/master/stb_image.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/external/stb_image.h"
|
||||
)
|
||||
|
||||
# Download external scripts
|
||||
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
|
||||
|
||||
download_if_missing(
|
||||
"https://raw.githubusercontent.com/Brady-Brandt/glstri/main/main.c"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/glstri.c"
|
||||
)
|
||||
|
||||
add_executable(glstri scripts/glstri.c)
|
||||
|
||||
# Find packages
|
||||
|
||||
# OpenGL
|
||||
set(OpenGL_GL_PREFERENCE GLVND) # "GLVND" Or "LEGACY"
|
||||
find_package(OpenGL REQUIRED)
|
||||
if (OPENGL_opengl_LIBRARY)
|
||||
set(OPENGL_LIB ${OPENGL_opengl_LIBRARY})
|
||||
elseif (OPENGL_gl_LIBRARY)
|
||||
message(STATUS "Using legacy OpenGL")
|
||||
set(OPENGL_LIB ${OPENGL_gl_LIBRARY})
|
||||
else()
|
||||
message(FATAL_ERROR "No suitable OpenGL library found.")
|
||||
endif()
|
||||
|
||||
# GLFW
|
||||
find_package(glfw3 REQUIRED)
|
||||
|
||||
# GLEW
|
||||
find_package(GLEW REQUIRED)
|
||||
|
||||
# Update submodules
|
||||
|
||||
find_package(Git QUIET)
|
||||
|
||||
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
|
||||
option(GIT_SUBMODULE "Check submodules during build" ON)
|
||||
if(GIT_SUBMODULE)
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
RESULT_VARIABLE GIT_SUBMOD_RESULT)
|
||||
if(NOT GIT_SUBMOD_RESULT EQUAL 0)
|
||||
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}. Please check out submodules.")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Submodule: cglm
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/cglm EXCLUDE_FROM_ALL)
|
||||
|
||||
# Submodule: skr
|
||||
add_library(skr INTERFACE)
|
||||
target_include_directories(skr INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/skr
|
||||
)
|
||||
|
||||
# Submodule: slog
|
||||
# add_library(slog INTERFACE)
|
||||
# target_include_directories(slog INTERFACE
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/external/slog
|
||||
# )
|
||||
|
||||
# Submodule: ini
|
||||
# add_library(ini INTERFACE)
|
||||
# target_include_directories(ini INTERFACE
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/external/ini/src
|
||||
# )
|
||||
|
||||
# Transpile GLSL into C
|
||||
|
||||
set(SHADER_DIR ${CMAKE_SOURCE_DIR}/main/shaders)
|
||||
set(GLSL_EXTS vert frag comp geom tesc tese)
|
||||
|
||||
foreach(ext ${GLSL_EXTS})
|
||||
file(GLOB SHADER_FILES ${SHADER_DIR}/*.${ext})
|
||||
|
||||
foreach(shader ${SHADER_FILES})
|
||||
get_filename_component(shader_name ${shader} NAME)
|
||||
get_filename_component(base_name ${shader} NAME_WE)
|
||||
|
||||
set(output_file ${SHADER_DIR}/${shader_name}.c)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${output_file}
|
||||
COMMAND $<TARGET_FILE:glstri> -s -v ${base_name}_${ext} ${shader} ${output_file}
|
||||
DEPENDS ${shader} glstri
|
||||
COMMENT "transpiling ${shader_name} -> ${output_file}"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
list(APPEND TRANSPILED_SHADERS ${output_file})
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
add_custom_target(transpile_shaders ALL DEPENDS ${TRANSPILED_SHADERS})
|
||||
|
||||
# Main program
|
||||
|
||||
add_executable(${BIN}
|
||||
main/main.c
|
||||
|
||||
# external/ini/src/ini.c
|
||||
)
|
||||
|
||||
target_include_directories(${BIN}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
external
|
||||
)
|
||||
|
||||
target_link_libraries(${BIN}
|
||||
PRIVATE
|
||||
m
|
||||
${OPENGL_LIB}
|
||||
glfw
|
||||
GLEW::GLEW
|
||||
cglm_headers
|
||||
skr
|
||||
# slog
|
||||
# ini
|
||||
)
|
||||
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
|
||||
target_compile_options(${BIN} PRIVATE
|
||||
$<$<CONFIG:Debug>:-g3 -O0 -Wall -Wextra -DDEBUG -fno-omit-frame-pointer -fsanitize=address,undefined>
|
||||
$<$<CONFIG:Release>:-O3 -g0 -DNDEBUG -ffunction-sections -fdata-sections -fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=>
|
||||
)
|
||||
|
||||
target_link_options(${BIN} PRIVATE
|
||||
$<$<CONFIG:Debug>:-fno-omit-frame-pointer -fsanitize=address,undefined>
|
||||
$<$<CONFIG:Release>:-Wl,--gc-sections>
|
||||
)
|
||||
|
||||
# Enable LTO in Release if supported
|
||||
option(ENABLE_LTO "Enable LTO in Release" ON)
|
||||
if(ENABLE_LTO)
|
||||
include(CheckIPOSupported)
|
||||
check_ipo_supported(RESULT ipo_ok OUTPUT ipo_err)
|
||||
if(ipo_ok)
|
||||
set_property(TARGET ${BIN} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
|
||||
else()
|
||||
target_compile_options(${BIN} PRIVATE $<$<CONFIG:Release>:-flto>)
|
||||
target_link_options(${BIN} PRIVATE $<$<CONFIG:Release>:-flto>)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Optionally strip symbols in Release
|
||||
option(STRIP_RELEASE "Strip symbols from Release binaries" ON)
|
||||
if(STRIP_RELEASE)
|
||||
if(CMAKE_STRIP)
|
||||
add_custom_command(TARGET ${BIN} POST_BUILD
|
||||
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${BIN}>
|
||||
)
|
||||
else()
|
||||
target_link_options(${BIN} PRIVATE $<$<CONFIG:Release>:-s>)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_dependencies(${BIN} transpile_shaders)
|
||||
22
Makefile
Normal file
22
Makefile
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
BUILD_DIR = build
|
||||
|
||||
.PHONY: all debug release clean run/debug run/release
|
||||
|
||||
all: debug
|
||||
|
||||
debug:
|
||||
cmake -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=Debug
|
||||
cmake --build $(BUILD_DIR)
|
||||
|
||||
release:
|
||||
cmake -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build $(BUILD_DIR)
|
||||
|
||||
run/debug: debug
|
||||
./$(BUILD_DIR)/proyecto
|
||||
|
||||
run/release: release
|
||||
./$(BUILD_DIR)/proyecto
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
5
README.md
Normal file
5
README.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Simulación de Cargas
|
||||
|
||||
## Dependencias para compilar
|
||||
|
||||
- Debian: `cmake pkg-config libglfw3-dev libglew-dev libassimp-dev`
|
||||
1
external/cglm
vendored
Submodule
1
external/cglm
vendored
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit a4602f2d5f1f275c02ef608ef27d4021572d9d6c
|
||||
1
external/skr
vendored
Submodule
1
external/skr
vendored
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 836aadb32cf5df09cfd0cae71767b9d09b695571
|
||||
36
main/main.c
Normal file
36
main/main.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <cglm/cglm.h>
|
||||
|
||||
#define SKR_BACKEND_API 0 // opengl
|
||||
#define SKR_BACKEND_WINDOW 0 // glfw
|
||||
#include <skr/skr.h>
|
||||
|
||||
int main(void) {
|
||||
SkrWindow window = {
|
||||
.Title = "Hello SKR",
|
||||
.Width = 800,
|
||||
.Height = 600,
|
||||
};
|
||||
|
||||
SkrState state = SkrInit(&window);
|
||||
if (!SKR_OK) {
|
||||
fprintf(stderr, "Failed to init window: %s\n", SKR_LAST_ERROR);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (glewInit() != GLEW_OK) {
|
||||
fprintf(stderr, "Failed to init GLEW\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (!SkrWindowShouldClose(&window)) {
|
||||
SkrRendererRender(&state);
|
||||
}
|
||||
|
||||
SkrFinalize(&state);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in a new issue