Added a little demo program. Refactored project.

This commit is contained in:
Yohan Boujon 2025-03-12 00:30:42 +01:00
parent cc21e12738
commit 88f5987dcf
6 changed files with 75 additions and 25 deletions

View file

@ -13,4 +13,4 @@ set(RAYLIB_VERSION 5.5)
include(dependencies.cmake) include(dependencies.cmake)
# Game source file # Game source file
include(game.cmake) add_subdirectory(game)

View file

@ -11,15 +11,18 @@ set(TARGET game)
# Source files # Source files
set(SOURCES "${PROJECT_SOURCE_DIR}/src") set(SOURCES "${PROJECT_SOURCE_DIR}/src")
add_executable(${TARGET} add_executable(${TARGET}
${SOURCES}/debug.cpp
${SOURCES}/main.cpp ${SOURCES}/main.cpp
) )
# Include folders # Include folders
target_include_directories(${TARGET} PRIVATE "${PROJECT_SOURCE_DIR}/include") target_include_directories(${TARGET} PRIVATE "${PROJECT_SOURCE_DIR}/include")
target_include_directories(${TARGET} PRIVATE "${raylib_INCLUDE_DIRS}") 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 # Libraries
target_link_libraries(${TARGET} raylib) target_link_libraries(${TARGET} raylib imgui rlimgui)
# Compilation depending on the platform # Compilation depending on the platform
if(MSVC) if(MSVC)

7
game/include/debug.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef _YOYO_CARD_DEBUG
#define _YOYO_CARD_DEBUG
void debug_window(void);
void open_window(void);
#endif //_YOYO_CARD_DEBUG

23
game/src/debug.cpp Normal file
View file

@ -0,0 +1,23 @@
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <imgui.h>
#include <cmath>
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;
}

40
game/src/main.cpp Normal file
View file

@ -0,0 +1,40 @@
#include <raylib.h>
#include <rlImGui.h>
#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;
}

View file

@ -1,23 +0,0 @@
#include <raylib.h>
#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;
}