GithubHelp home page GithubHelp logo

robloach / raylib-cpp Goto Github PK

View Code? Open in Web Editor NEW
588.0 10.0 76.0 12.6 MB

C++ Object Oriented Wrapper for raylib

Home Page: https://robloach.github.io/raylib-cpp/

License: zlib License

CMake 1.55% C++ 83.98% Makefile 6.58% C 7.90%
raylib

raylib-cpp's Introduction

raylib-cpp Logo

raylib-cpp Targeting raylib 5.0 Tests License

raylib-cpp is a C++ wrapper library for raylib, a simple and easy-to-use library to enjoy videogames programming. This C++ header provides object-oriented wrappers around raylib's struct interfaces. raylib-cpp is not required to use raylib in C++, but the classes do bring using the raylib API more inline with C++'s language paradigm.

Example

#include "raylib-cpp.hpp"

int main() {
    int screenWidth = 800;
    int screenHeight = 450;

    raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window");
    raylib::Texture logo("raylib_logo.png");

    SetTargetFPS(60);

    while (!window.ShouldClose())
    {
        BeginDrawing();

        window.ClearBackground(RAYWHITE);

        DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);

        // Object methods.
        logo.Draw(
            screenWidth / 2 - logo.GetWidth() / 2,
            screenHeight / 2 - logo.GetHeight() / 2);

        EndDrawing();
    }

    // UnloadTexture() and CloseWindow() are called automatically.

    return 0;
}

See the examples folder for more of the raylib examples that have been ported over to raylib-cpp.

Features

There are a few conventions that raylib-cpp takes on when adopting raylib. See the raylib-cpp documentation for details on the entire API.

Constructors

Object constructors load raylib objects.

// raylib
Texture2D texture = LoadTexture("texture.png");

// raylib-cpp
raylib::Texture2D texture("texture.png");

Object Methods

When a raylib method has an object as one of its arguments, you can call the method on the object itself.

// raylib
Vector2 position(50, 50);
DrawPixelV(position, PURPLE);

// raylib-cpp
raylib::Vector2 position(50, 50);
position.DrawPixel(PURPLE);

Method Names

If a method's name contains an object's name, it is removed from its name to shorten the method name.

// raylib
DrawTexture(texture, 50, 50, WHITE);

// raylib-cpp
texture.Draw(50, 50, WHITE);

Optional Parameters

Many methods have optional parameters with sane defaults.

// raylib
DrawTexture(texture, 50, 50, WHITE);

// raylib-cpp
texture.Draw(50, 50); // WHITE is provided as the default tint.

Object Destructors

Objects will attempt to unload their respective raylib resources on destruction. This means that there is no need to call Unload or Close methods. This applies to the window, textures, images, sounds, etc.

// raylib
InitWindow(640, 480, "Hello World");
CloseWindow();

// raylib-cpp
raylib::Window window(640, 480, "Hello World");
// window.Close() will be called automatically when the object is destructed.

Property Get/Set

Properties can be assigned through getter and setter methods. However, you still have access to the internal properties.

// raylib
Vector2 position;
position.x = 50;
position.y = 100;

// raylib-cpp
raylib::Vector2 position;
position.SetX(50);
position.SetY(100);

// ... or
position.x = 50;
position.y = 100;

Function Overloading

Many similar raylib method names have different name suffixes based on what arguments they take. With raylib-cpp, these cases use function overloading to allow using the same method names.

// raylib
Color color = GRAY;
DrawPixel(50, 50, color);
Vector2 position = {50.0f, 50.0f};
DrawPixelV(position, color); // Extra V in method name.

// raylib-cpp
raylib::Color color = raylib::Color::Gray();
color.DrawPixel(50, 50);
Vector2 position(50.0f, 50.0f);
color.DrawPixel(position); // No V in method name.
position.DrawPixel(color); // Alternatively

Method Chaining

When there's a method that doesn't return anything, in most cases it'll return the object itself, allowing method chaining.

// raylib
Image cat = ImageLoad("cat.png");
ImageCrop(&cat, (Rectangle){ 100, 10, 280, 380 });
ImageFlipHorizontal(&cat);
ImageResize(&cat, 150, 200);

// raylib-cpp
raylib::Image cat("cat.png");
cat.Crop(100, 10, 280, 380)
   .FlipHorizontal()
   .Resize(150, 200);

Operators

There are operator overloads implemented for objects.

// raylib
Vector2 position = {50, 50};
Vector2 speed = {10, 10};
position.x += speed.x;
position.y += speed.y;

// raylib-cpp
raylib::Vector2 position(50, 50);
raylib::Vector2 speed(10, 10);
position += speed; // Addition assignment operator override.

Vector-Based Returns

When there is a function that would return a pointer-array, there is a wrapper that allows returning a vector of objects instead.

// raylib
FilePathList files = LoadDirectoryFiles(".");
TraceLog(LOG_INFO, "Count: %i", files.count);
for (int i = 0; i < files.count; i++) {
    TraceLog(LOG_INFO, "File: %s", files.paths[i]);
}
UnloadDirectoryFiles(files);

// raylib-cpp
std::vector<std::string> files = raylib::GetDirectoryFiles(".");
TraceLog(LOG_INFO, "Count: %i", files.size());
for (auto& file : files) {
    TraceLog(LOG_INFO, "File: %s", file.c_str());
}

String Functions

Many of the raylib functions have std::string-related overrides to allow calling them directly with std::strings and avoid having to use the .c_str() method.

// raylib
const char* url = "https://raylib.com";
OpenURL(url);

// raylib-cpp
std::string url = "https://raylib.com";
raylib::OpenURL(url);

Exceptions

When loading an asset fails, raylib will log a warning, but provide no other feedback for you to act upon. raylib-cpp will throw a RaylibException runtime exception, allowing to provide a safe method for catching failed loads.

// raylib
Texture texture = LoadTexture("FileNotFound.png");
if (texture.width == 0) {
    TraceLog(LOG_ERROR, "Texture failed to load!");
}

// raylib-cpp
try {
    raylib::Texture texture("FileNotFound.png");
}
catch (raylib::RaylibException& error) {
    TraceLog(LOG_ERROR, "Texture failed to load!");
}

RayMath

The raymath methods are included.

// raylib
Vector2 direction = {50, 50};
Vector2 newDirection = Vector2Rotate(direction, 30);

// raylib-cpp
raylib::Vector2 direction(50, 50);
raylib::Vector2 newDirection = direction.Rotate(30);

Getting Started

raylib-cpp is a header-only library. This means in order to use it, you must link your project to raylib, and then include raylib-cpp.hpp.

  1. Set up a raylib project using the build and install instructions
  2. Ensure .cpp files are compiled with C++
  3. Download raylib-cpp
  4. Include include/raylib-cpp.hpp
    #include "path/to/raylib-cpp.hpp"

Starter Projects

The projects directory includes some starter templates...

If there's a project template you would like to see added, feel free to make an issue and we can add it in.

Applications

Development

The following are some tools in order to build and contribute to raylib-cpp...

Compiling

Since raylib-cpp is a header only library, the build process is the same as raylib's, except you will use C++ to compile instead of C. The following are some specific instructions on local development.

Desktop

raylib-cpp uses CMake as a primary target for development. To build it, and run the tests or examples, use...

git clone https://github.com/RobLoach/raylib-cpp.git
cd raylib-cpp
mkdir build
cd build
cmake ..
make
make test
./examples/core_basic_window

Web

Use emscripten to build and test core_basic_window_web.cpp.

mkdir build
cd build
emcmake cmake .. -DPLATFORM=Web -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-s USE_GLFW=3"
emmake make

See core_basic_window_web.html for an example HTML canvas you can you.

Documentation

To build the document with Doxygen, use...

git submodule update --init
doxygen projects/Doxygen/Doxyfile

To publish the documentation to GitHub Pages, use...

npm run deploy

Coding Standards

This uses cpplint to adopt coding standards.

cpplint --recursive include

Defines

  • RAYLIB_CPP_NO_MATH - When set, will skip adding the raymath.h integrations

License

raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check LICENSE for further details.

raylib-cpp's People

Contributors

arcod7 avatar aviloi avatar bensuperpc avatar bigfoot71 avatar bobthebadguy avatar crlimacastro avatar crystalix007 avatar dbrats avatar depau avatar dk949 avatar furudbat avatar jonjondev avatar knockerpulsar avatar kyomawolf avatar maciejewiczow avatar mahno9 avatar mbergerman avatar mojert avatar pineapplemachine avatar pkeir avatar plagakit avatar quentin-dev avatar raynei86 avatar robloach avatar sominator avatar swiderskis avatar tokyosu avatar ufrshubham avatar williamgrantuk avatar wmpowell8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raylib-cpp's Issues

Creating shared-library

By default when I run make it builds a static-library for the project. How one can create a shared library of the project?

Breaking changes

WARNING: BREAKING CHANGE on raylib!
Previous GetKeyPressed() method was actually returning unicode codepoints equivalent values instead of the key-code of the pressed key. So, it has been replaced by GetCharPressed(), returning unicode codepoints and GetKeyPressed() now returns key-codes.

WARNING! ANOTHER BREAKING CHANGE! GetImageData() renamed to LoadImageColors() to address an allocation/free issue.

CTestCustom.cmake does not exist

Hi, I'm trying to set up a project using the suggested cmake file.
I used the exact same one in projects/CMake (apart from trivial modifications like the project name) and I get the following error when I run cd build; cmake ..:

CMake Error: File /home/user/code/myproject/cmake/CTestCustom.cmake does not exist.
CMake Error at /tmp/cmakeCVUo5k/_deps/raylib-cpp-src/CMakeLists.txt:8 (configure_file):
  configure_file Problem configuring file


-- Configuring incomplete, errors occurred!
See also "/tmp/cmakeCVUo5k/CMakeFiles/CMakeOutput.log".
make: *** [Makefile:176: cmake_check_build_system] Error 1

It seems like CMAKE_SOURCE_DIR is set to my project's root directory instead of raylib-cpp's when this line runs:

configure_file(${CMAKE_SOURCE_DIR}/cmake/CTestCustom.cmake ${CMAKE_BINARY_DIR})

I'm not very experienced with cmake so I don't know too much beyond what I've shown here.

Initializer Member List

struct Vector2 {
  float x, y;
};

namespace raylib {
class Vector2 : public ::Vector2 {
        Vector2() : ::Vector2{5, 10} {}
};
}

Method Chaining

When a method returns void, return a reference to itself so that we can do method chaining...

raylib::Vector2 position(50, 50);
position.DrawPixel(PURPLE).DrawCircle(10.0f, BLUE);

Unable to make my raylib-cpp project into an apk

I've been trying to use the makefile to make my raylib-cpp projects into apk. I am currently stuck on trying to find out how fix this linker error. Does anyone have any solutions?

(Error Message Attached)
Capture

Update to const functions

Const functions denote functions that don't modify any of the member functions.

class Something
{
public:
    int m_value;
 
    Something(): m_value{0} { }
 
    void resetValue() { m_value = 0; }
    void setValue(int value) { m_value = value; }
 
    int getValue() const; // note addition of const keyword here
};
 
int Something::getValue() const // and here
{
    return m_value;
}

Need guide for newbie

Hello,

I'm absolutely new here.
I want to build my game with Visual Studio and raylib for cpp.
I glance at the library for C language and I found that it has a raylib.dll, raylib.lib and a header file (in the windows installer release) and I think it's enough to build and run the game.
So, what should I do with this to build my game with C++ language?
Thanks!

Make Errors on raylib-cpp

I just tried to clone the raylib-cpp repo and build it the way you described it in your readme.md.
However i get a bunch of errors in the make process.

I would really appreciate your help as your library seems quite promising.
Below are the errors thrown by the make process:

https://pastebin.pl/view/427e0018

Sharing my own projects built with raylib + raylib-cpp

@RobLoach Hi Rob, I heard from another issue thread that you are looking to expand the example projects. I organized a repo of a couple of small games I built with raylib + raylib-cpp here. Hope this helps some of the beginners when they try to adopt your awesome OOP wrapper and need more guidelines!

P.s. I'm most proud of my flappy_bird.cpp :) The README of my repo contains some screenshots of the gameplay as well!

Include Issues in multiple files.

Including "raylib-cpp.hpp" in multiple files with header guards causes multiple definition error.
I have a main.cpp which includes

#include "raylib-cpp.hpp"
#include "./Includes/ball.h"

and ball.h file:

#include "raylib-cpp.hpp"

I include the "raylib-cpp.hpp" in ball.h because I want access to the raylib namespace. It has header guards but still I get the error below:

https://pastebin.pl/view/2d1aaee9

My cmake file looks like this:

cmake_minimum_required(VERSION 3.11) # FetchContent is available in 3.11+
project(raylib-cpp-example)
# https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(GRAPHICS GRAPHICS_API_OPENGL_21)

# raylib
find_package(raylib 3.0.0 QUIET)
if (NOT raylib_FOUND)
    include(FetchContent)
    FetchContent_Declare(
      raylib
      GIT_REPOSITORY https://github.com/raysan5/raylib.git
      GIT_TAG f3091185ca7aed5effe4aa4da2ed0badb4186936
    )
    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)
      set(BUILD_GAMES    OFF CACHE BOOL "" FORCE)
      set(BUILD_TESTING  OFF CACHE BOOL "" FORCE)
      add_subdirectory(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR})
    endif()
endif()

# raylib-cpp
find_package(raylib-cpp 3.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 64df17e566aaa449196bfc34669b79b3a1f1d772
    )
    FetchContent_GetProperties(raylib-cpp)
    if (NOT raylib-cpp_POPULATED) # Have we downloaded raylib yet?
      set(FETCHCONTENT_QUIET NO)
      FetchContent_Populate(raylib-cpp)
      set(BUILD_RAYLIB_CPP_STATIC   OFF CACHE BOOL "" FORCE)
      set(BUILD_RAYLIB_CPP_EXAMPLES OFF CACHE BOOL "" FORCE)
      set(BUILD_TESTING             OFF CACHE BOOL "" FORCE)
      add_subdirectory(${raylib-cpp_SOURCE_DIR} ${raylib-cpp_BINARY_DIR})
    endif()
endif()

# This is the main part:
set(PROJECT_NAME Bounce)
file(GLOB PROJECT_SOURCES
    main.cpp
    Includes/*.cpp
    Includes/*.h
)
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
set(raylib_VERBOSE 1)
target_link_libraries(${PROJECT_NAME} PUBLIC raylib raylib-cpp)

# That's it! You should have an example executable that you can run. Have fun!

Am I doing something wrong here or is it something with the Color class?

CMake project not compiling

cmake .
-- Populating raylib-cpp
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-subbuild
[ 11%] Performing update step for 'raylib-cpp-populate'
[ 22%] No patch step for 'raylib-cpp-populate'
[ 33%] No configure step for 'raylib-cpp-populate'
[ 44%] No build step for 'raylib-cpp-populate'
[ 55%] No install step for 'raylib-cpp-populate'
[ 66%] No test step for 'raylib-cpp-populate'
[ 77%] Completed 'raylib-cpp-populate'
[100%] Built target raylib-cpp-populate
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake
make
[ 50%] Building CXX object CMakeFiles/raylib-cpp-example.dir/main.cpp.o
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/main.cpp:22:
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/raylib-cpp.hpp:63:
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Image.hpp:113:10: error: no member named
      'LoadImageAnim' in the global namespace
                        set(::LoadImageAnim(fileName.c_str(), frames));
                            ~~^
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Image.hpp:235:13: error: no member named
      'GetImagePalette' in the global namespace
                        return ::GetImagePalette(*this, maxPaletteSize, extractCount);
                               ~~^
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Image.hpp:298:84: error: too many arguments to
      function call, expected 5, have 6
                        ::ImageDrawText(this, text.c_str(), (int)position.x, (int)position.y, fontSize, color);
                        ~~~~~~~~~~~~~~~                                                                 ^~~~~
/usr/local/Cellar/raylib/3.0.0/include/raylib.h:1171:7: note: 'ImageDrawText' declared here
RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color);     // Draw text (defaul...
      ^
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/main.cpp:22:
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/raylib-cpp.hpp:63:
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Image.hpp:302:56: error: too many arguments to
      function call, expected 5, have 6
                        ::ImageDrawText(this, text.c_str(), x, y, fontSize, color);
                        ~~~~~~~~~~~~~~~                                     ^~~~~
/usr/local/Cellar/raylib/3.0.0/include/raylib.h:1171:7: note: 'ImageDrawText' declared here
RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color);     // Draw text (defaul...
      ^
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/main.cpp:22:
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/raylib-cpp.hpp:63:
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Image.hpp:306:28: error: no viable conversion
      from '::Font' (aka 'Font') to 'Vector2'
                        ::ImageDrawTextEx(this, font, text.c_str(), position, fontSize, spacing, tint);
                                                ^~~~
/usr/local/Cellar/raylib/3.0.0/include/raylib.h:174:16: note: candidate constructor (the implicit copy constructor) not viable: no
      known conversion from '::Font' (aka 'Font') to 'const Vector2 &' for 1st argument
typedef struct Vector2 {
               ^
/usr/local/Cellar/raylib/3.0.0/include/raylib.h:174:16: note: candidate constructor (the implicit move constructor) not viable: no
      known conversion from '::Font' (aka 'Font') to 'Vector2 &&' for 1st argument
/usr/local/Cellar/raylib/3.0.0/include/raylib.h:1172:48: note: passing argument to parameter 'position' here
RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text, float fontSize, float spacing, Color co...
                                               ^
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/main.cpp:22:
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/raylib-cpp.hpp:66:
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Mesh.hpp:91:6: error: no member named
      'MeshNormalsSmooth' in the global namespace
                        ::MeshNormalsSmooth(this);
                        ~~^
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/main.cpp:22:
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/raylib-cpp.hpp:70:
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Music.hpp:32:4: error: use of undeclared
      identifier 'looping'
                        looping = music.looping;
                        ^
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Music.hpp:32:20: error: no member named 'looping'
      in 'Music'
                        looping = music.looping;
                                  ~~~~~ ^
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Music.hpp:38:29: error: use of undeclared
      identifier 'looping'
                GETTERSETTER(bool,Looping,looping)
                                          ^
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Music.hpp:38:29: error: use of undeclared
      identifier 'looping'
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/main.cpp:22:
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/raylib-cpp.hpp:77:
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Texture2D.hpp:83:4: error: use of undeclared
      identifier 'UpdateTextureRec'
                        UpdateTextureRec(*this, rec, pixels);
                        ^
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Texture2D.hpp:146:6: error: no member named
      'DrawTextureTiled' in the global namespace
                        ::DrawTextureTiled(*this, sourceRec, destRec, origin, rotation, scale, tint);
                        ~~^
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/main.cpp:22:
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/raylib-cpp.hpp:83:
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Window.hpp:52:11: error: no member named
      'IsCursorOnScreen' in the global namespace; did you mean simply 'IsCursorOnScreen'?
                        return ::IsCursorOnScreen();
                               ^~~~~~~~~~~~~~~~~~
                               IsCursorOnScreen
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Window.hpp:51:15: note: 'IsCursorOnScreen'
      declared here
                inline bool IsCursorOnScreen() {
                            ^
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Window.hpp:65:13: error: no member named
      'IsWindowFocused' in the global namespace; did you mean 'IsWindowResized'?
                        return ::IsWindowFocused();
                               ~~^~~~~~~~~~~~~~~
                                 IsWindowResized
/usr/local/Cellar/raylib/3.0.0/include/raylib.h:877:12: note: 'IsWindowResized' declared here
RLAPI bool IsWindowResized(void);                                 // Check if window has been resized
           ^
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/main.cpp:22:
In file included from /Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/raylib-cpp.hpp:83:
/Users/mac/Downloads/raylib-cpp-3.0.0/projects/CMake/_deps/raylib-cpp-src/include/./Window.hpp:139:13: error: no member named
      'GetWindowScaleDPI' in the global namespace
                        return ::GetWindowScaleDPI();
                               ~~^
15 errors generated.
make[2]: *** [CMakeFiles/raylib-cpp-example.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/raylib-cpp-example.dir/all] Error 2
make: *** [all] Error 2

Changes to CMakeLists.txt

# set_property(TARGET tgt PROPERTY CXX_STANDARD 17)

set(CMAKE_CXX_FLAGS "-std=c++17")

set_property(TARGET tgt PROPERTY CXX_STANDARD 17) results in

CMake Error at CMakeLists.txt:45 (set_property):
  set_property could not find TARGET tgt.  Perhaps it has not yet been
  created.

Exceptions

Throw exceptions when loading assets is no worky.

Move Class Includes into a include sub-folder

Move the include/*.hpp files that include classes into a sub-folder from the include folder... Like include/raylib-cpp/Rectangle.hpp. This will help save from include conflicts.

Remove the static lib

This is a header-only library, so having a static build doesn't really make sense.

Operator Convertions

Put together operator overloads.......

For example:

Sound LoadSoundFromWave(Wave wave);

To allow for.....

Wave myWave("splash.wav");
Sound mySound = (Sound)myWave;

Raylib C++ Starter Project Template

Hi @RobLoach!

My name is Jonathan and I’ve been working with a mate recently to put together an automated template project for using the C++ bindings with just Make, keeping as much as possible statically linked (you can check it out here).

We built the project because we felt like it simplified the setup process, and makes using C++ with raylib far more accessible and understandable for newer devs. As such we thought that it may be of value to mention its existence in this repo, under the "starter projects” section.

If that's cool with you, let me know (if you want, I can throw a PR your way with the changes).

Sample project does not compile

I'm currently trying to compile the default project using your instructions, but keep getting errors like

/[...]/raylib-cpp/projects/CMake/build/_deps/raylib-cpp-src/include/./Image.hpp:113:10: error: ‘::LoadImageAnim’ has not been declared; did you mean ‘LoadImageRaw’?
  113 |    set(::LoadImageAnim(fileName.c_str(), frames));
      |          ^~~~~~~~~~~~~
      |          LoadImageRaw

Do you have any idea what I can do to fix it ?

no member named 'IsAudioBufferProcessed' in the global namespace

Reporting in case somebody else runs into the same problem when importing raylib.hpp.

error: no member named 'IsAudioBufferProcessed' in the global namespace; did you mean 'IsAudioStreamProcessed'?

This seems to be becauseIsAudioBufferProcessed was renamed toIsAudioStreamProcessed in August 2019. I guess the CPP bindings simply haven't been updated since then.

Inline variables in Color.hpp

lines 206 - 231 won't compile because they are declared as inline variables.
[Error] 'raylib::Color::DarkBlue' declared as an 'inline' variable
[Error] 'raylib::Color::Purple' declared as an 'inline' variable
etc.

Trouble Compiling

I'm using Raylib 3.0 on Windows 10 to run code very similar to examples/core/core_basic_window.cpp. This is the code:

#include "C:\raylib-cpp-master\include\raylib-cpp.hpp"

void UpdateDrawFrame(void);     // Update and Draw one frame

int main(void)
{
    const int screenWidth = 800;
    const int screenHeight = 450;
    
    raylib::Window w(screenWidth, screenHeight, "My first Window");
    SetTargetFPS(60);
    while (!w.ShouldClose())
    {
        UpdateDrawFrame();
    }
    return 0;
}

void UpdateDrawFrame(void)
{
    BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText("Hello World", 190, 200, 20, LIGHTGRAY);
    EndDrawing();
}

except I haven't been able to get that to compile. It complains about raymath.h missing. The output can be viewed here: https://pastebin.com/nCC9LNx4. So I go to the headers in the include folder and edit the raymath include statements to the path of my raylib/ src/raymath.h file. From:
#include "raymath.h" // NOLINT
to:
#include "C:\raylib\raylib\src\raymath.h" // NOLINT
But then I got a bunch of errors about undeclared functions: https://pastebin.com/LSL0eRfx. Note that I tried with release 3.0, 3.1, as well as the latest version from the master branch

Rescope raylib.h into raylib::impl namespace

Currently, the following code is included outside of namespace raylib, which pollutes the global namespace with raylib functions and types which can occasionally cause collisions. Is it possible to move this include into the raylib namespace? Many of the scope operators will have to be adjusted but I think this might result in some cleaner code. Also, I believe that the __cplusplus guards are not necessary when directly including a c header. I think this is typically used around C code that can be compiled by both a c & c++ compiler. The extern "C" is definitely still necessary though. Apologies if I am missing something.
https://isocpp.org/wiki/faq/mixing-c-and-cpp#include-c-hdrs-system

#ifdef __cplusplus
	extern "C" {
#endif
#include "raylib.h"
#ifdef __cplusplus
	}
#endif

Edit: extern "C" guards are in raylib.h already. It does not appear that it is necessary to include it in raylib-cpp

[Bug: Fix Provided!] DrawGradientV and DrawGradientH are BOTH calling ::DrawRectangleGradientH

As the names suggest, one is vertical gradient while the other is horizontal gradient. It seems to be a copy-paste oversight:

		inline Rectangle& DrawGradientV(::Color color1, ::Color color2){
			::DrawRectangleGradientH(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width), static_cast<int>(height), color1, color2);
			return *this;
		}
		inline Rectangle& DrawGradientH(::Color color1, ::Color color2) {
			::DrawRectangleGradientH(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width), static_cast<int>(height), color1, color2);
			return *this;
		}

DrawGradientV should call ::DrawRectangleGradientV instead. The parameter list remains unchanged, so it's a one-letter fix. Tested with success.

Tests with other compilers

Currently the CMakeLists.txt for the tests are not compatible with MSVC compiler options. It would be great to ensure testing is functional on Windows / other compilers if possible.

How to install raylib-cpp to standard paths like /usr/local/lib etc.

I am currently using your suggested approach #include "path/to/raylib-cpp.hpp", and it works fine so far. However, I'd love to install raylib-cpp to standard directories, usr/local/lib and /usr/local/include like the way I did it with raylib (reference: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux)

Is there a recommended way of doing so? I'm rather new to working with C/C++ and makefiles etc. but would love to learn more.

Btw, thanks for the effort, this OOP wrapper is very clean IMO and makes code looks so sleek!

Undeclared identifier "depthTexture"

In include/RenderTexture2D.hpp there are multiple references towards depthTexture. However, the RenderTexture2D struct has no such member. For your reference, this is the definition of raylib's RenderTexture2D struct:

// RenderTexture2D type, for texture rendering
typedef struct RenderTexture2D {
    unsigned int id;        // OpenGL Framebuffer Object (FBO) id
    Texture texture;      // Color buffer attachment texture
    Texture depth;        // Depth buffer attachment texture
} RenderTexture2D;

// RenderTexture type, same as RenderTexture2D
typedef RenderTexture2D RenderTexture;

Is it an inconsistency across different versions of raylib?

[Wave.hpp] Namings of Getter/Setters

In include/Wave.hpp, perhaps instead of

GETTERSETTER(unsigned int, X, sampleCount)
GETTERSETTER(unsigned int, Y, sampleRate)
GETTERSETTER(unsigned int, Z, sampleSize)
GETTERSETTER(unsigned int, W, channels)
GETTERSETTER(void *, Data, data)

You meant to do this?

GETTERSETTER(unsigned int, SampleCount, sampleCount)
GETTERSETTER(unsigned int, SampleRate, sampleRate)
GETTERSETTER(unsigned int, SampleSize, sampleSize)
GETTERSETTER(unsigned int, Channels, channels)
GETTERSETTER(void *, Data, data)

SIGABRT in Mesh::Unload() - MacOS,Apple Silicon M1

I have some code being virtually a port of the raylib "cubicmap" sample. When the program exits it experience a SIGABRT in Mesh::Unload().

I might have missed something, this is the core of the code:

raylib::Image imMap("resources/cubicmap.png");
raylib::Texture2D cubicmap(imMap);
raylib::Mesh mesh = raylib::Mesh::Cubicmap(imMap, (Vector3){ 1.0f, 1.0f, 1.0f });
raylib::Model model(mesh);
...

The original pure C ray lib example based code worked fine, on the other hand - not as much cleanup is done as is being done with the destructors being called.

Any help in tracing this down is appreciated

/Stephen

Several bugs

First,
Thank you so much for this CMake project!

I had to set these otherwise the projects did not compile:

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Now:

core_3d_camera_first_person.cpp
F:\Dropbox\Tech\production\ppc\raylib-cpp\examples\core\core_3d_camera_first_person.cpp(42): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data

And:

physics_demo.cpp
F:\Dropbox\Tech\production\ppc\raylib-cpp\vendor\raylib\src\physac.h(410): error C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax

And some more ...

Typo in the README example [Fix Provided!]

I was going through the README and noticed this typo against raylib-cpp's getter/setter methods and the declared variable. In particular, this line:

		// Object methods.
		logo.Draw(
			screenWidth / 2 - texture.getWidth() / 2,
			screenHeight / 2 - texture.getHeight() / 2);

should be changed to:

		// Object methods.
		logo.Draw(
			screenWidth / 2 - logo.GetWidth() / 2,
			screenHeight / 2 - logo.GetHeight() / 2);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.