From 88f5987dcf4be36d0ea8b6c3d32f33abe746f23a Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Wed, 12 Mar 2025 00:30:42 +0100 Subject: [PATCH] Added a little demo program. Refactored project. --- CMakeLists.txt | 2 +- game.cmake => game/CMakeLists.txt | 5 +++- game/include/debug.h | 7 ++++++ game/src/debug.cpp | 23 ++++++++++++++++++ game/src/main.cpp | 40 +++++++++++++++++++++++++++++++ src/main.cpp | 23 ------------------ 6 files changed, 75 insertions(+), 25 deletions(-) rename game.cmake => game/CMakeLists.txt (83%) create mode 100644 game/include/debug.h create mode 100644 game/src/debug.cpp create mode 100644 game/src/main.cpp delete mode 100644 src/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f02b1f7..c6afa19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,4 +13,4 @@ set(RAYLIB_VERSION 5.5) include(dependencies.cmake) # Game source file -include(game.cmake) \ No newline at end of file +add_subdirectory(game) \ No newline at end of file diff --git a/game.cmake b/game/CMakeLists.txt similarity index 83% rename from game.cmake rename to game/CMakeLists.txt index 9f8d3f2..af813ee 100644 --- a/game.cmake +++ b/game/CMakeLists.txt @@ -11,15 +11,18 @@ set(TARGET game) # Source files set(SOURCES "${PROJECT_SOURCE_DIR}/src") add_executable(${TARGET} + ${SOURCES}/debug.cpp ${SOURCES}/main.cpp ) # Include folders target_include_directories(${TARGET} PRIVATE "${PROJECT_SOURCE_DIR}/include") target_include_directories(${TARGET} PRIVATE "${raylib_INCLUDE_DIRS}") +target_include_directories(${TARGET} PRIVATE "${imgui_INCLUDE_DIRS}") +target_include_directories(${TARGET} PRIVATE "${rlImGui_INCLUDE_DIRS}") # Libraries -target_link_libraries(${TARGET} raylib) +target_link_libraries(${TARGET} raylib imgui rlimgui) # Compilation depending on the platform if(MSVC) diff --git a/game/include/debug.h b/game/include/debug.h new file mode 100644 index 0000000..82c59b3 --- /dev/null +++ b/game/include/debug.h @@ -0,0 +1,7 @@ +#ifndef _YOYO_CARD_DEBUG +#define _YOYO_CARD_DEBUG + +void debug_window(void); +void open_window(void); + +#endif //_YOYO_CARD_DEBUG \ No newline at end of file diff --git a/game/src/debug.cpp b/game/src/debug.cpp new file mode 100644 index 0000000..6de4c18 --- /dev/null +++ b/game/src/debug.cpp @@ -0,0 +1,23 @@ +#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) +#define _CRT_SECURE_NO_WARNINGS +#endif + +#include +#include + +bool _running = false; + +void debug_window(void) +{ + if (!_running) + return; + + ImGui::Begin("Hello, World!", &_running, ImGuiWindowFlags_NoCollapse); + ImGui::Text("Welcome to Dear ImGui!"); + ImGui::End(); +} + +void open_window(void) +{ + _running = true; +} \ No newline at end of file diff --git a/game/src/main.cpp b/game/src/main.cpp new file mode 100644 index 0000000..9938d39 --- /dev/null +++ b/game/src/main.cpp @@ -0,0 +1,40 @@ +#include +#include + +#include "debug.h" + +#if defined(_MSC_VER) && !defined(_DEBUG) +#define main WinMain +#endif + +int main() +{ + SetConfigFlags(FLAG_WINDOW_RESIZABLE); + InitWindow(800, 450, "hello world"); + //SetTargetFPS(60); + rlImGuiSetup(true); + + while (!WindowShouldClose()) + { + // Start Drawing + BeginDrawing(); + ClearBackground(RAYWHITE); + rlImGuiBegin(); + + // Logic + if(IsKeyPressed(KEY_F3)) + open_window(); + + debug_window(); + DrawText("Hello world from raylib! (Press F3 for debug!)", 190, 200, 20, LIGHTGRAY); + + // End Drawing + rlImGuiEnd(); + EndDrawing(); + } + + // Free memory + rlImGuiShutdown(); + CloseWindow(); + return 0; +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index b1382f9..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - -#if defined(_MSC_VER) && !defined(_DEBUG) -#define main WinMain -#endif - -int main(void) -{ - const int screenWidth = 800; - const int screenHeight = 450; - InitWindow(screenWidth, screenHeight, "raylib hello world"); - - SetTargetFPS(60); - while (!WindowShouldClose()) - { - BeginDrawing(); - ClearBackground(RAYWHITE); - DrawText("Hello world from raylib.", 190, 200, 20, LIGHTGRAY); - EndDrawing(); - } - CloseWindow(); - return 0; -} \ No newline at end of file