Add examples

This commit is contained in:
Rob Loach
2019-08-20 00:17:34 -04:00
parent cfa1c3715c
commit 89c180dfcb
13 changed files with 176 additions and 10 deletions

View File

@@ -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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -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 <string>
#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;
}

View File

@@ -35,7 +35,7 @@ namespace raylib {
return *this;
}
void Draw(::Color color) {
void Draw(::Color color = WHITE) {
DrawBoundingBox(*this, color);
}

View File

@@ -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;

View File

@@ -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) {

View File

@@ -42,7 +42,7 @@ namespace raylib {
}
void SetTexture(int mapType, ::Texture2D texture) {
SetMaterialTexture(this, mapType, texture);
::SetMaterialTexture(this, mapType, texture);
}
};

View File

@@ -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) {

View File

@@ -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"

View File

@@ -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?

View File

@@ -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)