From 4e72f41c292afa5db893b382fe34d53104aaaa0c Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Mon, 19 Aug 2019 21:29:02 -0400 Subject: [PATCH] Add Project example --- projects/CMake/CMakeLists.txt | 46 ++++++++++++++++++++++ projects/CMake/core_basic_window.cpp | 58 ++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 projects/CMake/CMakeLists.txt create mode 100644 projects/CMake/core_basic_window.cpp diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt new file mode 100644 index 0000000..9b06981 --- /dev/null +++ b/projects/CMake/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.11) # FetchContent is available in 3.11+ +project(example) + +find_package(raylib 2.0 QUIET) +if (NOT raylib_FOUND) + include(FetchContent) + FetchContent_Declare( + raylib + GIT_REPOSITORY https://github.com/raysan5/raylib.git + GIT_TAG 6f2f09947f5456cefb3d91d3f667f4d72fa55be6 + ) + FetchContent_GetProperties(raylib) + if (NOT raylib_POPULATED) # Have we downloaded raylib yet? + set(FETCHCONTENT_QUIET NO) + FetchContent_Populate(raylib) + set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples + set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # or games + add_subdirectory(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR}) + endif() +endif() + +find_package(raylibcpp 2.0 QUIET) +if (NOT raylibcpp_FOUND) + include(FetchContent) + FetchContent_Declare( + raylibcpp + GIT_REPOSITORY https://github.com/RobLoach/raylib-cpp.git + GIT_TAG de5e6184d043e9ae3e5a16836bc810b7485e95f2 + ) + FetchContent_GetProperties(raylib) + if (NOT raylib_POPULATED) # Have we downloaded raylib yet? + set(FETCHCONTENT_QUIET NO) + FetchContent_Populate(raylib) + set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples + set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # or games + add_subdirectory(${raylibcpp_SOURCE_DIR} ${raylibcpp_BINARY_DIR}) + endif() +endif() + +# This is the main part: +set(PROJECT_NAME core_basic_window) +add_executable(${PROJECT_NAME} core_basic_window.cpp) +#set(raylib_VERBOSE 1) +target_link_libraries(${PROJECT_NAME} raylib) + +# That's it! You should have an example executable that you can run. Have fun! diff --git a/projects/CMake/core_basic_window.cpp b/projects/CMake/core_basic_window.cpp new file mode 100644 index 0000000..9a78f1f --- /dev/null +++ b/projects/CMake/core_basic_window.cpp @@ -0,0 +1,58 @@ +/******************************************************************************************* +* +* raylib [core] example - Basic window +* +* Welcome to raylib! +* +* To test examples, just press F6 and execute raylib_compile_execute script +* Note that compiled executable is placed in the same folder as .c file +* +* You can find all basic examples on C:\raylib\raylib\examples folder or +* raylib official webpage: www.raylib.com +* +* Enjoy using raylib. :) +* +* This example has been created using raylib 1.0 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib/raylib.hpp" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + raylib::Color background(RAYWHITE); + raylib::Color textColor(LIGHTGRAY); + raylib::Window w(screenWidth, screenHeight, "raylib [core] example - basic window"); + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!w.ShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + background.ClearBackground(); + + textColor.DrawText("Congrats! You created your first window!", 190, 200, 20); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + return 0; +}