This commit is contained in:
Rob Loach
2019-08-10 14:53:47 -04:00
parent a7856d72f3
commit 14acffeb46
41 changed files with 677 additions and 81 deletions

View File

@@ -1,27 +1,34 @@
find_package(Raylib)
add_executable(core_basic_window core/core_basic_window.cpp)
target_link_libraries(core_basic_window raylib)
# Get the sources together
set(example_dirs audio core text textures)
set(example_sources)
set(example_resources)
add_executable(core_input_mouse core/core_input_mouse.cpp)
target_link_libraries(core_input_mouse raylib)
foreach(example_dir ${example_dirs})
file(GLOB sources ${example_dir}/*.cpp)
list(APPEND example_sources ${sources})
add_executable(textures_image_loading textures/textures_image_loading.cpp)
target_link_libraries(textures_image_loading raylib)
add_executable(textures_image_drawing textures/textures_image_drawing.cpp)
target_link_libraries(textures_image_drawing raylib)
configure_file(textures/resources/raylib_logo.png resources/cat.png COPYONLY)
configure_file(textures/resources/raylib_logo.png resources/custom_jupiter_crash.png COPYONLY)
configure_file(textures/resources/raylib_logo.png resources/parrots.png COPYONLY)
configure_file(textures/resources/raylib_logo.png resources/raylib_logo.png COPYONLY)
# Any any resources
file(GLOB resources ${example_dir}/resources/*)
list(APPEND example_resources ${resources})
endforeach()
add_executable(text_raylib_fonts text/text_raylib_fonts.cpp)
configure_file(text/resources/fonts/alagard.png resources/fonts/alagard.png COPYONLY)
configure_file(text/resources/fonts/alpha_beta.png resources/fonts/alpha_beta.png COPYONLY)
configure_file(text/resources/fonts/jupiter_crash.png resources/fonts/jupiter_crash.png COPYONLY)
configure_file(text/resources/fonts/mecha.png resources/fonts/mecha.png COPYONLY)
configure_file(text/resources/fonts/pixantiqua.png resources/fonts/pixantiqua.png COPYONLY)
configure_file(text/resources/fonts/pixelplay.png resources/fonts/pixelplay.png COPYONLY)
configure_file(text/resources/fonts/romulus.png resources/fonts/romulus.png COPYONLY)
configure_file(text/resources/fonts/setback.png resources/fonts/setback.png COPYONLY)
target_link_libraries(text_raylib_fonts raylib)
# Do each example
foreach(example_source ${example_sources})
# Create the basename for the example
get_filename_component(example_name ${example_source} NAME)
string(REPLACE ".cpp" "${OUTPUT_EXT}" example_name ${example_name})
# Setup the example
add_executable(${example_name} ${example_source})
target_link_libraries(${example_name} PUBLIC raylib-cpp raylib)
string(REGEX MATCH ".*/.*/" resources_dir ${example_source})
string(APPEND resources_dir "resources")
endforeach()
file(COPY ${example_resources} DESTINATION "resources/")

View File

@@ -0,0 +1,54 @@
/*******************************************************************************************
*
* raylib [audio] example - Sound loading and playing
*
* 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(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
raylib::Window w(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
raylib::AudioDevice audiodevice(); // Initialize audio device
raylib::Sound fxWav("resources/sound.wav"); // Load WAV audio file
raylib::Sound fxOgg("resources/tanatana.ogg"); // Load OGG audio file
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_SPACE)) fxWav.Play(); // Play WAV sound
if (IsKeyPressed(KEY_ENTER)) fxOgg.Play(); // Play OGG sound
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
return 0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -28,6 +28,7 @@ int main()
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);
@@ -45,13 +46,13 @@ int main()
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(background);
background.ClearBackground();
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
textColor.DrawText("Congrats! You created your first window!", 190, 200, 20);
EndDrawing();
//----------------------------------------------------------------------------------
}
return 0;
}
}

View File

@@ -21,7 +21,9 @@ int main()
raylib::Window w(screenWidth, screenHeight, "raylib [core] example - mouse input");
raylib::Vector2 ballPosition(-100.0f, -100.0f);
raylib::Color background(RAYWHITE);
raylib::Color ballColor(DARKBLUE);
raylib::Color textColor(DARKGRAY);
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//---------------------------------------------------------------------------------------
@@ -42,15 +44,15 @@ int main()
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
background.ClearBackground();
DrawCircleV(ballPosition, 40, ballColor);
ballPosition.DrawCircle(40, ballColor);
DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
textColor.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20);
EndDrawing();
//----------------------------------------------------------------------------------
}
return 0;
}
}

View File

@@ -0,0 +1,60 @@
/*******************************************************************************************
*
* raylib [core] example - Generate random values
*
* This example has been created using raylib 1.1 (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
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
raylib::Window w(screenWidth, screenHeight, "raylib [core] example - generate random values");
int framesCounter = 0; // Variable used to count frames
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
framesCounter++;
// Every two seconds (120 frames) a new random value is generated
if (((framesCounter/120)%2) == 1)
{
randValue = GetRandomValue(-8, 5);
framesCounter = 0;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON);
DrawText(FormatText("%i", randValue), 360, 180, 80, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
return 0;
}

View File

@@ -23,6 +23,8 @@ int main(void)
const int screenHeight = 450;
raylib::Window w(screenWidth, screenHeight, "raylib [textures] example - image drawing");
raylib::Color background(RAYWHITE);
raylib::Color darkGray(DARKGRAY);
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
raylib::Image cat("resources/cat.png"); // Load image in CPU memory (RAM)
@@ -63,13 +65,13 @@ int main(void)
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
background.ClearBackground();
texture.Draw(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, WHITE);
DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, texture.width, texture.height, DARKGRAY);
darkGray.DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, texture.width, texture.height);
DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, DARKGRAY);
DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, DARKGRAY);
darkGray.DrawText("We are drawing only one texture from various images composed!", 240, 350, 10);
darkGray.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10);
EndDrawing();
//----------------------------------------------------------------------------------