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+
project(game)
project(game C CXX)
# Generate compile_commands.json
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)
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
add_executable(${PROJECT_NAME})
file(GLOB_RECURSE PROJECTSOURCES src/*.c)
file(GLOB_RECURSE PROJECTSOURCES "src/*.c" "src/*.cpp")
target_sources(${PROJECT_NAME} PRIVATE ${PROJECTSOURCES})
file(GLOB_RECURSE PROJECTDATA data/*.h)
target_sources(${PROJECT_NAME} PRIVATE ${PROJECTDATA})
#set(raylib_VERBOSE 1)
target_link_libraries(${PROJECT_NAME} raylib)
target_include_directories(${PROJECT_NAME} PRIVATE ${raylib_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} raylib raylib_cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${raylib_INCLUDE_DIRS} ${raylib_cpp_INCLUDE_DIRS})
# Web Configurations
if(${PLATFORM} STREQUAL "Web")

View File

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