diff --git a/README.md b/README.md index 9ba2eda..eb89aa1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ C++ wrapper library around [raylib](https://www.raylib.com/), a simple and easy-to-use library to enjoy videogames programming. -Provides object oriented wrappers around some of the struct interfaces, which saves you from having to worry about unloading the objects yourself. +Provides object-oriented wrappers around some of the struct interfaces. ## Example @@ -13,7 +13,9 @@ int main(int argc, char* argv[]) { int screenWidth = 800; int screenHeight = 450; - raylib::Window w(screenWidth, screenHeight, "raylib [core] example - basic window"); + + raylib::Window w(screenWidth, screenHeight, "raylib-cpp - basic window"); + raylib::Texture logo("raylib_logo.png"); SetTargetFPS(60); @@ -25,10 +27,12 @@ int main(int argc, char* argv[]) DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); + logo.Draw(screenWidth / 2 - texture.getWidth() / 2, screenHeight / 2 - texture.getHeight() / 2); + EndDrawing(); } - // No need to call CloseWindow(). + // UnloadTexture() and CloseWindow() are called automatically. return 0; } diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d75c99e..46f199c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -14,7 +14,6 @@ foreach(example_dir ${example_dirs}) list(APPEND example_resources ${resources}) endforeach() - # Do each example foreach(example_source ${example_sources}) # Create the basename for the example diff --git a/examples/textures/textures_image_drawing.cpp b/examples/textures/textures_image_drawing.cpp index bdae00b..5e86c7a 100644 --- a/examples/textures/textures_image_drawing.cpp +++ b/examples/textures/textures_image_drawing.cpp @@ -35,8 +35,7 @@ int main(void) // Draw one image over the other with a scaling of 1.5f parrots.Draw(cat, raylib::Rectangle(0, 0, cat.width, cat.height), - raylib::Rectangle(30, 40, cat.width*1.5f, cat.height*1.5f), - WHITE); + raylib::Rectangle(30, 40, cat.width*1.5f, cat.height*1.5f)); parrots.Crop(raylib::Rectangle(0, 50, parrots.width, parrots.height - 100)); // Crop resulting image @@ -44,7 +43,7 @@ int main(void) raylib::Font font("resources/custom_jupiter_crash.png"); // Draw over image using custom font - parrots.DrawTextEx(raylib::Vector2(300, 230), font, "PARROTS & CAT", font.baseSize, -2, WHITE); + parrots.DrawText(raylib::Vector2(300, 230), font, "PARROTS & CAT", font.baseSize, -2); raylib::Texture2D texture(parrots); // Image converted to texture, uploaded to GPU memory (VRAM) @@ -65,7 +64,7 @@ int main(void) background.ClearBackground(); - texture.Draw(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, WHITE); + texture.Draw(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40); darkGray.DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, texture.width, texture.height); darkGray.DrawText("We are drawing only one texture from various images composed!", 240, 350, 10); diff --git a/examples/textures/textures_image_loading.cpp b/examples/textures/textures_image_loading.cpp index bfdb61c..2792bbd 100644 --- a/examples/textures/textures_image_loading.cpp +++ b/examples/textures/textures_image_loading.cpp @@ -22,6 +22,8 @@ int main() raylib::Window w(screenWidth, screenHeight, "raylib [textures] example - image loading"); raylib::Texture texture("resources/raylib_logo.png"); + raylib::Color background(RAYWHITE); + raylib::Color textColor(LIGHTGRAY); // Main game loop while (!w.ShouldClose()) // Detect window close button or ESC key @@ -35,11 +37,11 @@ int main() //---------------------------------------------------------------------------------- BeginDrawing(); - ClearBackground(RAYWHITE); + background.ClearBackground(); texture.Draw(screenWidth / 2 - texture.getWidth() / 2, screenHeight / 2 - texture.getHeight() / 2); - DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY); + textColor.DrawText("this IS a texture loaded from an image!", 300, 370, 10); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/include/raylib/Image.hpp b/include/raylib/Image.hpp index 4c20e4d..0bd9349 100644 --- a/include/raylib/Image.hpp +++ b/include/raylib/Image.hpp @@ -85,19 +85,19 @@ namespace raylib { void Resize(int newWidth, int newHeight){ ImageResize(this, newWidth, newHeight); } - void Draw(::Image& src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint){ + void Draw(::Image& src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint = WHITE){ ImageDraw(this, src, srcRec, dstRec, tint); } - void DrawRectangle(::Rectangle rec, ::Color color){ + void DrawRectangle(::Rectangle rec, ::Color color = WHITE){ ImageDrawRectangle(this, rec, color); } - void DrawRectangleLines(::Rectangle rec, int thick, ::Color color){ + void DrawRectangleLines(::Rectangle rec, int thick, ::Color color = WHITE){ ImageDrawRectangleLines(this, rec, thick, color); } - void DrawText(::Vector2 position, const std::string& text, int fontSize, ::Color color){ + void DrawText(::Vector2 position, const std::string& text, int fontSize, ::Color color = WHITE){ ImageDrawText(this, position, text.c_str(), fontSize, color); } - void DrawTextEx(::Vector2 position, ::Font font, const std::string& text, float fontSize, float spacing, ::Color color){ + void DrawText(::Vector2 position, ::Font font, const std::string& text, float fontSize, float spacing, ::Color color = WHITE){ ImageDrawTextEx(this, position, font, text.c_str(), fontSize, spacing, color); } void FlipVertical() { diff --git a/include/raylib/Shader.hpp b/include/raylib/Shader.hpp index a905677..6ca890a 100644 --- a/include/raylib/Shader.hpp +++ b/include/raylib/Shader.hpp @@ -1,5 +1,5 @@ -#ifndef RAYLIB_CPP_VECTOR4_HPP_ -#define RAYLIB_CPP_VECTOR4_HPP_ +#ifndef RAYLIB_CPP_SHADER_HPP_ +#define RAYLIB_CPP_SHADER_HPP_ #include "raylib.h" #include "utils.hpp" @@ -25,7 +25,7 @@ namespace raylib { locs = shader.locs; } - GETTERSETTER(unsigned int,Id,i) + GETTERSETTER(unsigned int,Id,id) Shader& operator=(const ::Shader& shader) { set(shader); @@ -42,22 +42,24 @@ namespace raylib { } void Unload() { - UnloadShader(*this); + ::UnloadShader(*this); } static Shader Load(const std::string& vsFileName, const std::string& fsFileName) { - return LoadShader(vsFileName.c_str(), fsFileName.c_str()); + return ::LoadShader(vsFileName.c_str(), fsFileName.c_str()); } static Shader LoadCode(const std::string& vsCode, const std::string& fsCode) { - return LoadShaderCode(vsCode.c_str(), fsCode.c_str()); + char* param1 = (char*)vsCode.c_str(); + char* param2 = (char*)fsCode.c_str(); + return ::LoadShaderCode(param1, param2); } void BeginShaderMode() { - BeginShaderMode(*this); + ::BeginShaderMode(*this); } void EndShaderMode() { - EndShaderMode(); + ::EndShaderMode(); } int GetLocation(const std::string& uniformName) { diff --git a/include/raylib/Texture2D.hpp b/include/raylib/Texture2D.hpp index 7763f3e..ae9af07 100644 --- a/include/raylib/Texture2D.hpp +++ b/include/raylib/Texture2D.hpp @@ -58,23 +58,23 @@ namespace raylib { DrawTexture(*this, posX, posY, tint); } - void Draw(::Vector2 position, ::Color tint) { + void Draw(::Vector2 position, ::Color tint = WHITE) { DrawTextureV(*this, position, tint); } - void Draw(::Vector2 position, float rotation, float scale, ::Color tint) { + void Draw(::Vector2 position, float rotation, float scale = 1.0f, ::Color tint = WHITE) { DrawTextureEx(*this, position, rotation, scale, tint); } - void Draw(::Rectangle sourceRec, ::Vector2 position, ::Color tint) { + void Draw(::Rectangle sourceRec, ::Vector2 position, ::Color tint = WHITE) { DrawTextureRec(*this, sourceRec, position, tint); } - void Draw(::Vector2 tiling, ::Vector2 offset, ::Rectangle quad, ::Color tint) { + void Draw(::Vector2 tiling, ::Vector2 offset, ::Rectangle quad, ::Color tint = WHITE) { DrawTextureQuad(*this, tiling, offset, quad, tint); } - void Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin, float rotation, ::Color tint) { + void Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin, float rotation = 0, ::Color tint = WHITE) { DrawTexturePro(*this, sourceRec, destRec, origin, rotation, tint); } - void Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin, float rotation, ::Color tint) { + void Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin, float rotation = 0, ::Color tint = WHITE) { DrawTextureNPatch(*this, nPatchInfo, destRec, origin, rotation, tint); } diff --git a/include/raylib/raylib.hpp b/include/raylib/raylib.hpp index 2ae3f8a..9b8211e 100644 --- a/include/raylib/raylib.hpp +++ b/include/raylib/raylib.hpp @@ -12,6 +12,7 @@ #include "Image.hpp" #include "Material.hpp" #include "Mesh.hpp" +#include "Model.hpp" #include "Music.hpp" #include "Ray.hpp" #include "RayHitInfo.hpp" diff --git a/include/raylib/utils.hpp b/include/raylib/utils.hpp index ed1f1fc..2ec35ae 100644 --- a/include/raylib/utils.hpp +++ b/include/raylib/utils.hpp @@ -3,8 +3,8 @@ #ifndef GETTERSETTER #define GETTERSETTER(type, method, name) \ - type get##method() { return name;} \ - void set##method(type value) { name = value; } + inline type get##method() { return name;} \ + inline void set##method(type value) { name = value; } #endif -#endif \ No newline at end of file +#endif