diff --git a/examples/audio/audio_music_stream.cpp b/examples/audio/audio_music_stream.cpp new file mode 100644 index 0000000..86031fa --- /dev/null +++ b/examples/audio/audio_music_stream.cpp @@ -0,0 +1,84 @@ +/******************************************************************************************* +* +* raylib [audio] example - Music playing (streaming) +* +* This example has been created using raylib 1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 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 - music playing (streaming)"); + + raylib::AudioDevice audio(); // Initialize audio device + + raylib::Music music("resources/guitar_noodling.ogg"); + + music.Play(); + + float timePlayed = 0.0f; + bool pause = false; + + 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 + //---------------------------------------------------------------------------------- + music.Update(); // Update music buffer with new stream data + + // Restart music playing (stop and play) + if (IsKeyPressed(KEY_SPACE)) + { + music.Stop(); + music.Play(); + } + + // Pause/Resume music playing + if (IsKeyPressed(KEY_P)) + { + pause = !pause; + + if (pause) music.Pause(); + else music.Resume(); + } + + // Get timePlayed scaled to bar dimensions (400 pixels) + timePlayed = music.GetTimePlayed() / music.GetTimeLength() * 400; + + if (timePlayed > 400) music.Stop(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY); + + DrawRectangle(200, 200, 400, 12, LIGHTGRAY); + DrawRectangle(200, 200, (int)timePlayed, 12, MAROON); + DrawRectangleLines(200, 200, 400, 12, GRAY); + + DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY); + DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + return 0; +} diff --git a/examples/text/resources/custom_alagard.png b/examples/text/resources/custom_alagard.png new file mode 100644 index 0000000..6342655 Binary files /dev/null and b/examples/text/resources/custom_alagard.png differ diff --git a/examples/text/resources/custom_jupiter_crash.png b/examples/text/resources/custom_jupiter_crash.png new file mode 100644 index 0000000..2deaaef Binary files /dev/null and b/examples/text/resources/custom_jupiter_crash.png differ diff --git a/examples/text/resources/custom_mecha.png b/examples/text/resources/custom_mecha.png new file mode 100644 index 0000000..a8c9e06 Binary files /dev/null and b/examples/text/resources/custom_mecha.png differ diff --git a/examples/text/text_sprite_fonts.cpp b/examples/text/text_sprite_fonts.cpp new file mode 100644 index 0000000..28eb0b7 --- /dev/null +++ b/examples/text/text_sprite_fonts.cpp @@ -0,0 +1,69 @@ +/******************************************************************************************* +* +* raylib [text] example - Font loading and usage +* +* 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 + +#include "raylib/raylib.hpp" + +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + raylib::Window w(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage"); + + std::string msg1 = "THIS IS A custom SPRITE FONT..."; + std::string msg2 = "...and this is ANOTHER CUSTOM font..."; + std::string msg3 = "...and a THIRD one! GREAT! :D"; + + // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) + raylib::Font font1("resources/custom_mecha.png"); // Font loading + raylib::Font font2("resources/custom_alagard.png"); // Font loading + raylib::Font font3("resources/custom_jupiter_crash.png"); // Font loading + + raylib::Vector2 fontPosition1(screenWidth/2 - MeasureTextEx(font1, msg1, font1.baseSize, -3).x/2, + screenHeight/2 - font1.baseSize/2 - 80); + + raylib::Vector2 fontPosition2(screenWidth/2 - MeasureTextEx(font2, msg2, font2.baseSize, -2).x/2, + screenHeight/2 - font2.baseSize/2 - 10); + + raylib::Vector2 fontPosition3(screenWidth/2 - MeasureTextEx(font3, msg3, font3.baseSize, 2).x/2, + screenHeight/2 - font3.baseSize/2 + 50); + + 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 + //---------------------------------------------------------------------------------- + // TODO: Update variables here... + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + font1.DrawText(msg1, fontPosition1, font1.baseSize, -3); + font2.DrawText(msg2, fontPosition2, font2.baseSize, -2); + font3.DrawText(msg3, fontPosition3, font3.baseSize, 2); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + return 0; +} diff --git a/include/raylib/BoundingBox.hpp b/include/raylib/BoundingBox.hpp index 346b295..6a1d731 100644 --- a/include/raylib/BoundingBox.hpp +++ b/include/raylib/BoundingBox.hpp @@ -35,7 +35,7 @@ namespace raylib { return *this; } - void Draw(::Color color) { + void Draw(::Color color = WHITE) { DrawBoundingBox(*this, color); } diff --git a/include/raylib/Camera3D.hpp b/include/raylib/Camera3D.hpp index beed192..3a4c82d 100644 --- a/include/raylib/Camera3D.hpp +++ b/include/raylib/Camera3D.hpp @@ -80,6 +80,14 @@ namespace raylib { Vector2 GetWorldToScreen(::Vector3 position) { return ::GetWorldToScreen(position, *this); } + + void DrawBillboard(::Texture2D texture, ::Vector3 center, float size, ::Color tint = WHITE) { + ::DrawBillboard(*this, texture, center, size, tint); + } + + void DrawBillboard(Texture2D texture, Rectangle sourceRec, Vector3 center, float size, ::Color tint = WHITE) { + ::DrawBillboardRec(*this, texture, sourceRec, center, size, tint); + } }; typedef Camera3D Camera; diff --git a/include/raylib/Font.hpp b/include/raylib/Font.hpp index 7528a73..01d30de 100644 --- a/include/raylib/Font.hpp +++ b/include/raylib/Font.hpp @@ -65,10 +65,10 @@ namespace raylib { return *this; } - void DrawText(const std::string& text, ::Vector2 position, float fontSize, float spacing, ::Color tint) { + void DrawText(const std::string& text, ::Vector2 position, float fontSize, float spacing, ::Color tint = WHITE) { DrawTextEx(*this, text.c_str(), position, fontSize, spacing, tint); } - void DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing, bool wordWrap, ::Color tint) { + void DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing, bool wordWrap, ::Color tint = WHITE) { DrawTextRec(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint); } void DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, int selectStart, int selectLength, ::Color selectText, Color selectBack) { diff --git a/include/raylib/Material.hpp b/include/raylib/Material.hpp index 2303739..71825b9 100644 --- a/include/raylib/Material.hpp +++ b/include/raylib/Material.hpp @@ -42,7 +42,7 @@ namespace raylib { } void SetTexture(int mapType, ::Texture2D texture) { - SetMaterialTexture(this, mapType, texture); + ::SetMaterialTexture(this, mapType, texture); } }; diff --git a/include/raylib/ModelAnimation.hpp b/include/raylib/ModelAnimation.hpp index 9772f01..2bd5639 100644 --- a/include/raylib/ModelAnimation.hpp +++ b/include/raylib/ModelAnimation.hpp @@ -24,8 +24,8 @@ namespace raylib { } GETTERSETTER(int,BoneCount,boneCount) - GETTERSETTER(::BoneInfo,Bones,bones) - GETTERSETTER(int,FrameCount,FrameCount) + GETTERSETTER(::BoneInfo*,Bones,bones) + GETTERSETTER(int,FrameCount,frameCount) GETTERSETTER(Transform**,FramePoses,framePoses) ModelAnimation& operator=(const ::ModelAnimation& model) { diff --git a/include/raylib/raylib.hpp b/include/raylib/raylib.hpp index 2e373b5..35ac12d 100644 --- a/include/raylib/raylib.hpp +++ b/include/raylib/raylib.hpp @@ -12,11 +12,11 @@ #include "Image.hpp" #include "Material.hpp" #include "Mesh.hpp" -#include "Model.hpp" #include "ModelAnimation.hpp" +#include "Model.hpp" #include "Music.hpp" -#include "Ray.hpp" #include "RayHitInfo.hpp" +#include "Ray.hpp" #include "Rectangle.hpp" #include "RenderTexture2D.hpp" #include "Shader.hpp" diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt index acae485..b72138f 100644 --- a/projects/CMake/CMakeLists.txt +++ b/projects/CMake/CMakeLists.txt @@ -20,13 +20,13 @@ if (NOT raylib_FOUND) endif() endif() -find_package(raylib-cpp 2.0 QUIET) +find_package(raylib-cpp 0.1 QUIET) if (NOT raylib-cpp_FOUND) include(FetchContent) FetchContent_Declare( raylib-cpp GIT_REPOSITORY https://github.com/RobLoach/raylib-cpp.git - GIT_TAG de5e6184d043e9ae3e5a16836bc810b7485e95f2 + GIT_TAG cfa1c3715c0fbf20d9a7d7f66fc4f128216b57e4 ) FetchContent_GetProperties(raylib-cpp) if (NOT raylib-cpp_POPULATED) # Have we downloaded raylib yet? diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a3646a6..756a1a8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,11 +29,16 @@ macro(ADD_CATCH_TESTS executable) endmacro() find_package(Raylib) + set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CTEST_CUSTOM_TESTS_IGNORE pkg-config--static) + list(APPEND SOURCES catch.hpp raylib_test.cpp) list(APPEND LIBS raylib-cpp raylib) + add_executable(raylib_test ${SOURCES}) + target_link_libraries(raylib_test ${LIBS}) ADD_CATCH_TESTS(raylib_test)