Initial commit

This commit is contained in:
Lunar-Archive
2025-12-21 13:26:32 -05:00
commit ecd2cce04c
17 changed files with 442 additions and 0 deletions

2
.clangd Normal file
View File

@@ -0,0 +1,2 @@
CompileFlags:
CompilationDatabase: "./build"

View File

@@ -0,0 +1,151 @@
name: CMake on multiple platforms
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
platform: Windows
artifact_name: windows
build_type: Release
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
platform: Linux
artifact_name: linux
build_type: Release
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
platform: MacOS
artifact_name: macos
build_type: Release
- os: ubuntu-latest
c_compiler: emcc
cpp_compiler: em++
platform: Web
artifact_name: web
build_type: Release
steps:
- uses: actions/checkout@v4
- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Install Linux Dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev vim-common
- name: Install MacOS Dependencies
if: runner.os == 'macOS'
run: |
brew install cmake
xcode-select --install || true
- name: Install Windows Dependencies
if: runner.os == 'Windows'
run: choco install vim -y
shell: pwsh
- name: Cache CMake files
uses: actions/cache@v4
with:
path: |
~/.cmake
${{ github.workspace }}/build/_deps
key: ${{ runner.os }}-cmake-${{ matrix.c_compiler }}-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}
restore-keys: |
${{ runner.os }}-cmake-${{ matrix.c_compiler }}-
${{ runner.os }}-cmake-
- name: Setup Emscripten
if: matrix.c_compiler == 'emcc'
uses: mymindstorm/setup-emsdk@v14
with:
version: latest
- name: Setup Web Build Environment
if: matrix.c_compiler == 'emcc'
run: |
mkdir -p ${{ steps.strings.outputs.build-output-dir }}/assets
# cp -r assets/* ${{ steps.strings.outputs.build-output-dir }}/assets/
- name: Configure CMake
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
${{ matrix.c_compiler == 'emcc' && '-DPLATFORM=Web' || '' }}
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }}
- name: Create Release ZIP (Windows)
if: matrix.platform == 'Windows'
run: |
cd build/${{ matrix.build_type }}
Compress-Archive -Path *.exe -DestinationPath ../../${{ matrix.artifact_name }}.zip
shell: pwsh
- name: Create Release ZIP (Web)
if: matrix.platform == 'Web'
run: |
cd build
zip -r ../${{ matrix.artifact_name }}.zip *.html *.js *.data *.wasm 2>/dev/null || true
shell: bash
- name: Create Release ZIP (Linux/macOS)
if: matrix.platform == 'Linux' || matrix.platform == 'MacOS'
run: |
mkdir -p release_files
cd build
# Copy executable files (excluding libraries and build artifacts)
for file in *; do
if [ -f "$file" ] && [ -x "$file" ]; then
case "$file" in
*.so|*.a|*.dylib|*.sh) ;;
*) cp "$file" ../release_files/ ;;
esac
fi
done
cd ../release_files
if [ -n "$(ls -A 2>/dev/null)" ]; then
zip ../${{ matrix.artifact_name }}.zip *
fi
shell: bash
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: ${{ matrix.artifact_name }}.zip

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
build*/*
.cache/*

51
CMakeLists.txt Normal file
View File

@@ -0,0 +1,51 @@
cmake_minimum_required(VERSION 3.11) # FetchContent is available in 3.11+
project(game C CXX)
# Generate compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Dependencies
find_package(raylib QUIET) # QUIET or REQUIRED
if(NOT raylib_FOUND) # If there's none, fetch and build raylib
include(FetchContent)
FetchContent_Declare(
raylib
DOWNLOAD_EXTRACT_TIMESTAMP OFF
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG master
)
FetchContent_GetProperties(raylib)
if(NOT raylib_POPULATED) # Have we downloaded raylib yet?
set(FETCHCONTENT_QUIET NO)
FetchContent_MakeAvailable(raylib)
endif()
endif()
# Our Project
add_executable(${PROJECT_NAME})
# Add source files
file(GLOB_RECURSE PROJECTSOURCES "src/*.c" "src/*.cpp")
target_sources(${PROJECT_NAME} PRIVATE ${PROJECTSOURCES})
# Include directories
target_include_directories(${PROJECT_NAME} PRIVATE
"data"
${raylib_INCLUDE_DIRS}
)
# Link libraries
target_link_libraries(${PROJECT_NAME} raylib)
# Web Configurations
if(${PLATFORM} STREQUAL "Web")
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s GL_ENABLE_GET_PROC_ADDRESS=1 -s SINGLE_FILE=1 --shell-file ${CMAKE_SOURCE_DIR}/src/minshell.html")
endif()
# macOS frameworks
if(APPLE)
target_link_libraries(${PROJECT_NAME} "-framework IOKit")
target_link_libraries(${PROJECT_NAME} "-framework Cocoa")
target_link_libraries(${PROJECT_NAME} "-framework OpenGL")
endif()

16
LICENSE Normal file
View File

@@ -0,0 +1,16 @@
Copyright (c) 2013-2023 Ramon Santamaria (@raysan5)
This software is provided "as-is", without any express or implied warranty. In no event
will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you
wrote the original software. If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented
as being the original software.
3. This notice may not be removed or altered from any source distribution.

3
README.md Normal file
View File

@@ -0,0 +1,3 @@
# RaylibTemplate
A template for making games with Raylib (with CMake)

BIN
assets/cube.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 B

11
data/cube.png.h Normal file
View File

@@ -0,0 +1,11 @@
unsigned char cube_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08,
0x08, 0x06, 0x00, 0x00, 0x00, 0xc4, 0x0f, 0xbe, 0x8b, 0x00, 0x00, 0x00,
0x2b, 0x49, 0x44, 0x41, 0x54, 0x18, 0x57, 0x63, 0x64, 0x60, 0x60, 0xf8,
0xcf, 0x80, 0x07, 0x30, 0x82, 0x14, 0xd4, 0x33, 0x30, 0x30, 0x34, 0x60,
0xc1, 0x20, 0x49, 0xb0, 0x02, 0x90, 0x11, 0xe8, 0x92, 0x20, 0xdc, 0x38,
0x98, 0x4c, 0x80, 0xfb, 0x09, 0x0b, 0x00, 0x00, 0x41, 0x79, 0x1d, 0x01,
0xd9, 0xf2, 0x1b, 0x87, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44,
0xae, 0x42, 0x60, 0x82, 0x00, 0x00};
unsigned int cube_png_len = 102;

7
src/consts.c Normal file
View File

@@ -0,0 +1,7 @@
#include "consts.h"
const int SCREEN_WIDTH = 320;
const int SCREEN_HEIGHT = 240;
const int WIN_WIDTH = 1280;
const int WIN_HEIGHT = 720;

5
src/consts.h Normal file
View File

@@ -0,0 +1,5 @@
extern const int SCREEN_WIDTH;
extern const int SCREEN_HEIGHT;
extern const int WIN_WIDTH;
extern const int WIN_HEIGHT;

14
src/draw.c Normal file
View File

@@ -0,0 +1,14 @@
#include "draw.h"
#include "main.h"
#include "raylib.h"
#include "raymath.h"
void Draw() {
ClearBackground(BLACK);
DrawCircleV((Vector2){160.0f, 120.0f}, 120.0f, WHITE);
BeginMode3D(cam);
{
DrawModel(cube, Vector3Zero(), 1.0f, WHITE);
}
EndMode3D();
}

1
src/draw.h Normal file
View File

@@ -0,0 +1 @@
extern void Draw();

86
src/main.c Normal file
View File

@@ -0,0 +1,86 @@
#include "main.h"
#include "consts.h"
#include "draw.h"
#include "raylib.h"
#include "raymath.h"
#include "update.h"
#include <math.h>
#include "../data/cube.png.h"
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
#endif
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
static void MainLoop();
RenderTexture2D target;
Image texImg;
Texture2D texture;
Camera3D cam;
Model cube;
int main(void) {
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
InitWindow(WIN_WIDTH, WIN_HEIGHT, "game");
SetTargetFPS(60);
SetExitKey(KEY_BACKSPACE);
target = LoadRenderTexture(SCREEN_WIDTH, SCREEN_HEIGHT);
SetTextureFilter(target.texture, TEXTURE_FILTER_POINT);
texImg = LoadImageFromMemory(".png", cube_png, cube_png_len);
texture = LoadTextureFromImage(texImg);
cam = (Camera3D){0};
cam.position = (Vector3){0.0f, 0.0f, sqrtf(3.0f)};
cam.target = (Vector3){0.0f, 0.0f, 0.0f};
cam.up = (Vector3){0.0f, 1.0f, 0.0f};
cam.fovy = 60.0f;
cam.projection = CAMERA_PERSPECTIVE;
cube = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
cube.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = texture;
#if defined(PLATFORM_WEB)
emscripten_set_main_loop(MainLoop, 0, 1);
#else
while (!WindowShouldClose())
MainLoop();
#endif
CloseWindow();
return 0;
}
static void MainLoop() {
int winWidth = GetScreenWidth(), winHeight = GetScreenHeight();
float scale =
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
Update();
BeginTextureMode(target);
{
Draw();
}
EndTextureMode();
BeginDrawing();
{
ClearBackground(BLACK);
DrawTexturePro(
target.texture,
(Rectangle){0.0f, 0.0f, (float)SCREEN_WIDTH, (float)-SCREEN_HEIGHT},
(Rectangle){(winWidth - ((float)SCREEN_WIDTH * scale)) * 0.5f,
(winHeight - ((float)SCREEN_HEIGHT * scale)) * 0.5f,
(float)SCREEN_WIDTH * scale, (float)SCREEN_HEIGHT * scale},
(Vector2){0, 0}, 0.0f, WHITE);
}
EndDrawing();
}

9
src/main.h Normal file
View File

@@ -0,0 +1,9 @@
#include "raylib.h"
extern RenderTexture2D target;
extern Image texImg;
extern Texture2D texture;
extern Camera3D cam;
extern Model cube;

72
src/minshell.html Normal file
View File

@@ -0,0 +1,72 @@
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
body {
margin: 0px;
overflow: hidden;
background-color: black;
}
canvas.emscripten {
border: 0px none;
background-color: black;
padding-left: 0;
padding-right: 0;
margin-left: auto;
margin-right: auto;
display: block;
}
</style>
<script type='text/javascript' src="https://cdn.jsdelivr.net/gh/eligrey/FileSaver.js/dist/FileSaver.min.js"> </script>
<script type='text/javascript'>
function saveFileFromMEMFSToDisk(memoryFSname, localFSname) // This can be called by C/C++ code
{
var isSafari = false; // Not supported, navigator.userAgent access is being restricted
//var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
var data = FS.readFile(memoryFSname);
var blob;
if (isSafari) blob = new Blob([data.buffer], {type: "application/octet-stream"});
else blob = new Blob([data.buffer], {type: "application/octet-binary"});
// NOTE: SaveAsDialog is a browser setting. For example, in Google Chrome,
// in Settings/Advanced/Downloads section you have a setting:
// 'Ask where to save each file before downloading' - which you can set true/false.
// If you enable this setting it would always ask you and bring the SaveAsDialog
saveAs(blob, localFSname);
}
</script>
</head>
<body>
<canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas>
<p id="output" />
<script>
var Module = {
print: (function () {
var element = document.getElementById('output');
if (element) element.value = ''; // clear browser cache
return function (text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);
if (element) {
element.value += text + "\n";
element.scrollTop = element.scrollHeight; // focus on bottom
}
};
})(),
canvas: (function () {
var canvas = document.getElementById('canvas');
return canvas;
})()
};
</script>
{{{ SCRIPT }}}
</body>
</html>

11
src/update.c Normal file
View File

@@ -0,0 +1,11 @@
#include "update.h"
#include "main.h"
#include "raylib.h"
#include "raymath.h"
void Update() {
cube.transform =
MatrixMultiply(MatrixRotateXYZ(Vector3Scale((Vector3){1.0f, 1.5f, 2.5f},
GetFrameTime())),
cube.transform);
}

1
src/update.h Normal file
View File

@@ -0,0 +1 @@
extern void Update();