7
0
mirror of https://gitlab.com/raylibtemplates/rt.git synced 2026-06-28 11:15:21 -04:00

Begin porting project to C++

It is not done yet, and will not build.
This commit is contained in:
maple
2025-11-05 00:15:29 +00:00
parent 425bdf147d
commit cace53901c
2 changed files with 31 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.11) # FetchContent is available in 3.11+ cmake_minimum_required(VERSION 3.11) # FetchContent is available in 3.11+
project(game) project(game C CXX)
# Generate compile_commands.json # Generate compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@@ -19,19 +19,34 @@ if(NOT raylib_FOUND) # If there's none, fetch and build raylib
FetchContent_MakeAvailable(raylib) FetchContent_MakeAvailable(raylib)
endif() endif()
endif() endif()
set(RAYLIB_CPP_VERSION "v5.5.0")
find_package(raylib_cpp QUIET) # QUIET or REQUIRED
if(NOT raylib_cpp_FOUND) # If there's none, fetch and build raylib
include(FetchContent)
FetchContent_Declare(
raylib_cpp
DOWNLOAD_EXTRACT_TIMESTAMP OFF
URL https://github.com/RobLoach/raylib-cpp/archive/refs/tags/${RAYLIB_CPP_VERSION}.tar.gz
)
FetchContent_GetProperties(raylib_cpp)
if(NOT raylib_cpp_POPULATED) # Have we downloaded raylib yet?
set(FETCHCONTENT_QUIET NO)
FetchContent_MakeAvailable(raylib_cpp)
endif()
endif()
# Our Project # Our Project
add_executable(${PROJECT_NAME}) add_executable(${PROJECT_NAME})
file(GLOB_RECURSE PROJECTSOURCES src/*.c) file(GLOB_RECURSE PROJECTSOURCES "src/*.c" "src/*.cpp")
target_sources(${PROJECT_NAME} PRIVATE ${PROJECTSOURCES}) target_sources(${PROJECT_NAME} PRIVATE ${PROJECTSOURCES})
file(GLOB_RECURSE PROJECTDATA data/*.h) file(GLOB_RECURSE PROJECTDATA data/*.h)
target_sources(${PROJECT_NAME} PRIVATE ${PROJECTDATA}) target_sources(${PROJECT_NAME} PRIVATE ${PROJECTDATA})
#set(raylib_VERBOSE 1) #set(raylib_VERBOSE 1)
target_link_libraries(${PROJECT_NAME} raylib) target_link_libraries(${PROJECT_NAME} raylib raylib_cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${raylib_INCLUDE_DIRS}) target_include_directories(${PROJECT_NAME} PRIVATE ${raylib_INCLUDE_DIRS} ${raylib_cpp_INCLUDE_DIRS})
# Web Configurations # Web Configurations
if(${PLATFORM} STREQUAL "Web") if(${PLATFORM} STREQUAL "Web")

View File

@@ -1,7 +1,5 @@
#include "raylib.h"
#include "raymath.h"
#include "../data/cube.png.h" #include "../data/cube.png.h"
#include <raylib-cpp.hpp>
#define SCREEN_WIDTH (320) #define SCREEN_WIDTH (320)
#define SCREEN_HEIGHT (240) #define SCREEN_HEIGHT (240)
@@ -10,26 +8,21 @@
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
int main(void) { int main(void) {
SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE | raylib::Window window(SCREEN_WIDTH, SCREEN_HEIGHT, "game",
FLAG_WINDOW_MAXIMIZED | FLAG_VSYNC_HINT); FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE |
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "game"); FLAG_WINDOW_MAXIMIZED | FLAG_VSYNC_HINT);
SetWindowMinSize(320, 240); window.SetMinSize({320, 240});
SetTargetFPS(60); window.SetTargetFPS(60);
RenderTexture2D target = LoadRenderTexture(SCREEN_WIDTH, SCREEN_HEIGHT); raylib::RenderTexture2D target(320, 240);
SetTextureFilter(target.texture, TEXTURE_FILTER_POINT);
Image image = target.GetTexture().SetFilter(TEXTURE_FILTER_POINT);
LoadImageFromMemory(".png", assets_cube_png, assets_cube_png_len);
Texture2D texture = LoadTextureFromImage(image); raylib::Image texImg(".png", assets_cube_png, assets_cube_png_len);
raylib::Texture2D texture(texImg);
Camera camera = {0}; raylib::Camera3D cam(raylib::Vector3::Zero(), raylib::Vector3::Zero(),
camera.position = (Vector3){0.0f, 0.0f, 5.0f}; {0.0f, 1.0f, 0.0f}, 60.0f, CAMERA_PERSPECTIVE);
camera.target = (Vector3){0.0f, 0.0f, 0.0f};
camera.up = (Vector3){0.0f, 1.0f, 0.0f};
camera.fovy = 60.0f;
camera.projection = CAMERA_PERSPECTIVE;
Model cube = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f)); Model cube = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
cube.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = texture; cube.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = texture;