Added raylib-cpp header files to my project

This commit is contained in:
2024-01-31 21:01:35 -05:00
parent c83b347620
commit e6f328ea1d
38 changed files with 7356 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
#ifndef RAYLIB_CPP_INCLUDE_AUDIODEVICE_HPP_
#define RAYLIB_CPP_INCLUDE_AUDIODEVICE_HPP_
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./RaylibException.hpp"
namespace raylib {
/**
* Audio device management functions.
*/
class AudioDevice {
public:
/**
* Initialize audio device and context.
*
* @param lateInit Whether or not to post-pone initializing the context.
*
* @throws raylib::RaylibException Throws if the AudioDevice failed to initialize.
*/
AudioDevice(bool lateInit = false) {
if (!lateInit) {
Init();
}
}
/**
* Close the audio device and context.
*/
~AudioDevice() {
Close();
}
/**
* Initialize audio device and context.
*
* @throws raylib::RaylibException Throws if the AudioDevice failed to initialize.
*/
inline void Init() {
::InitAudioDevice();
if (!IsReady()) {
throw RaylibException("Failed to initialize AudioDevice");
}
}
/**
* Close the audio device and context.
*/
inline void Close() {
::CloseAudioDevice();
}
/**
* Check if audio device has been initialized successfully.
*/
inline bool IsReady() const {
return ::IsAudioDeviceReady();
}
/**
* Set master volume (listener).
*
* @param volume The desired volume to set.
*/
inline AudioDevice& SetVolume(float volume) {
::SetMasterVolume(volume);
return *this;
}
};
} // namespace raylib
using RAudioDevice = raylib::AudioDevice;
#endif // RAYLIB_CPP_INCLUDE_AUDIODEVICE_HPP_

View File

@@ -0,0 +1,227 @@
#ifndef RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_
#define RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./RaylibException.hpp"
namespace raylib {
/**
* AudioStream management functions
*/
class AudioStream : public ::AudioStream {
public:
AudioStream(const ::AudioStream& music) {
set(music);
}
AudioStream(rAudioBuffer* buffer = nullptr,
rAudioProcessor *processor = nullptr,
unsigned int sampleRate = 0,
unsigned int sampleSize = 0,
unsigned int channels = 0) : ::AudioStream{buffer, processor, sampleRate, sampleSize, channels} {
// Nothing.
}
/**
* Init audio stream (to stream raw audio pcm data)
*
* @throws raylib::RaylibException Throws if the AudioStream failed to load.
*/
AudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels = 2) {
Load(sampleRate, sampleSize, channels);
}
AudioStream(const AudioStream&) = delete;
AudioStream(AudioStream&& other) {
set(other);
other.buffer = nullptr;
other.processor = nullptr;
other.sampleRate = 0;
other.sampleSize = 0;
other.channels = 0;
}
~AudioStream() {
Unload();
}
GETTERSETTER(rAudioBuffer *, Buffer, buffer)
GETTERSETTER(rAudioProcessor *, Processor, processor)
GETTERSETTER(unsigned int, SampleRate, sampleRate)
GETTERSETTER(unsigned int, SampleSize, sampleSize)
GETTERSETTER(unsigned int, Channels, channels)
AudioStream& operator=(const ::AudioStream& stream) {
set(stream);
return *this;
}
AudioStream& operator=(const AudioStream&) = delete;
AudioStream& operator=(AudioStream&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.buffer = nullptr;
other.processor = nullptr;
other.sampleRate = 0;
other.sampleSize = 0;
other.channels = 0;
return *this;
}
/**
* Update audio stream buffers with data
*/
inline AudioStream& Update(const void *data, int samplesCount) {
::UpdateAudioStream(*this, data, samplesCount);
return *this;
}
/**
* Unload audio stream and free memory
*/
inline void Unload() {
::UnloadAudioStream(*this);
}
/**
* Check if any audio stream buffers requires refill
*/
inline bool IsProcessed() const {
return ::IsAudioStreamProcessed(*this);
}
/**
* Play audio stream
*/
inline AudioStream& Play() {
::PlayAudioStream(*this);
return *this;
}
/**
* Pause audio stream
*/
inline AudioStream& Pause() {
::PauseAudioStream(*this);
return *this;
}
/**
* Resume audio stream
*/
inline AudioStream& Resume() {
::ResumeAudioStream(*this);
return *this;
}
/**
* Check if audio stream is playing
*/
inline bool IsPlaying() const {
return ::IsAudioStreamPlaying(*this);
}
/**
* Stop audio stream
*/
inline AudioStream& Stop() {
::StopAudioStream(*this);
return *this;
}
/**
* Set volume for audio stream (1.0 is max level)
*/
inline AudioStream& SetVolume(float volume = 1.0f) {
::SetAudioStreamVolume(*this, volume);
return *this;
}
/**
* Set pitch for audio stream (1.0 is base level)
*/
inline AudioStream& SetPitch(float pitch) {
::SetAudioStreamPitch(*this, pitch);
return *this;
}
/**
* Set pan for audio stream (0.5 is centered)
*/
inline AudioStream& SetPan(float pan = 0.5f) {
::SetAudioStreamPitch(*this, pan);
return *this;
}
/**
* Default size for new audio streams
*/
inline static void SetBufferSizeDefault(int size) {
::SetAudioStreamBufferSizeDefault(size);
}
/**
* Audio thread callback to request new data
*/
inline void SetCallback(::AudioCallback callback) {
::SetAudioStreamCallback(*this, callback);
}
/**
* Attach audio stream processor to stream
*/
inline void AttachProcessor(::AudioCallback processor) {
::SetAudioStreamCallback(*this, processor);
}
/**
* Detach audio stream processor from stream
*/
inline void DetachProcessor(::AudioCallback processor) {
::SetAudioStreamCallback(*this, processor);
}
/**
* Retrieve whether or not the audio stream is ready.
*/
bool IsReady() const {
return ::IsAudioStreamReady(*this);
}
/**
* Load audio stream (to stream raw audio pcm data)
*
* @throws raylib::RaylibException Throws if the AudioStream failed to load.
*/
void Load(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels = 2) {
Unload();
set(::LoadAudioStream(SampleRate, SampleSize, Channels));
if (!IsReady()) {
throw RaylibException("Failed to load audio stream");
}
}
protected:
void set(const ::AudioStream& stream) {
buffer = stream.buffer;
processor = stream.processor;
sampleRate = stream.sampleRate;
sampleSize = stream.sampleSize;
channels = stream.channels;
}
};
} // namespace raylib
using RAudioStream = raylib::AudioStream;
#endif // RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_

View File

@@ -0,0 +1,87 @@
#ifndef RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_
#define RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* Bounding box type
*/
class BoundingBox : public ::BoundingBox {
public:
/*
* Copy a bounding box from another bounding box.
*/
BoundingBox(const ::BoundingBox& box) : ::BoundingBox{box.min, box.max} {
// Nothing.
}
/**
* Compute mesh bounding box limits
*/
BoundingBox(const ::Mesh& mesh) {
set(::GetMeshBoundingBox(mesh));
}
BoundingBox(::Vector3 minMax = ::Vector3{0.0f, 0.0f, 0.0f}) : ::BoundingBox{minMax, minMax} {}
BoundingBox(::Vector3 min, ::Vector3 max) : ::BoundingBox{min, max} {}
GETTERSETTER(::Vector3, Min, min)
GETTERSETTER(::Vector3, Max, max)
BoundingBox& operator=(const ::BoundingBox& box) {
set(box);
return *this;
}
/**
* Draw a bounding box with wires
*/
inline void Draw(::Color color = {255, 255, 255, 255}) const {
::DrawBoundingBox(*this, color);
}
/**
* Detect collision between two boxes
*/
inline bool CheckCollision(const ::BoundingBox& box2) const {
return CheckCollisionBoxes(*this, box2);
}
/**
* Detect collision between box and sphere
*/
inline bool CheckCollision(::Vector3 center, float radius) const {
return CheckCollisionBoxSphere(*this, center, radius);
}
/**
* Detect collision between ray and bounding box
*/
inline bool CheckCollision(const ::Ray& ray) const {
return GetRayCollisionBox(ray, *this).hit;
}
/**
* Get collision information between ray and bounding box
*/
inline RayCollision GetCollision(const ::Ray& ray) const {
return GetRayCollisionBox(ray, *this);
}
protected:
void set(const ::BoundingBox& box) {
min = box.min;
max = box.max;
}
void set(const ::Vector3& _min, const ::Vector3& _max) {
min = _min;
max = _max;
}
};
} // namespace raylib
using RBoundingBox = raylib::BoundingBox;
#endif // RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_

View File

@@ -0,0 +1,75 @@
#ifndef RAYLIB_CPP_INCLUDE_CAMERA2D_HPP_
#define RAYLIB_CPP_INCLUDE_CAMERA2D_HPP_
#include "./raylib.hpp"
#include "./Vector2.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* Camera2D type, defines a 2d camera
*/
class Camera2D : public ::Camera2D {
public:
Camera2D(const ::Camera2D& camera) {
set(camera);
}
Camera2D() {}
Camera2D(::Vector2 offset, ::Vector2 target,
float rotation = 0.0f, float zoom = 1.0f) : ::Camera2D{offset, target, rotation, zoom} {}
inline Camera2D& BeginMode() {
::BeginMode2D(*this);
return *this;
}
inline Camera2D& EndMode() {
::EndMode2D();
return *this;
}
GETTERSETTER(::Vector2, Offset, offset)
GETTERSETTER(::Vector2, Target, target)
GETTERSETTER(float, Rotation, rotation)
GETTERSETTER(float, Zoom, zoom)
Camera2D& operator=(const ::Camera2D& camera) {
set(camera);
return *this;
}
/**
* Returns camera 2d transform matrix
*/
inline Matrix GetMatrix() const {
return ::GetCameraMatrix2D(*this);
}
/**
* Returns the world space position for a 2d camera screen space position
*/
inline Vector2 GetScreenToWorld(::Vector2 position) const {
return ::GetScreenToWorld2D(position, *this);
}
/**
* Returns the screen space position for a 3d world space position
*/
inline Vector2 GetWorldToScreen(::Vector2 position) const {
return ::GetWorldToScreen2D(position, *this);
}
protected:
void set(const ::Camera2D& camera) {
offset = camera.offset;
target = camera.target;
rotation = camera.rotation;
zoom = camera.zoom;
}
};
} // namespace raylib
using RCamera2D = raylib::Camera2D;
#endif // RAYLIB_CPP_INCLUDE_CAMERA2D_HPP_

View File

@@ -0,0 +1,139 @@
#ifndef RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
#define RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
#include "./raylib.hpp"
#include "./Vector3.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* Camera type, defines a camera position/orientation in 3d space
*/
class Camera3D : public ::Camera3D {
public:
Camera3D(const ::Camera3D& camera) {
set(camera);
}
/**
* Create a new Camera3D.
*
* @param position Camera position
* @param target Camera target it looks-at
* @param up Camera up vector (rotation over its axis)
* @param fovy Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
* @param projection Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
*/
Camera3D(::Vector3 position,
::Vector3 target = ::Vector3{0.0f, 0.0f, 0.0f},
::Vector3 up = ::Vector3{0.0f, 1.0f, 0.0f},
float fovy = 0,
int projection = CAMERA_PERSPECTIVE) : ::Camera3D{position, target, up, fovy, projection} {}
Camera3D() {}
GETTERSETTER(::Vector3, Position, position)
GETTERSETTER(::Vector3, Target, target)
GETTERSETTER(::Vector3, Up, up)
GETTERSETTER(float, Fovy, fovy)
GETTERSETTER(int, Projection, projection)
Camera3D& operator=(const ::Camera3D& camera) {
set(camera);
return *this;
}
/**
* Initializes 3D mode with custom camera (3D)
*/
Camera3D& BeginMode() {
::BeginMode3D(*this);
return *this;
}
/**
* Ends 3D mode and returns to default 2D orthographic mode
*/
Camera3D& EndMode() {
::EndMode3D();
return *this;
}
/**
* Get camera transform matrix (view matrix)
*/
inline Matrix GetMatrix() const {
return ::GetCameraMatrix(*this);
}
/**
* Update camera position for selected mode
*/
inline Camera3D& Update(int mode) {
::UpdateCamera(this, mode);
return *this;
}
/**
* Update camera movement/rotation
*/
inline Camera3D& Update(::Vector3 movement, ::Vector3 rotation, float zoom = 1.0f) {
::UpdateCameraPro(this, movement, rotation, zoom);
return *this;
}
/**
* Returns a ray trace from mouse position
*/
inline Ray GetMouseRay(::Vector2 mousePosition) const {
return ::GetMouseRay(mousePosition, *this);
}
/**
* Returns the screen space position for a 3d world space position
*/
inline Vector2 GetWorldToScreen(::Vector3 position) const {
return ::GetWorldToScreen(position, *this);
}
/**
* Draw a billboard texture.
*/
inline void DrawBillboard(
const ::Texture2D& texture,
::Vector3 center,
float size,
::Color tint = {255, 255, 255, 255}) const {
::DrawBillboard(*this, texture, center, size, tint);
}
/**
* Draw a billboard texture defined by source.
*/
inline void DrawBillboard(
const ::Texture2D& texture,
::Rectangle sourceRec,
::Vector3 center,
::Vector2 size,
::Color tint = {255, 255, 255, 255}) const {
::DrawBillboardRec(*this, texture, sourceRec, center, size, tint);
}
protected:
void set(const ::Camera3D& camera) {
position = camera.position;
target = camera.target;
up = camera.up;
fovy = camera.fovy;
projection = camera.projection;
}
};
typedef Camera3D Camera;
} // namespace raylib
using RCamera = raylib::Camera;
using RCamera3D = raylib::Camera3D;
#endif // RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_

View File

@@ -0,0 +1,281 @@
#ifndef RAYLIB_CPP_INCLUDE_COLOR_HPP_
#define RAYLIB_CPP_INCLUDE_COLOR_HPP_
#include <string>
#include "./raylib.hpp"
#include "./Vector4.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* Color type, RGBA (32bit)
*/
class Color : public ::Color {
public:
Color(const ::Color& color) : ::Color{color.r, color.g, color.b, color.a} {}
Color(
unsigned char red,
unsigned char green,
unsigned char blue,
unsigned char alpha = 255) : ::Color{red, green, blue, alpha} {};
/**
* Black.
*/
Color() : ::Color{0, 0, 0, 255} {};
/**
* Returns a Color from HSV values
*/
Color(::Vector3 hsv) {
set(::ColorFromHSV(hsv.x, hsv.y, hsv.z));
}
/**
* Returns a Color from HSV values
*/
static ::Color FromHSV(float hue, float saturation, float value) {
return ::ColorFromHSV(hue, saturation, value);
}
/**
* Get Color structure from hexadecimal value
*/
Color(unsigned int hexValue) {
set(::GetColor(hexValue));
}
Color(void *srcPtr, int format) {
set(::GetPixelColor(srcPtr, format));
}
/**
* Returns hexadecimal value for a Color
*/
int ToInt() const {
return ::ColorToInt(*this);
}
/**
* Returns hexadecimal value for a Color
*/
operator int() const {
return ::ColorToInt(*this);
}
inline std::string ToString() const {
return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a);
}
inline operator std::string() const {
return ToString();
}
/**
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
*/
Color Fade(float alpha) const {
return ::Fade(*this, alpha);
}
/**
* Returns Color normalized as float [0..1]
*/
Vector4 Normalize() const {
return ::ColorNormalize(*this);
}
/**
* Returns Color from normalized values [0..1]
*/
Color(::Vector4 normalized) {
set(::ColorFromNormalized(normalized));
}
/**
* Returns HSV values for a Color
*/
Vector3 ToHSV() const {
return ::ColorToHSV(*this);
}
GETTERSETTER(unsigned char, R, r)
GETTERSETTER(unsigned char, G, g)
GETTERSETTER(unsigned char, B, b)
GETTERSETTER(unsigned char, A, a)
Color& operator=(const ::Color& color) {
set(color);
return *this;
}
/**
* Set background color (framebuffer clear color)
*/
inline Color& ClearBackground() {
::ClearBackground(*this);
return *this;
}
inline void DrawPixel(int x, int y) const {
::DrawPixel(x, y, *this);
}
/**
* Draw a pixel
*/
inline void DrawPixel(::Vector2 pos) const {
::DrawPixelV(pos, *this);
}
/**
* Draw a line
*/
inline void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY) const {
::DrawLine(startPosX, startPosY, endPosX, endPosY, *this);
}
/**
* Draw a line using Vector points
*/
inline void DrawLine(::Vector2 startPos, ::Vector2 endPos) const {
::DrawLineV(startPos, endPos, *this);
}
/**
* Draw a line using Vector points, with a given thickness
*/
inline void DrawLine(::Vector2 startPos, ::Vector2 endPos, float thick) const {
::DrawLineEx(startPos, endPos, thick, *this);
}
inline void DrawLineBezier(::Vector2 startPos, ::Vector2 endPos, float thick = 1.0f) const {
::DrawLineBezier(startPos, endPos, thick, *this);
}
inline void DrawLineStrip(::Vector2 *points, int numPoints) const {
::DrawLineStrip(points, numPoints, *this);
}
inline void DrawText(const std::string& text, int posX = 0, int posY = 0, int fontSize = 10.0f) const {
::DrawText(text.c_str(), posX, posY, fontSize, *this);
}
inline void DrawText(const ::Font& font, const std::string& text, ::Vector2 position,
float fontSize, float spacing) const {
::DrawTextEx(font, text.c_str(), position, fontSize, spacing, *this);
}
inline void DrawText(
const ::Font& font,
const std::string& text,
::Vector2 position,
::Vector2 origin,
float rotation,
float fontSize,
float spacing) const {
::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, *this);
}
inline void DrawRectangle(int posX, int posY, int width, int height) const {
::DrawRectangle(posX, posY, width, height, *this);
}
inline void DrawRectangle(::Vector2 position, ::Vector2 size) const {
::DrawRectangleV(position, size, *this);
}
inline void DrawRectangle(::Rectangle rec) const {
::DrawRectangleRec(rec, *this);
}
inline void DrawRectangle(::Rectangle rec, ::Vector2 origin, float rotation) const {
::DrawRectanglePro(rec, origin, rotation, *this);
}
inline void DrawRectangleLines(int posX, int posY, int width, int height) const {
::DrawRectangleLines(posX, posY, width, height, *this);
}
inline void DrawRectangleLines(::Rectangle rec, float lineThick) const {
::DrawRectangleLinesEx(rec, lineThick, *this);
}
/**
* Get color multiplied with another color
*/
inline Color Tint(::Color tint) {
return ::ColorTint(*this, tint);
}
/**
* Get color with brightness correction, brightness factor goes from -1.0f to 1.0f
*/
inline Color Brightness(float factor) {
return ::ColorBrightness(*this, factor);
}
/**
* Get color with contrast correction, contrast values between -1.0f and 1.0f
*/
inline Color Contrast(float contrast) {
return ::ColorContrast(*this, contrast);
}
/**
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
*/
Color Alpha(float alpha) const {
return ::ColorAlpha(*this, alpha);
}
/**
* Returns src alpha-blended into dst color with tint
*/
Color AlphaBlend(::Color dst, ::Color tint) const {
return ::ColorAlphaBlend(dst, *this, tint);
}
inline static Color LightGray() { return LIGHTGRAY; }
inline static Color Gray() { return GRAY; }
inline static Color DarkGray() { return DARKGRAY; }
inline static Color Yellow() { return YELLOW; }
inline static Color Gold() { return GOLD; }
inline static Color Orange() { return ORANGE; }
inline static Color Pink() { return PINK; }
inline static Color Red() { return RED; }
inline static Color Maroon() { return MAROON; }
inline static Color Green() { return GREEN; }
inline static Color Lime() { return LIME; }
inline static Color DarkGreen() { return DARKGREEN; }
inline static Color SkyBlue() { return SKYBLUE; }
inline static Color Blue() { return BLUE; }
inline static Color DarkBlue() { return DARKBLUE; }
inline static Color Purple() { return PURPLE; }
inline static Color Violet() { return VIOLET; }
inline static Color DarkPurple() { return DARKPURPLE; }
inline static Color Beige() { return BEIGE; }
inline static Color Brown() { return BROWN; }
inline static Color DarkBrown() { return DARKBROWN; }
inline static Color White() { return WHITE; }
inline static Color Black() { return BLACK; }
inline static Color Blank() { return BLANK; }
inline static Color Magenta() { return MAGENTA; }
inline static Color RayWhite() { return RAYWHITE; }
protected:
void set(const ::Color& color) {
r = color.r;
g = color.g;
b = color.b;
a = color.a;
}
};
} // namespace raylib
using RColor = raylib::Color;
#endif // RAYLIB_CPP_INCLUDE_COLOR_HPP_

View File

@@ -0,0 +1,304 @@
#ifndef RAYLIB_CPP_INCLUDE_FONT_HPP_
#define RAYLIB_CPP_INCLUDE_FONT_HPP_
#include <string>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./RaylibException.hpp"
#include "./TextureUnmanaged.hpp"
namespace raylib {
/**
* Font type, includes texture and charSet array data
*/
class Font : public ::Font {
public:
Font(int baseSize,
int glyphCount,
int glyphPadding,
::Texture2D texture,
::Rectangle *recs = nullptr,
::GlyphInfo *glyphs = nullptr) : ::Font{baseSize, glyphCount, glyphPadding, texture, recs, glyphs} {
// Nothing.
}
/**
* Retrieves the default Font.
*/
Font() {
set(::GetFontDefault());
}
Font(const ::Font& font) {
set(font);
}
/**
* Loads a Font from the given file.
*
* @param fileName The file name of the font to load.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*/
Font(const std::string& fileName) {
Load(fileName);
}
/**
* Loads a Font from the given file, with generation parameters.
*
* @param fileName The file name of the font to load.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*
* @see ::LoadFontEx
*/
Font(const std::string& fileName, int fontSize, int* fontChars = 0, int charCount = 0) {
Load(fileName, fontSize, fontChars, charCount);
}
/**
* Loads a Font from the given image with a color key.
*
* @param image The image to load the fond from.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*
* @see ::LoadFontFromImage()
*/
Font(const ::Image& image, ::Color key, int firstChar) {
Load(image, key, firstChar);
}
/**
* Loads a font from memory, based on the given file type and file data.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*
* @see ::LoadFontFromMemory()
*/
Font(const std::string& fileType, const unsigned char* fileData, int dataSize, int fontSize,
int *fontChars, int charsCount) {
Load(fileType, fileData, dataSize, fontSize, fontChars, charsCount);
}
Font(const Font&) = delete;
Font(Font&& other) {
set(other);
other.baseSize = 0;
other.glyphCount = 0;
other.glyphPadding = 0;
other.texture = {};
other.recs = nullptr;
other.glyphs = nullptr;
}
~Font() {
Unload();
}
void Unload() {
// Protect against calling UnloadFont() twice.
if (baseSize != 0) {
UnloadFont(*this);
baseSize = 0;
}
}
GETTERSETTER(int, BaseSize, baseSize)
GETTERSETTER(int, GlyphCount, glyphCount)
GETTERSETTER(int, GlyphPadding, glyphPadding)
GETTERSETTER(::Rectangle*, Recs, recs)
GETTERSETTER(::GlyphInfo*, Glyphs, glyphs)
/**
* Get the texture atlas containing the glyphs.
*/
inline TextureUnmanaged GetTexture() {
return texture;
}
/**
* Set the texture atlas containing the glyphs.
*/
inline void SetTexture(const ::Texture& newTexture) {
texture = newTexture;
}
Font& operator=(const ::Font& font) {
Unload();
set(font);
return *this;
}
Font& operator=(const Font&) = delete;
Font& operator=(Font&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.baseSize = 0;
other.glyphCount = 0;
other.glyphPadding = 0;
other.texture = {};
other.recs = nullptr;
other.glyphs = nullptr;
return *this;
}
/**
* Loads a font from a given file.
*
* @param fileName The filename of the font to load.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*
* @see ::LoadFont()
*/
void Load(const std::string& fileName) {
set(::LoadFont(fileName.c_str()));
if (!IsReady()) {
throw new RaylibException("Failed to load Font with from file: " + fileName);
}
}
/**
* Loads a font from a given file with generation parameters.
*
* @param fileName The filename of the font to load.
* @param fontSize The desired size of the font.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*
* @see ::LoadFontEx()
*/
void Load(const std::string& fileName, int fontSize, int* fontChars, int charCount) {
set(::LoadFontEx(fileName.c_str(), fontSize, fontChars, charCount));
if (!IsReady()) {
throw new RaylibException("Failed to load Font with from file with font size: " + fileName);
}
}
void Load(const ::Image& image, ::Color key, int firstChar) {
set(::LoadFontFromImage(image, key, firstChar));
if (!IsReady()) {
throw new RaylibException("Failed to load Font with from image");
}
}
void Load(const std::string& fileType, const unsigned char* fileData, int dataSize, int fontSize,
int *fontChars, int charsCount) {
set(::LoadFontFromMemory(fileType.c_str(), fileData, dataSize, fontSize, fontChars,
charsCount));
if (!IsReady()) {
throw new RaylibException("Failed to load Font " + fileType + " with from file data");
}
}
/**
* Returns if the font is ready to be used.
*/
bool IsReady() const {
return ::IsFontReady(*this);
}
/**
* Draw text using font and additional parameters.
*/
inline void DrawText(const std::string& text, ::Vector2 position, float fontSize,
float spacing, ::Color tint = WHITE) const {
::DrawTextEx(*this, text.c_str(), position, fontSize, spacing, tint);
}
/**
* Draw text using font and additional parameters.
*/
inline void DrawText(const std::string& text, int posX, int posY, float fontSize,
float spacing, ::Color tint = WHITE) const {
::DrawTextEx(*this, text.c_str(),
{ static_cast<float>(posX), static_cast<float>(posY) },
fontSize, spacing, tint);
}
inline void DrawText(
const std::string& text,
::Vector2 position,
::Vector2 origin,
float rotation,
float fontSize,
float spacing,
::Color tint = WHITE) const {
::DrawTextPro(*this, text.c_str(),
position, origin,
rotation, fontSize,
spacing, tint);
}
/**
* Draw one character (codepoint)
*/
inline void DrawText(int codepoint,
::Vector2 position,
float fontSize,
::Color tint = { 255, 255, 255, 255 }) const {
::DrawTextCodepoint(*this, codepoint, position, fontSize, tint);
}
/**
* Draw multiple character (codepoint)
*/
inline void DrawText(const int *codepoints,
int count, ::Vector2 position,
float fontSize, float spacing,
::Color tint = { 255, 255, 255, 255 }) const {
::DrawTextCodepoints(*this,
codepoints, count,
position, fontSize,
spacing, tint);
}
/**
* Measure string size for Font
*/
inline Vector2 MeasureText(const std::string& text, float fontSize, float spacing) const {
return ::MeasureTextEx(*this, text.c_str(), fontSize, spacing);
}
/**
* Get index position for a unicode character on font
*/
inline int GetGlyphIndex(int character) const {
return ::GetGlyphIndex(*this, character);
}
/**
* Create an image from text (custom sprite font)
*/
inline ::Image ImageText(const std::string& text, float fontSize,
float spacing, ::Color tint) const {
return ::ImageTextEx(*this, text.c_str(), fontSize, spacing, tint);
}
protected:
void set(const ::Font& font) {
baseSize = font.baseSize;
glyphCount = font.glyphCount;
glyphPadding = font.glyphPadding;
texture = font.texture;
recs = font.recs;
glyphs = font.glyphs;
}
};
} // namespace raylib
using RFont = raylib::Font;
#endif // RAYLIB_CPP_INCLUDE_FONT_HPP_

View File

@@ -0,0 +1,378 @@
/**
* C++ wrapper functions for raylib.
*/
#ifndef RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
#define RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
#include <string>
#include <vector>
#include "./raylib.hpp"
/**
* Allow changing the declare type for all raylib-cpp global functions. Defaults to static.
*/
#ifndef RLCPPAPI
#define RLCPPAPI static
#endif
namespace raylib {
/**
* Initialize window and OpenGL context
*/
RLCPPAPI inline void InitWindow(int width, int height, const std::string& title = "raylib") {
::InitWindow(width, height, title.c_str());
}
/**
* Set title for window
*/
RLCPPAPI inline void SetWindowTitle(const std::string& title) {
::SetWindowTitle(title.c_str());
}
/**
* Get the human-readable, UTF-8 encoded name of the primary monitor
*/
RLCPPAPI inline std::string GetMonitorName(int monitor = 0) {
return ::GetMonitorName(monitor);
}
/**
* Set clipboard text content
*/
RLCPPAPI inline void SetClipboardText(const std::string& text) {
::SetClipboardText(text.c_str());
}
/**
* Get clipboard text content
*/
RLCPPAPI inline std::string GetClipboardText() {
return ::GetClipboardText();
}
/**
* Takes a screenshot of current screen (saved a .png)
*/
RLCPPAPI inline void TakeScreenshot(const std::string& fileName) {
::TakeScreenshot(fileName.c_str());
}
/**
* Get gamepad internal name id
*/
RLCPPAPI inline std::string GetGamepadName(int gamepad) {
return ::GetGamepadName(gamepad);
}
/**
* Load text data from file (read)
*/
RLCPPAPI std::string LoadFileText(const std::string& fileName) {
char* text = ::LoadFileText(fileName.c_str());
std::string output(text);
::UnloadFileText(text);
return output;
}
/**
* Save text data to file (write)
*/
RLCPPAPI inline bool SaveFileText(const std::string& fileName, const std::string& text) {
return ::SaveFileText(fileName.c_str(), const_cast<char*>(text.c_str()));
}
/**
* Check if file exists
*/
RLCPPAPI inline bool FileExists(const std::string& fileName) {
return ::FileExists(fileName.c_str());
}
/**
* Check if directory path exists
*/
RLCPPAPI inline bool DirectoryExists(const std::string& dirPath) {
return ::DirectoryExists(dirPath.c_str());
}
/**
* Check file extension (including point: .png, .wav)
*/
RLCPPAPI inline bool IsFileExtension(const std::string& fileName, const std::string& ext) {
return ::IsFileExtension(fileName.c_str(), ext.c_str());
}
/**
* Get pointer to extension for a filename string (including point: ".png")
*/
RLCPPAPI inline std::string GetFileExtension(const std::string& fileName) {
return ::GetFileExtension(fileName.c_str());
}
/**
* Get pointer to filename for a path string
*/
RLCPPAPI inline std::string GetFileName(const std::string& filePath) {
return ::GetFileName(filePath.c_str());
}
/**
* Get filename string without extension
*/
RLCPPAPI inline std::string GetFileNameWithoutExt(const std::string& filePath) {
return ::GetFileNameWithoutExt(filePath.c_str());
}
/**
* Get full path for a given fileName with path
*/
RLCPPAPI inline std::string GetDirectoryPath(const std::string& filePath) {
return ::GetDirectoryPath(filePath.c_str());
}
/**
* Get previous directory path for a given path
*/
RLCPPAPI inline std::string GetPrevDirectoryPath(const std::string& dirPath) {
return ::GetPrevDirectoryPath(dirPath.c_str());
}
/**
* Get current working directory
*/
RLCPPAPI inline std::string GetWorkingDirectory() {
return ::GetWorkingDirectory();
}
/**
* Get filenames in a directory path
*/
RLCPPAPI std::vector<std::string> LoadDirectoryFiles(const std::string& dirPath) {
FilePathList files = ::LoadDirectoryFiles(dirPath.c_str());
std::vector<std::string> output(files.paths, files.paths + files.count);
::UnloadDirectoryFiles(files);
return output;
}
/**
* Change working directory, return true on success
*/
RLCPPAPI inline bool ChangeDirectory(const std::string& dir) {
return ::ChangeDirectory(dir.c_str());
}
/**
* Get dropped files names
*/
RLCPPAPI std::vector<std::string> LoadDroppedFiles() {
if (!::IsFileDropped()) {
return std::vector<std::string>();
}
FilePathList files = ::LoadDroppedFiles();
std::vector<std::string> output(files.paths, files.paths + files.count);
::UnloadDroppedFiles(files);
return output;
}
/**
* Get file modification time (last write time)
*/
RLCPPAPI inline long GetFileModTime(const std::string& fileName) { // NOLINT
return ::GetFileModTime(fileName.c_str());
}
/**
* Open URL with default system browser (if available)
*/
RLCPPAPI inline void OpenURL(const std::string& url) {
return ::OpenURL(url.c_str());
}
/**
* Load an image.
*/
RLCPPAPI inline ::Image LoadImage(const std::string& fileName) {
return ::LoadImage(fileName.c_str());
}
/**
* Load an image from RAW file data
*/
RLCPPAPI inline ::Image LoadImageRaw(const std::string& fileName,
int width, int height,
int format, int headerSize) {
return ::LoadImageRaw(fileName.c_str(), width, height, format, headerSize);
}
/**
* Load animated image data
*/
RLCPPAPI inline ::Image LoadImageAnim(const std::string& fileName, int *frames) {
return ::LoadImageAnim(fileName.c_str(), frames);
}
/**
* Load image from memory buffer, fileType refers to extension like "png"
*/
RLCPPAPI inline ::Image LoadImageFromMemory(const std::string& fileType,
const unsigned char *fileData,
int dataSize) {
return ::LoadImageFromMemory(fileType.c_str(), fileData, dataSize);
}
/**
* Export image data to file
*/
RLCPPAPI inline bool ExportImage(const Image& image, const std::string& fileName) {
return ::ExportImage(image, fileName.c_str());
}
/**
* Export image as code file (.h) defining an array of bytes
*/
RLCPPAPI inline bool ExportImageAsCode(const Image& image, const std::string& fileName) {
return ::ExportImageAsCode(image, fileName.c_str());
}
/**
* Draw text (using default font)
*/
RLCPPAPI inline void DrawText(const std::string& text, int posX, int posY, int fontSize, ::Color color) {
::DrawText(text.c_str(), posX, posY, fontSize, color);
}
/**
* Draw text using font and additional parameters
*/
RLCPPAPI inline void DrawTextEx(const Font& font, const std::string& text, Vector2 position,
float fontSize, float spacing, ::Color tint) {
::DrawTextEx(font, text.c_str(), position, fontSize, spacing, tint);
}
/**
* Draw text using Font and pro parameters (rotation)
*/
RLCPPAPI inline void DrawTextPro(const Font& font, const std::string& text, Vector2 position,
Vector2 origin, float rotation, float fontSize, float spacing, ::Color tint) {
::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, tint);
}
/**
* Load font from file (filename must include file extension)
*/
RLCPPAPI inline ::Font LoadFont(const std::string& fileName) {
return ::LoadFont(fileName.c_str());
}
/**
* Load font from file (filename must include file extension)
*/
RLCPPAPI inline ::Font LoadFontEx(const std::string& fileName, int fontSize, int *fontChars, int charsCount) {
return ::LoadFontEx(fileName.c_str(), fontSize, fontChars, charsCount);
}
/**
* Measure string width for default font
*/
RLCPPAPI inline int MeasureText(const std::string& text, int fontSize) {
return ::MeasureText(text.c_str(), fontSize);
}
/**
* Check if two text string are equal
*/
RLCPPAPI inline bool TextIsEqual(const std::string& text1, const std::string& text2) {
return ::TextIsEqual(text1.c_str(), text2.c_str());
}
/**
* Check if two text string are equal
*/
RLCPPAPI inline unsigned int TextLength(const std::string& text) {
return ::TextLength(text.c_str());
}
/**
* Get text length, checks for '\0' ending
*/
RLAPI inline std::string TextSubtext(const std::string& text, int position, int length) {
return ::TextSubtext(text.c_str(), position, length);
}
/**
* Replace text string
*/
RLAPI inline std::string TextReplace(const std::string& text, const std::string& replace, const std::string& by) {
const char* input = text.c_str();
char* output = ::TextReplace(const_cast<char*>(input), replace.c_str(), by.c_str());
if (output != NULL) {
std::string stringOutput(output);
free(output);
return stringOutput;
}
return "";
}
/**
* Insert text in a position
*/
RLAPI inline std::string TextInsert(const std::string& text, const std::string& insert, int position) {
char* output = ::TextInsert(text.c_str(), insert.c_str(), position);
if (output != NULL) {
std::string stringOutput(output);
free(output);
return stringOutput;
}
return "";
}
/**
* Split text into multiple strings
*/
RLAPI inline std::vector<std::string> TextSplit(const std::string& text, char delimiter) {
int count;
const char** split = ::TextSplit(text.c_str(), delimiter, &count);
return std::vector<std::string>(split, split + count);
}
/**
* Find first text occurrence within a string
*/
RLAPI inline int TextFindIndex(const std::string& text, const std::string& find) {
return ::TextFindIndex(text.c_str(), find.c_str());
}
/**
* Get upper case version of provided string
*/
RLAPI inline std::string TextToUpper(const std::string& text) {
return ::TextToUpper(text.c_str());
}
/**
* Get lower case version of provided string
*/
RLAPI inline std::string TextToLower(const std::string& text) {
return ::TextToLower(text.c_str());
}
/**
* Get Pascal case notation version of provided string
*/
RLAPI inline std::string TextToPascal(const std::string& text) {
return ::TextToPascal(text.c_str());
}
/**
* Get integer value from text (negative values not supported)
*/
RLAPI inline int TextToInteger(const std::string& text) {
return ::TextToInteger(text.c_str());
}
} // namespace raylib
#endif // RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_

View File

@@ -0,0 +1,124 @@
#ifndef RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
#define RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
#include <string>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* Input-related functions: gamepads
*/
class Gamepad {
public:
Gamepad(int gamepadNumber = 0) {
set(gamepadNumber);
}
int number;
GETTERSETTER(int, Number, number)
Gamepad& operator=(const Gamepad& gamepad) {
set(gamepad);
return *this;
}
Gamepad& operator=(int gamepadNumber) {
set(gamepadNumber);
return *this;
}
operator int() const { return number; }
/**
* Detect if a gamepad is available
*/
inline bool IsAvailable() const {
return ::IsGamepadAvailable(number);
}
/**
* Detect if a gamepad is available
*/
static inline bool IsAvailable(int number) {
return ::IsGamepadAvailable(number);
}
/**
* Return gamepad internal name id
*/
std::string GetName() const {
return ::GetGamepadName(number);
}
/**
* Return gamepad internal name id
*/
operator std::string() const {
return GetName();
}
/**
* Detect if a gamepad button has been pressed once
*/
inline bool IsButtonPressed(int button) const {
return ::IsGamepadButtonPressed(number, button);
}
/**
* Detect if a gamepad button is being pressed
*/
inline bool IsButtonDown(int button) const {
return ::IsGamepadButtonDown(number, button);
}
/**
* Detect if a gamepad button has been released once
*/
inline bool IsButtonReleased(int button) const {
return ::IsGamepadButtonReleased(number, button);
}
/**
* Detect if a gamepad button is NOT being pressed
*/
inline bool IsButtonUp(int button) const {
return ::IsGamepadButtonUp(number, button);
}
/**
* Get the last gamepad button pressed
*/
inline int GetButtonPressed() const {
return ::GetGamepadButtonPressed();
}
/**
* Return gamepad axis count for a gamepad
*/
inline int GetAxisCount() const {
return ::GetGamepadAxisCount(number);
}
/**
* Return axis movement value for a gamepad axis
*/
inline float GetAxisMovement(int axis) const {
return ::GetGamepadAxisMovement(number, axis);
}
inline int SetMappings(const std::string& mappings) {
return SetGamepadMappings(mappings.c_str());
}
protected:
inline void set(int gamepadNumber) {
number = gamepadNumber;
}
};
} // namespace raylib
using RGamepad = raylib::Gamepad;
#endif // RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_

View File

@@ -0,0 +1,750 @@
#ifndef RAYLIB_CPP_INCLUDE_IMAGE_HPP_
#define RAYLIB_CPP_INCLUDE_IMAGE_HPP_
#include <string>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./RaylibException.hpp"
#include "./Color.hpp"
namespace raylib {
/**
* Image type, bpp always RGBA (32bit)
*
* Data stored in CPU memory (RAM)
*/
class Image : public ::Image {
public:
Image(void* data = nullptr,
int width = 0,
int height = 0,
int mipmaps = 1,
int format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8) : ::Image{data, width, height, mipmaps, format} {
// Nothing.
}
Image(const ::Image& image) {
set(image);
}
/**
* Load an image from the given file.
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*
* @see Load()
*/
Image(const std::string& fileName) {
Load(fileName);
}
/**
* Load a raw image from the given file, with the provided width, height, and formats.
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*
* @see LoadRaw()
*/
Image(const std::string& fileName, int width, int height, int format, int headerSize = 0) {
Load(fileName, width, height, format, headerSize);
}
/**
* Load an animation image from the given file.
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*
* @see LoadAnim()
*/
Image(const std::string& fileName, int* frames) {
Load(fileName, frames);
}
/**
* Load an image from the given file.
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*/
Image(const std::string& fileType, const unsigned char* fileData, int dataSize) {
Load(fileType, fileData, dataSize);
}
/**
* Load an image from the given file.
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*/
Image(const ::Texture2D& texture) {
Load(texture);
}
Image(int width, int height, ::Color color = {255, 255, 255, 255}) {
set(::GenImageColor(width, height, color));
}
Image(const std::string& text, int fontSize, ::Color color = {255, 255, 255, 255}) {
set(::ImageText(text.c_str(), fontSize, color));
}
Image(const ::Font& font, const std::string& text, float fontSize, float spacing,
::Color tint = {255, 255, 255, 255}) {
set(::ImageTextEx(font, text.c_str(), fontSize, spacing, tint));
}
Image(const Image& other) {
set(other.Copy());
}
Image(Image&& other) {
set(other);
other.data = nullptr;
other.width = 0;
other.height = 0;
other.mipmaps = 0;
other.format = 0;
}
static ::Image Text(const std::string& text, int fontSize,
::Color color = {255, 255, 255, 255}) {
return ::ImageText(text.c_str(), fontSize, color);
}
static ::Image Text(const ::Font& font, const std::string& text, float fontSize, float spacing,
::Color tint = {255, 255, 255, 255}) {
return ::ImageTextEx(font, text.c_str(), fontSize, spacing, tint);
}
/**
* Get pixel data from screen buffer and return an Image (screenshot)
*/
static ::Image LoadFromScreen() {
return ::LoadImageFromScreen();
}
/**
* Generate image: plain color
*/
static ::Image Color(int width, int height, ::Color color = {255, 255, 255, 255}) {
return ::GenImageColor(width, height, color);
}
/**
* Generate image: linear gradient
*/
static ::Image GradientLinear(int width, int height, int direction, ::Color start, ::Color end) {
return ::GenImageGradientLinear(width, height, direction, start, end);
}
/**
* Generate image: radial gradient
*/
static ::Image GradientRadial(int width, int height, float density,
::Color inner, ::Color outer) {
return ::GenImageGradientRadial(width, height, density, inner, outer);
}
/**
* Generate image: checked
*/
static ::Image Checked(int width, int height, int checksX, int checksY,
::Color col1 = {255, 255, 255, 255}, ::Color col2 = {0, 0, 0, 255}) {
return ::GenImageChecked(width, height, checksX, checksY, col1, col2);
}
/**
* Generate image: white noise
*/
static ::Image WhiteNoise(int width, int height, float factor) {
return ::GenImageWhiteNoise(width, height, factor);
}
/**
* Generate image: cellular algorithm. Bigger tileSize means bigger cells
*/
static ::Image Cellular(int width, int height, int tileSize) {
return ::GenImageCellular(width, height, tileSize);
}
~Image() {
Unload();
}
Image& operator=(const ::Image& image) {
set(image);
return *this;
}
Image& operator=(const Image& other) {
if (this == &other) {
return *this;
}
Unload();
set(other.Copy());
return *this;
}
Image& operator=(Image&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.data = nullptr;
other.width = 0;
other.height = 0;
other.mipmaps = 0;
other.format = 0;
return *this;
}
/**
* Load image from file into CPU memory (RAM)
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*
* @see ::LoadImage()
*/
void Load(const std::string& fileName) {
set(::LoadImage(fileName.c_str()));
if (!IsReady()) {
throw RaylibException("Failed to load Image from file: " + fileName);
}
}
/**
* Load image from RAW file data.
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*
* @see ::LoadImageRaw()
*/
void Load(const std::string& fileName, int width, int height, int format, int headerSize) {
set(::LoadImageRaw(fileName.c_str(), width, height, format, headerSize));
if (!IsReady()) {
throw RaylibException("Failed to load Image from file: " + fileName);
}
}
/**
* Load image sequence from file (frames appended to image.data).
*
* @throws raylib::RaylibException Thrown if the image animation to load from the file.
*
* @see ::LoadImageAnim()
*/
void Load(const std::string& fileName, int* frames) {
set(::LoadImageAnim(fileName.c_str(), frames));
if (!IsReady()) {
throw RaylibException("Failed to load Image from file: " + fileName);
}
}
/**
* Load image from memory buffer, fileType refers to extension: i.e. "png".
*
* @throws raylib::RaylibException Thrown if the image animation to load from the file.
*
* @see ::LoadImageFromMemory()
*/
void Load(
const std::string& fileType,
const unsigned char *fileData,
int dataSize) {
set(::LoadImageFromMemory(fileType.c_str(), fileData, dataSize));
if (!IsReady()) {
throw RaylibException("Failed to load Image data with file type: " + fileType);
}
}
/**
* Load an image from the given file.
*
* @throws raylib::RaylibException Thrown if the image animation to load from the file.
*
* @see ::LoadImageFromTexture()
*/
void Load(const ::Texture2D& texture) {
set(::LoadImageFromTexture(texture));
if (!IsReady()) {
throw RaylibException("Failed to load Image from texture.");
}
}
/**
* Unload image from CPU memory (RAM)
*/
inline void Unload() {
if (data != nullptr) {
::UnloadImage(*this);
data = nullptr;
}
}
/**
* Export image data to file, returns true on success
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*/
inline void Export(const std::string& fileName) const {
if (!::ExportImage(*this, fileName.c_str())) {
throw RaylibException(TextFormat("Failed to export Image to file: %s", fileName.c_str()));
}
}
/**
* Export image to memory buffer
*/
inline unsigned char* ExportToMemory(const char *fileType, int *fileSize) {
return ::ExportImageToMemory(*this, fileType, fileSize);
}
/**
* Export image as code file defining an array of bytes, returns true on success
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*/
inline void ExportAsCode(const std::string& fileName) const {
if (!::ExportImageAsCode(*this, fileName.c_str())) {
throw RaylibException(TextFormat("Failed to export Image code to file: %s", fileName.c_str()));
}
}
GETTERSETTER(void*, Data, data)
GETTERSETTER(int, Width, width)
GETTERSETTER(int, Height, height)
GETTERSETTER(int, Mipmaps, mipmaps)
GETTERSETTER(int, Format, format)
/**
* Retrieve the width and height of the image.
*/
inline ::Vector2 GetSize() const {
return {static_cast<float>(width), static_cast<float>(height)};
}
/**
* Create an image duplicate (useful for transformations)
*/
inline ::Image Copy() const {
return ::ImageCopy(*this);
}
/**
* Create an image from another image piece
*/
inline ::Image FromImage(::Rectangle rec) const {
return ::ImageFromImage(*this, rec);
}
/**
* Convert image data to desired format
*/
inline Image& Format(int newFormat) {
::ImageFormat(this, newFormat);
return *this;
}
/**
* Convert image to POT (power-of-two)
*/
inline Image& ToPOT(::Color fillColor) {
::ImageToPOT(this, fillColor);
return *this;
}
/**
* Crop an image to area defined by a rectangle
*/
inline Image& Crop(::Rectangle crop) {
::ImageCrop(this, crop);
return *this;
}
/**
* Crop image depending on alpha value
*/
inline Image& AlphaCrop(float threshold) {
::ImageAlphaCrop(this, threshold);
return *this;
}
/**
* Clear alpha channel to desired color
*/
inline Image& AlphaClear(::Color color, float threshold) {
::ImageAlphaClear(this, color, threshold);
return *this;
}
/**
* Apply alpha mask to image
*/
inline Image& AlphaMask(const ::Image& alphaMask) {
::ImageAlphaMask(this, alphaMask);
return *this;
}
/**
* Premultiply alpha channel
*/
inline Image& AlphaPremultiply() {
::ImageAlphaPremultiply(this);
return *this;
}
/**
* Crop an image to a new given width and height.
*/
inline Image& Crop(int newWidth, int newHeight) {
return Crop(0, 0, newWidth, newHeight);
}
/**
* Crop an image to a new given width and height based on a vector.
*/
inline Image& Crop(::Vector2 size) {
return Crop(0, 0, static_cast<int>(size.x), static_cast<int>(size.y));
}
/**
* Crop an image to area defined by a rectangle
*/
inline Image& Crop(int offsetX, int offsetY, int newWidth, int newHeight) {
::Rectangle rect{
static_cast<float>(offsetX),
static_cast<float>(offsetY),
static_cast<float>(newWidth),
static_cast<float>(newHeight)
};
::ImageCrop(this, rect);
return *this;
}
/**
* Resize and image to new size
*/
inline Image& Resize(int newWidth, int newHeight) {
::ImageResize(this, newWidth, newHeight);
return *this;
}
/**
* Resize and image to new size using Nearest-Neighbor scaling algorithm
*/
inline Image& ResizeNN(int newWidth, int newHeight) {
::ImageResizeNN(this, newWidth, newHeight);
return *this;
}
/**
* Resize canvas and fill with color
*/
inline Image& ResizeCanvas(int newWidth, int newHeight, int offsetX = 0, int offsetY = 0,
::Color color = {255, 255, 255, 255}) {
::ImageResizeCanvas(this, newWidth, newHeight, offsetX, offsetY, color);
return *this;
}
/**
* Generate all mipmap levels for a provided image
*/
inline Image& Mipmaps() {
::ImageMipmaps(this);
return *this;
}
/**
* Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
*/
inline Image& Dither(int rBpp, int gBpp, int bBpp, int aBpp) {
::ImageDither(this, rBpp, gBpp, bBpp, aBpp);
return *this;
}
/**
* Flip image vertically
*/
inline Image& FlipVertical() {
::ImageFlipVertical(this);
return *this;
}
/**
* Flip image horizontally
*/
inline Image& FlipHorizontal() {
::ImageFlipHorizontal(this);
return *this;
}
/**
* Rotate image by input angle in degrees (-359 to 359)
*/
inline Image& Rotate(int degrees) {
::ImageRotate(this, degrees);
return *this;
}
/**
* Rotate image clockwise 90deg
*/
inline Image& RotateCW() {
::ImageRotateCW(this);
return *this;
}
/**
* Rotate image counter-clockwise 90deg
*/
inline Image& RotateCCW() {
::ImageRotateCCW(this);
return *this;
}
/**
* Modify image color: tint
*/
inline Image& ColorTint(::Color color = {255, 255, 255, 255}) {
::ImageColorTint(this, color);
return *this;
}
/**
* Modify image color: invert
*/
inline Image& ColorInvert() {
::ImageColorInvert(this);
return *this;
}
/**
* Modify image color: grayscale
*/
inline Image& ColorGrayscale() {
::ImageColorGrayscale(this);
return *this;
}
/**
* Modify image color: contrast
*
* @param contrast Contrast values between -100 and 100
*/
inline Image& ColorContrast(float contrast) {
::ImageColorContrast(this, contrast);
return *this;
}
/**
* Modify image color: brightness
*
* @param brightness Brightness values between -255 and 255
*/
inline Image& ColorBrightness(int brightness) {
::ImageColorBrightness(this, brightness);
return *this;
}
/**
* Modify image color: replace color
*/
inline Image& ColorReplace(::Color color, ::Color replace) {
::ImageColorReplace(this, color, replace);
return *this;
}
/**
* Get image alpha border rectangle
*
* @param threshold Threshold is defined as a percentatge: 0.0f -> 1.0f
*/
inline Rectangle GetAlphaBorder(float threshold) const {
return ::GetImageAlphaBorder(*this, threshold);
}
/**
* Get image pixel color at (x, y) position
*/
inline raylib::Color GetColor(int x = 0, int y = 0) const {
return ::GetImageColor(*this, x, y);
}
/**
* Get image pixel color at vector position
*/
inline raylib::Color GetColor(::Vector2 position) const {
return ::GetImageColor(*this, static_cast<int>(position.x), static_cast<int>(position.y));
}
/**
* Clear image background with given color
*/
inline Image& ClearBackground(::Color color = {0, 0, 0, 255}) {
::ImageClearBackground(this, color);
return *this;
}
/**
* Draw pixel within an image
*/
inline void DrawPixel(int posX, int posY, ::Color color = {255, 255, 255, 255}) {
::ImageDrawPixel(this, posX, posY, color);
}
inline void DrawPixel(::Vector2 position, ::Color color = {255, 255, 255, 255}) {
::ImageDrawPixelV(this, position, color);
}
inline void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY,
::Color color = {255, 255, 255, 255}) {
::ImageDrawLine(this, startPosX, startPosY, endPosX, endPosY, color);
}
inline void DrawLine(::Vector2 start, ::Vector2 end, ::Color color = {255, 255, 255, 255}) {
::ImageDrawLineV(this, start, end, color);
}
inline void DrawCircle(int centerX, int centerY, int radius,
::Color color = {255, 255, 255, 255}) {
::ImageDrawCircle(this, centerX, centerY, radius, color);
}
inline void DrawCircle(::Vector2 center, int radius,
::Color color = {255, 255, 255, 255}) {
::ImageDrawCircleV(this, center, radius, color);
}
inline void DrawRectangle(int posX, int posY, int width, int height,
::Color color = {255, 255, 255, 255}) {
::ImageDrawRectangle(this, posX, posY, width, height, color);
}
inline void DrawRectangle(Vector2 position, Vector2 size,
::Color color = {255, 255, 255, 255}) {
::ImageDrawRectangleV(this, position, size, color);
}
inline void DrawRectangle(::Rectangle rec, ::Color color = {255, 255, 255, 255}) {
::ImageDrawRectangleRec(this, rec, color);
}
inline void DrawRectangleLines(::Rectangle rec, int thick = 1,
::Color color = {255, 255, 255, 255}) {
::ImageDrawRectangleLines(this, rec, thick, color);
}
inline void Draw(const ::Image& src, ::Rectangle srcRec, ::Rectangle dstRec,
::Color tint = {255, 255, 255, 255}) {
::ImageDraw(this, src, srcRec, dstRec, tint);
}
inline void DrawText(const std::string& text, ::Vector2 position, int fontSize,
::Color color = {255, 255, 255, 255}) {
::ImageDrawText(this,
text.c_str(),
static_cast<int>(position.x),
static_cast<int>(position.y),
fontSize,
color);
}
inline void DrawText(const std::string& text, int x, int y, int fontSize,
::Color color = {255, 255, 255, 255}) {
::ImageDrawText(this, text.c_str(), x, y, fontSize, color);
}
inline void DrawText(const ::Font& font, const std::string& text, ::Vector2 position,
float fontSize, float spacing, ::Color tint = {255, 255, 255, 255}) {
::ImageDrawTextEx(this, font, text.c_str(), position, fontSize, spacing, tint);
}
/**
* Load color data from image as a Color array (RGBA - 32bit)
*/
inline ::Color* LoadColors() const {
return ::LoadImageColors(*this);
}
/**
* Load colors palette from image as a Color array (RGBA - 32bit)
*/
inline ::Color* LoadPalette(int maxPaletteSize, int *colorsCount) const {
return ::LoadImagePalette(*this, maxPaletteSize, colorsCount);
}
/**
* Unload color data loaded with LoadImageColors()
*/
inline void UnloadColors(::Color* colors) const {
::UnloadImageColors(colors);
}
/**
* Unload colors palette loaded with LoadImagePalette()
*/
inline void UnloadPalette(::Color* colors) const {
::UnloadImagePalette(colors);
}
/**
* Load texture from image data.
*/
inline ::Texture2D LoadTexture() const {
return ::LoadTextureFromImage(*this);
}
/**
* Loads a texture from the image data.
*
* @see LoadTexture()
*/
inline operator ::Texture2D() {
return LoadTexture();
}
/**
* Get pixel data size in bytes for certain format
*/
static int GetPixelDataSize(int width, int height, int format = PIXELFORMAT_UNCOMPRESSED_R32G32B32A32) {
return ::GetPixelDataSize(width, height, format);
}
/**
* Returns the pixel data size based on the current image.
*
* @return The pixel data size of the image.
*/
inline int GetPixelDataSize() const {
return ::GetPixelDataSize(width, height, format);
}
/**
* Retrieve whether or not the Image has been loaded.
*
* @return True or false depending on whether the Image has been loaded.
*/
inline bool IsReady() const {
return ::IsImageReady(*this);
}
protected:
void set(const ::Image& image) {
data = image.data;
width = image.width;
height = image.height;
mipmaps = image.mipmaps;
format = image.format;
}
};
} // namespace raylib
using RImage = raylib::Image;
#endif // RAYLIB_CPP_INCLUDE_IMAGE_HPP_

View File

@@ -0,0 +1,133 @@
#ifndef RAYLIB_CPP_INCLUDE_MATERIAL_HPP_
#define RAYLIB_CPP_INCLUDE_MATERIAL_HPP_
#include <string>
#include <vector>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* Material type (generic)
*/
class Material : public ::Material {
public:
Material(const ::Material& material) {
set(material);
}
/**
* Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps)
*/
Material() {
set(LoadMaterialDefault());
}
Material(const Material&) = delete;
Material(Material&& other) {
set(other);
other.maps = nullptr;
other.shader = {};
other.params[0] = 0.0f;
other.params[1] = 0.0f;
other.params[2] = 0.0f;
other.params[3] = 0.0f;
}
~Material() {
Unload();
}
/**
* Load materials from model file
*/
static std::vector<Material> Load(const std::string& fileName) {
int count = 0;
// TODO(RobLoach): Material::Load() possibly leaks the materials array.
::Material* materials = ::LoadMaterials(fileName.c_str(), &count);
return std::vector<Material>(materials, materials + count);
}
GETTERSETTER(::Shader, Shader, shader)
GETTERSETTER(::MaterialMap*, Maps, maps)
// TODO(RobLoach): Resolve the Material params being a float[4].
// GETTERSETTER(float[4], Params, params)
Material& operator=(const ::Material& material) {
set(material);
return *this;
}
Material& operator=(const Material&) = delete;
Material& operator=(Material&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.maps = nullptr;
other.shader = {};
return *this;
}
/**
* Unload material from memory
*/
inline void Unload() {
if (maps != nullptr) {
::UnloadMaterial(*this);
maps = nullptr;
}
}
/**
* Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...)
*/
inline Material& SetTexture(int mapType, const ::Texture2D& texture) {
::SetMaterialTexture(this, mapType, texture);
return *this;
}
/**
* Draw a 3d mesh with material and transform
*/
inline void DrawMesh(const ::Mesh& mesh, ::Matrix transform) const {
::DrawMesh(mesh, *this, transform);
}
/**
* Draw multiple mesh instances with material and different transforms
*/
inline void DrawMesh(const ::Mesh& mesh, ::Matrix* transforms, int instances) const {
::DrawMeshInstanced(mesh, *this, transforms, instances);
}
/**
* Check if material is ready
*/
inline bool IsReady() const {
return ::IsMaterialReady(*this);
}
protected:
void set(const ::Material& material) {
shader = material.shader;
maps = material.maps;
params[0] = material.params[0];
params[1] = material.params[1];
params[2] = material.params[2];
params[3] = material.params[3];
}
};
} // namespace raylib
using RMaterial = raylib::Material;
#endif // RAYLIB_CPP_INCLUDE_MATERIAL_HPP_

View File

@@ -0,0 +1,232 @@
#ifndef RAYLIB_CPP_INCLUDE_MATRIX_HPP_
#define RAYLIB_CPP_INCLUDE_MATRIX_HPP_
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raymath.hpp"
#ifndef RAYLIB_CPP_NO_MATH
#include <cmath>
#endif
namespace raylib {
/**
* Matrix type (OpenGL style 4x4 - right handed, column major)
*/
class Matrix : public ::Matrix {
public:
Matrix(const ::Matrix& mat) : ::Matrix{
mat.m0, mat.m4, mat.m8, mat.m12,
mat.m1, mat.m5, mat.m9, mat.m13,
mat.m2, mat.m6, mat.m10, mat.m14,
mat.m3, mat.m7, mat.m11, mat.m15} {
// Nothing.
}
Matrix(
float m0 = 0, float m4 = 0, float m8 = 0, float m12 = 0,
float m1 = 0, float m5 = 0, float m9 = 0, float m13 = 0,
float m2 = 0, float m6 = 0, float m10 = 0, float m14 = 0,
float m3 = 0, float m7 = 0, float m11 = 0, float m15 = 0) :
::Matrix{
m0, m4, m8, m12,
m1, m5, m9, m13,
m2, m6, m10, m14,
m3, m7, m11, m15} {
// Nothing.
}
GETTERSETTER(float, M0, m0)
GETTERSETTER(float, M1, m1)
GETTERSETTER(float, M2, m2)
GETTERSETTER(float, M3, m3)
GETTERSETTER(float, M4, m4)
GETTERSETTER(float, M5, m5)
GETTERSETTER(float, M6, m6)
GETTERSETTER(float, M7, m7)
GETTERSETTER(float, M8, m8)
GETTERSETTER(float, M9, m9)
GETTERSETTER(float, M10, m10)
GETTERSETTER(float, M11, m11)
GETTERSETTER(float, M12, m12)
GETTERSETTER(float, M13, m13)
GETTERSETTER(float, M14, m14)
GETTERSETTER(float, M15, m15)
Matrix& operator=(const ::Matrix& matrix) {
set(matrix);
return *this;
}
Matrix& operator=(const Matrix& matrix) {
set(matrix);
return *this;
}
bool operator==(const ::Matrix& other) {
return m0 == other.m0
&& m1 == other.m1
&& m2 == other.m2
&& m3 == other.m3
&& m4 == other.m4
&& m5 == other.m5
&& m6 == other.m6
&& m7 == other.m7
&& m8 == other.m8
&& m9 == other.m9
&& m10 == other.m10
&& m11 == other.m11
&& m12 == other.m12
&& m13 == other.m13
&& m14 == other.m14
&& m15 == other.m15;
}
bool operator!=(const ::Matrix& other) {
return !(*this == other);
}
#ifndef RAYLIB_CPP_NO_MATH
/**
* Returns the trace of the matrix (sum of the values along the diagonal)
*/
inline float Trace() const {
return ::MatrixTrace(*this);
}
/**
* Transposes provided matrix
*/
inline Matrix Transpose() const {
return ::MatrixTranspose(*this);
}
inline Matrix Invert() const {
return ::MatrixInvert(*this);
}
static Matrix Identity() {
return ::MatrixIdentity();
}
Matrix Add(const ::Matrix& right) {
return ::MatrixAdd(*this, right);
}
Matrix operator+(const ::Matrix& matrix) {
return ::MatrixAdd(*this, matrix);
}
Matrix Subtract(const ::Matrix& right) {
return ::MatrixSubtract(*this, right);
}
Matrix operator-(const ::Matrix& matrix) {
return ::MatrixSubtract(*this, matrix);
}
static Matrix Translate(float x, float y, float z) {
return ::MatrixTranslate(x, y, z);
}
static Matrix Rotate(Vector3 axis, float angle) {
return ::MatrixRotate(axis, angle);
}
static Matrix RotateXYZ(Vector3 angle) {
return ::MatrixRotateXYZ(angle);
}
static Matrix RotateX(float angle) {
return ::MatrixRotateX(angle);
}
static Matrix RotateY(float angle) {
return ::MatrixRotateY(angle);
}
static Matrix RotateZ(float angle) {
return ::MatrixRotateZ(angle);
}
static Matrix Scale(float x, float y, float z) {
return ::MatrixScale(x, y, z);
}
Matrix Multiply(const ::Matrix& right) const {
return ::MatrixMultiply(*this, right);
}
Matrix operator*(const ::Matrix& matrix) {
return ::MatrixMultiply(*this, matrix);
}
static Matrix Frustum(double left, double right, double bottom, double top,
double near, double far) {
return ::MatrixFrustum(left, right, bottom, top, near, far);
}
static Matrix Perspective(double fovy, double aspect, double near, double far) {
return ::MatrixPerspective(fovy, aspect, near, far);
}
static Matrix Ortho(double left, double right, double bottom, double top,
double near, double far) {
return ::MatrixOrtho(left, right, bottom, top, near, far);
}
static Matrix LookAt(Vector3 eye, Vector3 target, Vector3 up) {
return ::MatrixLookAt(eye, target, up);
}
inline float16 ToFloatV() const {
return ::MatrixToFloatV(*this);
}
operator float16() {
return ToFloatV();
}
/**
* Set shader uniform value (matrix 4x4)
*/
inline Matrix& SetShaderValue(const ::Shader& shader, int uniformLoc) {
::SetShaderValueMatrix(shader, uniformLoc, *this);
return *this;
}
inline static Matrix GetCamera(const ::Camera& camera) {
return ::GetCameraMatrix(camera);
}
inline static Matrix GetCamera(const ::Camera2D& camera) {
return ::GetCameraMatrix2D(camera);
}
#endif
protected:
void set(const ::Matrix& mat) {
m0 = mat.m0;
m1 = mat.m1;
m2 = mat.m2;
m3 = mat.m3;
m4 = mat.m4;
m5 = mat.m5;
m6 = mat.m6;
m7 = mat.m7;
m8 = mat.m8;
m9 = mat.m9;
m10 = mat.m10;
m11 = mat.m11;
m12 = mat.m12;
m13 = mat.m13;
m14 = mat.m14;
m15 = mat.m15;
}
};
} // namespace raylib
using RMatrix = raylib::Matrix;
#endif // RAYLIB_CPP_INCLUDE_MATRIX_HPP_

View File

@@ -0,0 +1,292 @@
#ifndef RAYLIB_CPP_INCLUDE_MESH_HPP_
#define RAYLIB_CPP_INCLUDE_MESH_HPP_
#include <string>
#include <vector>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./BoundingBox.hpp"
#include "./Model.hpp"
namespace raylib {
/**
* Vertex data definning a mesh
*/
class Mesh : public ::Mesh {
public:
Mesh(const ::Mesh& mesh) {
set(mesh);
}
/**
* Load meshes from model file
*/
// static std::vector<Mesh> Load(const std::string& fileName) {
// int count = 0;
// ::Mesh* meshes = LoadMeshes(fileName.c_str(), &count);
// return std::vector<Mesh>(meshes, meshes + count);
// }
Mesh(const Mesh&) = delete;
Mesh(Mesh&& other) {
set(other);
other.vertexCount = 0;
other.triangleCount = 0;
other.vertices = nullptr;
other.texcoords = nullptr;
other.texcoords2 = nullptr;
other.normals = nullptr;
other.tangents = nullptr;
other.colors = nullptr;
other.indices = nullptr;
other.animVertices = nullptr;
other.animNormals = nullptr;
other.boneIds = nullptr;
other.boneWeights = nullptr;
other.vaoId = 0;
other.vboId = nullptr;
}
/**
* Generate polygonal mesh
*/
static ::Mesh Poly(int sides, float radius) {
return ::GenMeshPoly(sides, radius);
}
/**
* Generate plane mesh (with subdivisions)
*/
static ::Mesh Plane(float width, float length, int resX, int resZ) {
return ::GenMeshPlane(width, length, resX, resZ);
}
/**
* Generate cuboid mesh
*/
static ::Mesh Cube(float width, float height, float length) {
return ::GenMeshCube(width, height, length);
}
/**
* Generate sphere mesh (standard sphere)
*/
static ::Mesh Sphere(float radius, int rings, int slices) {
return ::GenMeshSphere(radius, rings, slices);
}
/**
* Generate half-sphere mesh (no bottom cap)
*/
static ::Mesh HemiSphere(float radius, int rings, int slices) {
return ::GenMeshHemiSphere(radius, rings, slices);
}
/**
* Generate cylinder mesh
*/
static ::Mesh Cylinder(float radius, float height, int slices) {
return ::GenMeshCylinder(radius, height, slices);
}
/**
* Generate cone/pyramid mesh
*/
static ::Mesh Cone(float radius, float height, int slices) {
return ::GenMeshCone(radius, height, slices);
}
/**
* Generate torus mesh
*/
static ::Mesh Torus(float radius, float size, int radSeg, int sides) {
return ::GenMeshTorus(radius, size, radSeg, sides);
}
/**
* Generate trefoil knot mesh
*/
static ::Mesh Knot(float radius, float size, int radSeg, int sides) {
return ::GenMeshKnot(radius, size, radSeg, sides);
}
/**
* Generate heightmap mesh from image data
*/
static ::Mesh Heightmap(const ::Image& heightmap, ::Vector3 size) {
return ::GenMeshHeightmap(heightmap, size);
}
/**
* Generate cubes-based map mesh from image data
*/
static ::Mesh Cubicmap(const ::Image& cubicmap, ::Vector3 cubeSize) {
return ::GenMeshCubicmap(cubicmap, cubeSize);
}
GETTERSETTER(int, VertexCount, vertexCount)
GETTERSETTER(int, TriangleCount, triangleCount)
GETTERSETTER(float*, Vertices, vertices)
GETTERSETTER(float *, TexCoords, texcoords)
GETTERSETTER(float *, TexCoords2, texcoords2)
GETTERSETTER(float *, Normals, normals)
GETTERSETTER(float *, Tangents, tangents)
GETTERSETTER(unsigned char *, Colors, colors)
GETTERSETTER(unsigned short *, Indices, indices) // NOLINT
GETTERSETTER(float *, AnimVertices, animVertices)
GETTERSETTER(float *, AnimNormals, animNormals)
GETTERSETTER(unsigned char *, BoneIds, boneIds)
GETTERSETTER(float *, BoneWeights, boneWeights)
GETTERSETTER(unsigned int, VaoId, vaoId)
GETTERSETTER(unsigned int *, VboId, vboId)
Mesh& operator=(const ::Mesh& mesh) {
set(mesh);
return *this;
}
Mesh& operator=(const Mesh&) = delete;
Mesh& operator=(Mesh&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.vertexCount = 0;
other.triangleCount = 0;
other.vertices = nullptr;
other.texcoords = nullptr;
other.texcoords2 = nullptr;
other.normals = nullptr;
other.tangents = nullptr;
other.colors = nullptr;
other.indices = nullptr;
other.animVertices = nullptr;
other.animNormals = nullptr;
other.boneIds = nullptr;
other.boneWeights = nullptr;
other.vaoId = 0;
other.vboId = nullptr;
return *this;
}
~Mesh() {
Unload();
}
/**
* Upload mesh vertex data to GPU (VRAM)
*/
inline void Upload(bool dynamic = false) {
::UploadMesh(this, dynamic);
}
/**
* Upload mesh vertex data to GPU (VRAM)
*/
inline void UpdateBuffer(int index, void *data, int dataSize, int offset = 0) {
::UpdateMeshBuffer(*this, index, data, dataSize, offset);
}
/**
* Draw a 3d mesh with material and transform
*/
inline void Draw(const ::Material& material, const ::Matrix& transform) const {
::DrawMesh(*this, material, transform);
}
/**
* Draw multiple mesh instances with material and different transforms
*/
inline void Draw(const ::Material& material, ::Matrix* transforms, int instances) const {
::DrawMeshInstanced(*this, material, transforms, instances);
}
/**
* Export mesh data to file
*
* @throws raylib::RaylibException Throws if failed to export the Mesh.
*/
inline void Export(const std::string& fileName) {
if (!::ExportMesh(*this, fileName.c_str())) {
throw new RaylibException("Failed to export the Mesh");
}
}
/**
* Unload mesh from memory (RAM and/or VRAM)
*/
inline void Unload() {
if (vboId != nullptr) {
::UnloadMesh(*this);
vboId = nullptr;
}
}
/**
* Compute mesh bounding box limits
*/
inline raylib::BoundingBox BoundingBox() const {
return ::GetMeshBoundingBox(*this);
}
/**
* Compute mesh bounding box limits
*/
operator raylib::BoundingBox() {
return BoundingBox();
}
/**
* Compute mesh tangents
*/
inline Mesh& GenTangents() {
::GenMeshTangents(this);
return *this;
}
/**
* Load model from generated mesh
*/
inline raylib::Model LoadModelFrom() const {
return ::LoadModelFromMesh(*this);
}
/**
* Load model from generated mesh
*/
operator raylib::Model() {
return ::LoadModelFromMesh(*this);
}
protected:
void set(const ::Mesh& mesh) {
vertexCount = mesh.vertexCount;
triangleCount = mesh.triangleCount;
vertices = mesh.vertices;
texcoords = mesh.texcoords;
texcoords2 = mesh.texcoords2;
normals = mesh.normals;
tangents = mesh.tangents;
colors = mesh.colors;
indices = mesh.indices;
animVertices = mesh.animVertices;
animNormals = mesh.animNormals;
boneIds = mesh.boneIds;
boneWeights = mesh.boneWeights;
vaoId = mesh.vaoId;
vboId = mesh.vboId;
}
};
} // namespace raylib
using RMesh = raylib::Mesh;
#endif // RAYLIB_CPP_INCLUDE_MESH_HPP_

View File

@@ -0,0 +1,243 @@
#ifndef RAYLIB_CPP_INCLUDE_MODEL_HPP_
#define RAYLIB_CPP_INCLUDE_MODEL_HPP_
#include <string>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./RaylibException.hpp"
namespace raylib {
class Mesh;
/**
* Model type
*/
class Model : public ::Model {
public:
Model() {
// Nothing.
}
/*
* Copy a model from another model.
*/
Model(const ::Model& model) {
set(model);
}
/*
* Load a model from a file.
*
* @throws raylib::RaylibException Throws if failed to load the Modal.
*/
Model(const std::string& fileName) {
Load(fileName);
}
/*
* Load a model from a mesh.
*
* @throws raylib::RaylibException Throws if failed to load the Modal.
*/
Model(const ::Mesh& mesh) {
Load(mesh);
}
~Model() {
Unload();
}
Model(const Model&) = delete;
Model(Model&& other) {
set(other);
other.meshCount = 0;
other.materialCount = 0;
other.meshes = nullptr;
other.materials = nullptr;
other.meshMaterial = nullptr;
other.boneCount = 0;
other.bones = nullptr;
other.bindPose = nullptr;
}
GETTERSETTER(::Matrix, Transform, transform)
GETTERSETTER(int, MeshCount, meshCount)
GETTERSETTER(int, MaterialCount, materialCount)
GETTERSETTER(::Mesh*, Meshes, meshes)
GETTERSETTER(::Material*, Materials, materials)
GETTERSETTER(int*, MeshMaterial, meshMaterial)
GETTERSETTER(int, BoneCount, boneCount)
GETTERSETTER(::BoneInfo*, Bones, bones)
GETTERSETTER(::Transform*, BindPose, bindPose)
Model& operator=(const ::Model& model) {
set(model);
return *this;
}
Model& operator=(const Model&) = delete;
Model& operator=(Model&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.meshCount = 0;
other.materialCount = 0;
other.meshes = nullptr;
other.materials = nullptr;
other.meshMaterial = nullptr;
other.boneCount = 0;
other.bones = nullptr;
other.bindPose = nullptr;
return *this;
}
/**
* Unload model (including meshes) from memory (RAM and/or VRAM)
*/
inline void Unload() {
if (meshes != nullptr || materials != nullptr) {
::UnloadModel(*this);
meshes = nullptr;
materials = nullptr;
}
}
/**
* Set material for a mesh
*/
inline Model& SetMeshMaterial(int meshId, int materialId) {
::SetModelMeshMaterial(this, meshId, materialId);
return *this;
}
/**
* Update model animation pose
*/
inline Model& UpdateAnimation(const ::ModelAnimation& anim, int frame) {
::UpdateModelAnimation(*this, anim, frame);
return *this;
}
/**
* Check model animation skeleton match
*/
inline bool IsModelAnimationValid(const ::ModelAnimation& anim) const {
return ::IsModelAnimationValid(*this, anim);
}
/**
* Draw a model (with texture if set)
*/
inline void Draw(::Vector3 position,
float scale = 1.0f,
::Color tint = {255, 255, 255, 255}) const {
::DrawModel(*this, position, scale, tint);
}
/**
* Draw a model with extended parameters
*/
inline void Draw(
::Vector3 position,
::Vector3 rotationAxis,
float rotationAngle = 0.0f,
::Vector3 scale = {1.0f, 1.0f, 1.0f},
::Color tint = {255, 255, 255, 255}) const {
::DrawModelEx(*this, position, rotationAxis, rotationAngle, scale, tint);
}
/**
* Draw a model wires (with texture if set)
*/
inline void DrawWires(::Vector3 position,
float scale = 1.0f,
::Color tint = {255, 255, 255, 255}) const {
::DrawModelWires(*this, position, scale, tint);
}
/**
* Draw a model wires (with texture if set) with extended parameters
*/
inline void DrawWires(
::Vector3 position,
::Vector3 rotationAxis,
float rotationAngle = 0.0f,
::Vector3 scale = {1.0f, 1.0f, 1.0f},
::Color tint = {255, 255, 255, 255}) const {
::DrawModelWiresEx(*this, position, rotationAxis, rotationAngle, scale, tint);
}
/**
* Compute model bounding box limits (considers all meshes)
*/
inline BoundingBox GetBoundingBox() const {
return ::GetModelBoundingBox(*this);
}
/**
* Compute model bounding box limits (considers all meshes)
*/
operator BoundingBox() const {
return ::GetModelBoundingBox(*this);
}
/**
* Determines whether or not the Model has data in it.
*/
bool IsReady() const {
return ::IsModelReady(*this);
}
/**
* Loads a Model from the given file.
*
* @throws raylib::RaylibException Throws if failed to load the Modal.
*/
void Load(const std::string& fileName) {
set(::LoadModel(fileName.c_str()));
if (!IsReady()) {
throw RaylibException("Failed to load Model from " + fileName);
}
}
/**
* Loads a Model from the given Mesh.
*
* @throws raylib::RaylibException Throws if failed to load the Modal.
*/
void Load(const ::Mesh& mesh) {
set(::LoadModelFromMesh(mesh));
if (!IsReady()) {
throw RaylibException("Failed to load Model from Mesh");
}
}
protected:
void set(const ::Model& model) {
transform = model.transform;
meshCount = model.meshCount;
materialCount = model.materialCount;
meshes = model.meshes;
materials = model.materials;
meshMaterial = model.meshMaterial;
boneCount = model.boneCount;
bones = model.bones;
bindPose = model.bindPose;
}
};
} // namespace raylib
using RModel = raylib::Model;
#endif // RAYLIB_CPP_INCLUDE_MODEL_HPP_

View File

@@ -0,0 +1,111 @@
#ifndef RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
#define RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
#include <vector>
#include <string>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./Mesh.hpp"
namespace raylib {
/**
* Model animation
*/
class ModelAnimation : public ::ModelAnimation {
public:
ModelAnimation(const ::ModelAnimation& model) {
set(model);
}
ModelAnimation(const ModelAnimation&) = delete;
ModelAnimation(ModelAnimation&& other) {
set(other);
other.boneCount = 0;
other.frameCount = 0;
other.bones = nullptr;
other.framePoses = nullptr;
}
~ModelAnimation() {
Unload();
}
/**
* Load model animations from file
*/
static std::vector<ModelAnimation> Load(const std::string& fileName) {
int count = 0;
::ModelAnimation* modelAnimations = ::LoadModelAnimations(fileName.c_str(), &count);
std::vector<ModelAnimation> mats(modelAnimations, modelAnimations + count);
RL_FREE(modelAnimations);
return mats;
}
GETTERSETTER(int, BoneCount, boneCount)
GETTERSETTER(::BoneInfo*, Bones, bones)
GETTERSETTER(int, FrameCount, frameCount)
GETTERSETTER(::Transform**, FramePoses, framePoses)
ModelAnimation& operator=(const ::ModelAnimation& model) {
set(model);
return *this;
}
ModelAnimation& operator=(const ModelAnimation&) = delete;
ModelAnimation& operator=(ModelAnimation&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.boneCount = 0;
other.frameCount = 0;
other.bones = nullptr;
other.framePoses = nullptr;
return *this;
}
/**
* Unload animation data
*/
inline void Unload() {
::UnloadModelAnimation(*this);
}
/**
* Update model animation pose
*/
inline ModelAnimation& Update(const ::Model& model, int frame) {
::UpdateModelAnimation(model, *this, frame);
return *this;
}
/**
* Check model animation skeleton match
*/
inline bool IsValid(const ::Model& model) const {
return ::IsModelAnimationValid(model, *this);
}
protected:
void set(const ::ModelAnimation& model) {
boneCount = model.boneCount;
frameCount = model.frameCount;
bones = model.bones;
framePoses = model.framePoses;
}
};
} // namespace raylib
using RModelAnimation = raylib::ModelAnimation;
#endif // RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_

View File

@@ -0,0 +1,153 @@
#ifndef RAYLIB_CPP_INCLUDE_MOUSE_HPP_
#define RAYLIB_CPP_INCLUDE_MOUSE_HPP_
#include "./raylib.hpp"
#include "./Vector2.hpp"
namespace raylib {
/**
* Input-related functions: mouse
*/
class Mouse {
public:
/**
* Detect if a mouse button has been pressed once
*/
static inline bool IsButtonPressed(int button) {
return ::IsMouseButtonPressed(button);
}
/**
* Detect if a mouse button is being pressed
*/
static inline bool IsButtonDown(int button) {
return ::IsMouseButtonDown(button);
}
/**
* Detect if a mouse button has been released once
*/
static inline bool IsButtonReleased(int button) {
return ::IsMouseButtonReleased(button);
}
static inline bool IsButtonUp(int button) {
return ::IsMouseButtonUp(button);
}
static inline int GetX() {
return ::GetMouseX();
}
static inline int GetY() {
return ::GetMouseY();
}
static inline void SetX(int x) {
::SetMousePosition(x, GetY());
}
static inline void SetY(int y) {
::SetMousePosition(GetX(), y);
}
static inline Vector2 GetPosition() {
return ::GetMousePosition();
}
static inline void SetPosition(int x, int y) {
::SetMousePosition(x, y);
}
static inline void SetPosition(::Vector2 position) {
::SetMousePosition(static_cast<int>(position.x), static_cast<int>(position.y));
}
/**
* Get mouse delta between frames
*/
static inline Vector2 GetDelta() {
return ::GetMouseDelta();
}
static inline void SetOffset(int offsetX = 0, int offsetY = 0) {
::SetMouseOffset(offsetX, offsetY);
}
static inline void SetOffset(::Vector2 offset) {
::SetMouseOffset(static_cast<int>(offset.x), static_cast<int>(offset.y));
}
static inline void SetScale(float scaleX = 1.0f, float scaleY = 1.0f) {
::SetMouseScale(scaleX, scaleY);
}
static inline void SetScale(::Vector2 scale) {
::SetMouseScale(scale.x, scale.y);
}
/**
* Get mouse wheel movement for X or Y, whichever is larger
*/
static inline float GetWheelMove() {
return ::GetMouseWheelMove();
}
/**
* Get mouse wheel movement for both X and Y
*
* @see ::GetMouseWheelMoveV()
*/
static inline Vector2 GetWheelMoveV() {
return GetMouseWheelMoveV();
}
/**
* Sets the current mouse cursor icon.
*
* @see ::MouseCursor
*/
static inline void SetCursor(int cursor = MOUSE_CURSOR_DEFAULT) {
::SetMouseCursor(cursor);
}
/**
* Get touch position X for touch point 0 (relative to screen size)
*/
static inline int GetTouchX() {
return ::GetTouchX();
}
/**
* Get touch position Y for touch point 0 (relative to screen size)
*/
static inline int GetTouchY() {
return ::GetTouchY();
}
/**
* Get touch position XY for a touch point index (relative to screen size)
*/
static inline Vector2 GetTouchPosition(int index) {
return ::GetTouchPosition(index);
}
/**
* Get a ray trace from mouse position
*/
static inline Ray GetRay(::Vector2 mousePosition, const ::Camera& camera) {
return ::GetMouseRay(mousePosition, camera);
}
/**
* Get a ray trace from mouse position
*/
static inline Ray GetRay(const ::Camera& camera) {
return ::GetMouseRay(::GetMousePosition(), camera);
}
};
} // namespace raylib
using RMouse = raylib::Mouse;
#endif // RAYLIB_CPP_INCLUDE_MOUSE_HPP_

View File

@@ -0,0 +1,239 @@
#ifndef RAYLIB_CPP_INCLUDE_MUSIC_HPP_
#define RAYLIB_CPP_INCLUDE_MUSIC_HPP_
#include <string>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./RaylibException.hpp"
namespace raylib {
/**
* Music stream type (audio file streaming from memory)
*/
class Music : public ::Music {
public:
Music(::AudioStream stream = {nullptr, nullptr, 0, 0, 0},
unsigned int frameCount = 0,
bool looping = false,
int ctxType = 0,
void *ctxData = nullptr) : ::Music{stream, frameCount, looping, ctxType, ctxData} {}
Music(const ::Music& music) {
set(music);
}
/**
* Load music stream from file
*
* @throws raylib::RaylibException Throws if the music failed to load.
*/
Music(const std::string& fileName) {
Load(fileName);
}
/**
* Load music stream from memory
*
* @throws raylib::RaylibException Throws if the music failed to load.
*/
Music(const std::string& fileType, unsigned char* data, int dataSize) {
Load(fileType, data, dataSize);
}
Music(const Music&) = delete;
Music(Music&& other) {
set(other);
other.stream = {};
other.frameCount = 0;
other.looping = false;
other.ctxType = 0;
other.ctxData = nullptr;
}
/**
* Unload music stream
*/
~Music() {
Unload();
}
GETTERSETTER(::AudioStream, Stream, stream)
GETTERSETTER(unsigned int, FrameCount, frameCount)
GETTERSETTER(bool, Looping, looping)
GETTERSETTER(int, CtxType, ctxType)
GETTERSETTER(void*, CtxData, ctxData)
Music& operator=(const ::Music& music) {
set(music);
return *this;
}
Music& operator=(const Music&) = delete;
Music& operator=(Music&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.ctxType = 0;
other.ctxData = nullptr;
other.looping = false;
other.frameCount = 0;
other.stream = {};
return *this;
}
/**
* Unload music stream
*/
inline void Unload() {
::UnloadMusicStream(*this);
}
/**
* Start music playing
*/
inline Music& Play() {
::PlayMusicStream(*this);
return *this;
}
/**
* Updates buffers for music streaming
*/
inline Music& Update() {
::UpdateMusicStream(*this);
return *this;
}
/**
* Stop music playing
*/
inline Music& Stop() {
::StopMusicStream(*this);
return *this;
}
/**
* Pause music playing
*/
inline Music& Pause() {
::PauseMusicStream(*this);
return *this;
}
/**
* Resume music playing
*/
inline Music& Resume() {
::ResumeMusicStream(*this);
return *this;
}
/**
* Seek music to a position (in seconds)
*/
inline Music& Seek(float position) {
SeekMusicStream(*this, position);
return *this;
}
/**
* Check if music is playing
*/
inline bool IsPlaying() const {
return ::IsMusicStreamPlaying(*this);
}
/**
* Set volume for music
*/
inline Music& SetVolume(float volume) {
::SetMusicVolume(*this, volume);
return *this;
}
/**
* Set pitch for music
*/
inline Music& SetPitch(float pitch) {
::SetMusicPitch(*this, pitch);
return *this;
}
/**
* Set pan for a music (0.5 is center)
*/
inline Music& SetPan(float pan = 0.5f) {
::SetMusicPan(*this, pan);
return *this;
}
/**
* Get music time length (in seconds)
*/
inline float GetTimeLength() const {
return ::GetMusicTimeLength(*this);
}
/**
* Get current music time played (in seconds)
*/
inline float GetTimePlayed() const {
return ::GetMusicTimePlayed(*this);
}
/**
* Load music stream from file
*
* @throws raylib::RaylibException Throws if the music failed to load.
*/
void Load(const std::string& fileName) {
set(::LoadMusicStream(fileName.c_str()));
if (!IsReady()) {
throw RaylibException(TextFormat("Failed to load Music from file: %s", fileName.c_str()));
}
}
/**
* Load music stream from memory
*
* @throws raylib::RaylibException Throws if the music failed to load.
*/
void Load(const std::string& fileType, unsigned char* data, int dataSize) {
set(::LoadMusicStreamFromMemory(fileType.c_str(), data, dataSize));
if (!IsReady()) {
throw RaylibException(TextFormat("Failed to load Music from %s file dat", fileType.c_str()));
}
}
/**
* Retrieve whether or not the Music has been loaded.
*
* @return True or false depending on whether the Music has been loaded.
*/
inline bool IsReady() const {
return ::IsMusicReady(*this);
}
protected:
void set(const ::Music& music) {
stream = music.stream;
frameCount = music.frameCount;
looping = music.looping;
ctxType = music.ctxType;
ctxData = music.ctxData;
}
};
} // namespace raylib
using RMusic = raylib::Music;
#endif // RAYLIB_CPP_INCLUDE_MUSIC_HPP_

101
includes/raylib-cpp/Ray.hpp Normal file
View File

@@ -0,0 +1,101 @@
#ifndef RAYLIB_CPP_INCLUDE_RAY_HPP_
#define RAYLIB_CPP_INCLUDE_RAY_HPP_
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./RayCollision.hpp"
namespace raylib {
/**
* Ray type (useful for raycast)
*/
class Ray : public ::Ray {
public:
Ray(const ::Ray& ray) {
set(ray);
}
Ray(::Vector3 position = {0.0f, 0.0f, 0.0f}, ::Vector3 direction = {0.0f, 0.0f, 0.0f}) :
::Ray{position, direction} {
// Nothing.
}
Ray(::Vector2 mousePosition, const ::Camera& camera) {
set(::GetMouseRay(mousePosition, camera));
}
Ray& operator=(const ::Ray& ray) {
set(ray);
return *this;
}
GETTERSETTER(::Vector3, Position, position)
GETTERSETTER(::Vector3, Direction, direction)
/**
* Draw a ray line
*/
inline void Draw(::Color color) const {
DrawRay(*this, color);
}
/**
* Get collision information between ray and sphere
*/
inline RayCollision GetCollision(::Vector3 center, float radius) const {
return ::GetRayCollisionSphere(*this, center, radius);
}
/**
* Detect collision between ray and box
*/
inline RayCollision GetCollision(const ::BoundingBox& box) const {
return ::GetRayCollisionBox(*this, box);
}
/**
* Get collision information between ray and mesh
*/
inline RayCollision GetCollision(const ::Mesh& mesh, const ::Matrix& transform) const {
return ::GetRayCollisionMesh(*this, mesh, transform);
}
/**
* Get collision info between ray and triangle
*/
inline RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const {
return ::GetRayCollisionTriangle(*this, p1, p2, p3);
}
/**
* Get collision info between ray and quad
*/
inline RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3, ::Vector3 p4) const {
return ::GetRayCollisionQuad(*this, p1, p2, p3, p4);
}
/**
* Get a ray trace from mouse position
*/
inline static Ray GetMouse(::Vector2 mousePosition, const ::Camera& camera) {
return ::GetMouseRay(mousePosition, camera);
}
/**
* Get a ray trace from mouse position
*/
inline static Ray GetMouse(const ::Camera& camera) {
return ::GetMouseRay(::GetMousePosition(), camera);
}
protected:
inline void set(const ::Ray& ray) {
position = ray.position;
direction = ray.direction;
}
};
} // namespace raylib
using RRay = raylib::Ray;
#endif // RAYLIB_CPP_INCLUDE_RAY_HPP_

View File

@@ -0,0 +1,79 @@
#ifndef RAYLIB_CPP_INCLUDE_RAYCOLLISION_HPP_
#define RAYLIB_CPP_INCLUDE_RAYCOLLISION_HPP_
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* Raycast hit information
*/
class RayCollision : public ::RayCollision {
public:
RayCollision(const ::RayCollision& ray) {
set(ray);
}
RayCollision(bool hit, float distance,
::Vector3 point, ::Vector3 normal) : ::RayCollision{hit, distance, point, normal} {
// Nothing.
}
/**
* Get collision info between ray and bounding box
*/
RayCollision(const ::Ray& ray, const ::BoundingBox& box) {
set(::GetRayCollisionBox(ray, box));
}
/**
* Get collision info between ray and mesh
*/
RayCollision(const ::Ray& ray, const ::Mesh& mesh, const ::Matrix& transform) {
set(::GetRayCollisionMesh(ray, mesh, transform));
}
/**
* Get collision info between ray and quad
*/
RayCollision(const ::Ray& ray, ::Vector3 p1, ::Vector3 p2, ::Vector3 p3, ::Vector3 p4) {
set(::GetRayCollisionQuad(ray, p1, p2, p3, p4));
}
/**
* Get collision info between ray and sphere
*/
RayCollision(const ::Ray& ray, ::Vector3 center, float radius) {
set(::GetRayCollisionSphere(ray, center, radius));
}
/**
* Get collision info between ray and triangle
*/
RayCollision(const ::Ray& ray, ::Vector3 p1, ::Vector3 p2, ::Vector3 p3) {
set(::GetRayCollisionTriangle(ray, p1, p2, p3));
}
RayCollision& operator=(const ::RayCollision& ray) {
set(ray);
return *this;
}
GETTERSETTER(bool, Hit, hit)
GETTERSETTER(float, Distance, distance)
GETTERSETTER(::Vector3, Position, point)
GETTERSETTER(::Vector3, Normal, normal)
protected:
void set(const ::RayCollision& ray) {
hit = ray.hit;
distance = ray.distance;
point = ray.point;
normal = ray.normal;
}
};
} // namespace raylib
using RRayCollision = raylib::RayCollision;
#endif // RAYLIB_CPP_INCLUDE_RAYCOLLISION_HPP_

View File

@@ -0,0 +1,38 @@
#ifndef RAYLIB_CPP_INCLUDE_RAYLIBEXCEPTION_HPP_
#define RAYLIB_CPP_INCLUDE_RAYLIBEXCEPTION_HPP_
#include <stdexcept>
#include <string>
#include "./raylib.hpp"
namespace raylib {
/**
* Exception used for most raylib-related exceptions.
*/
class RaylibException : public std::runtime_error {
public:
/**
* Construct a runtime exception with the given message.
*
* @param message The message to provide for the exception.
*/
RaylibException(std::string message) throw() : std::runtime_error(message) {
// Nothing
}
/**
* Outputs the exception message to TraceLog().
*
* @param logLevel The output status to use when outputing.
*/
void TraceLog(int logLevel = LOG_ERROR) {
::TraceLog(logLevel, std::runtime_error::what());
}
};
} // namespace raylib
using RRaylibException = raylib::RaylibException;
#endif // RAYLIB_CPP_INCLUDE_RAYLIBEXCEPTION_HPP_

View File

@@ -0,0 +1,161 @@
#ifndef RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
#define RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./Vector2.hpp"
namespace raylib {
/**
* Rectangle type
*/
class Rectangle : public ::Rectangle {
public:
Rectangle(const ::Rectangle& rect) : ::Rectangle{rect.x, rect.y, rect.width, rect.height} {}
Rectangle(float x, float y, float width, float height) : ::Rectangle{x, y, width, height} {}
Rectangle(float x, float y, float width) : ::Rectangle{x, y, width, 0} {}
Rectangle(float x, float y) : ::Rectangle{x, y, 0, 0} {}
Rectangle(float x) : ::Rectangle{x, 0, 0, 0} {}
Rectangle() : ::Rectangle{0, 0, 0, 0} {}
Rectangle(::Vector2 position, ::Vector2 size)
: ::Rectangle{position.x, position.y, size.x, size.y} {}
Rectangle(::Vector2 size) : ::Rectangle{0, 0, size.x, size.y} {}
Rectangle(::Vector4 rect) : ::Rectangle{rect.x, rect.y, rect.z, rect.w} {}
GETTERSETTER(float, X, x)
GETTERSETTER(float, Y, y)
GETTERSETTER(float, Width, width)
GETTERSETTER(float, Height, height)
Rectangle& operator=(const ::Rectangle& rect) {
set(rect);
return *this;
}
inline ::Vector4 ToVector4() {
return {x, y, width, height};
}
operator ::Vector4() const {
return {x, y, width, height};
}
/**
* Draw a color-filled rectangle
*/
inline void Draw(::Color color) const {
::DrawRectangleRec(*this, color);
}
inline void Draw(::Vector2 origin, float rotation, ::Color color) const {
::DrawRectanglePro(*this, origin, rotation, color);
}
inline void DrawGradientV(::Color color1, ::Color color2) const {
::DrawRectangleGradientV(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
static_cast<int>(height), color1, color2);
}
inline void DrawGradientH(::Color color1, ::Color color2) const {
::DrawRectangleGradientH(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
static_cast<int>(height), color1, color2);
}
inline void DrawGradient(::Color col1, ::Color col2, ::Color col3, ::Color col4) const {
::DrawRectangleGradientEx(*this, col1, col2, col3, col4);
}
inline void DrawLines(::Color color) const {
::DrawRectangleLines(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
static_cast<int>(height), color);
}
inline void DrawLines(::Color color, float lineThick) const {
::DrawRectangleLinesEx(*this, lineThick, color);
}
inline void DrawRounded(float roundness, int segments, ::Color color) const {
::DrawRectangleRounded(*this, roundness, segments, color);
}
inline void DrawRoundedLines(float roundness, int segments,
float lineThick, ::Color color) const {
::DrawRectangleRoundedLines(*this, roundness, segments, lineThick, color);
}
/**
* Check collision between two rectangles
*/
inline bool CheckCollision(::Rectangle rec2) const {
return ::CheckCollisionRecs(*this, rec2);
}
/**
* Get collision rectangle for two rectangles collision
*/
inline ::Rectangle GetCollision(::Rectangle rec2) const {
return ::GetCollisionRec(*this, rec2);
}
/**
* Check if point is inside rectangle
*/
inline bool CheckCollision(::Vector2 point) const {
return ::CheckCollisionPointRec(point, *this);
}
/**
* Check collision between circle and rectangle
*/
inline bool CheckCollision(::Vector2 center, float radius) const {
return ::CheckCollisionCircleRec(center, radius, *this);
}
inline Vector2 GetSize() const {
return {width, height};
}
inline Rectangle& SetSize(float newWidth, float newHeight) {
width = newWidth;
height = newHeight;
return *this;
}
inline Rectangle& SetSize(const ::Vector2& size) {
return SetSize(size.x, size.y);
}
inline Rectangle& SetShapesTexture(const ::Texture2D& texture) {
::SetShapesTexture(texture, *this);
return *this;
}
inline Vector2 GetPosition() const {
return {x, y};
}
inline Rectangle& SetPosition(float newX, float newY) {
x = newX;
y = newY;
return *this;
}
inline Rectangle& SetPosition(const ::Vector2& position) {
return SetPosition(position.x, position.y);
}
protected:
void set(const ::Rectangle& rect) {
x = rect.x;
y = rect.y;
width = rect.width;
height = rect.height;
}
};
} // namespace raylib
using RRectangle = raylib::Rectangle;
#endif // RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_

View File

@@ -0,0 +1,143 @@
#ifndef RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
#define RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./RaylibException.hpp"
#include "./TextureUnmanaged.hpp"
namespace raylib {
/**
* RenderTexture type, for texture rendering
*/
class RenderTexture : public ::RenderTexture {
public:
/**
* Default constructor to build an empty RenderTexture.
*/
RenderTexture() {
id = 0;
}
RenderTexture(const ::RenderTexture& renderTexture) {
set(renderTexture);
}
RenderTexture(unsigned int id, const ::Texture& texture, const ::Texture& depth) :
::RenderTexture{id, texture, depth} {}
/**
* Load texture for rendering (framebuffer)
*/
RenderTexture(int width, int height) {
set(::LoadRenderTexture(width, height));
}
RenderTexture(const RenderTexture&) = delete;
RenderTexture(RenderTexture&& other) {
set(other);
other.id = 0;
other.texture = {};
other.depth = {};
}
GETTERSETTER(unsigned int, Id, id)
/**
* Get the color buffer attachment texture.
*/
inline TextureUnmanaged GetTexture() {
return texture;
}
inline void SetTexture(const ::Texture& newTexture) {
texture = newTexture;
}
/**
* Depth buffer attachment texture
*/
inline TextureUnmanaged GetDepth() {
return depth;
}
inline void SetDepth(const ::Texture& newDepth) {
depth = newDepth;
}
RenderTexture& operator=(const ::RenderTexture& texture) {
set(texture);
return *this;
}
RenderTexture& operator=(const RenderTexture&) = delete;
RenderTexture& operator=(RenderTexture&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.id = 0;
other.texture = {};
other.depth = {};
return *this;
}
~RenderTexture() {
Unload();
}
inline void Unload() {
UnloadRenderTexture(*this);
}
/**
* Initializes render texture for drawing
*/
inline RenderTexture& BeginMode() {
::BeginTextureMode(*this);
return *this;
}
/**
* Ends drawing to render texture
*/
inline RenderTexture& EndMode() {
::EndTextureMode();
return *this;
}
/**
* Load texture for rendering (framebuffer)
*/
static RenderTexture Load(int width, int height) {
return ::LoadRenderTexture(width, height);
}
/**
* Retrieves whether or not the render texture is ready.
*/
inline bool IsReady() const {
return ::IsRenderTextureReady(*this);
}
protected:
void set(const ::RenderTexture& renderTexture) {
id = renderTexture.id;
texture = renderTexture.texture;
depth = renderTexture.depth;
}
};
typedef RenderTexture RenderTexture2D;
} // namespace raylib
using RRenderTexture = raylib::RenderTexture;
using RRenderTexture2D = raylib::RenderTexture2D;
#endif // RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_

View File

@@ -0,0 +1,196 @@
#ifndef RAYLIB_CPP_INCLUDE_SHADER_HPP_
#define RAYLIB_CPP_INCLUDE_SHADER_HPP_
#include <string>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "Texture.hpp"
namespace raylib {
/**
* Shader type (generic)
*/
class Shader : public ::Shader {
public:
Shader(const ::Shader& shader) {
set(shader);
}
Shader(unsigned int id, int* locs = nullptr) : ::Shader{id, locs} {}
Shader(const std::string& vsFileName, const std::string& fsFileName) {
set(::LoadShader(vsFileName.c_str(), fsFileName.c_str()));
}
Shader(const char* vsFileName, const char* fsFileName) {
set(::LoadShader(vsFileName, fsFileName));
}
Shader(const Shader&) = delete;
Shader(Shader&& other) {
set(other);
other.id = 0;
other.locs = nullptr;
}
/**
* Load shader from files and bind default locations.
*
* @see ::LoadShader
*/
static ::Shader Load(const std::string& vsFileName, const std::string& fsFileName) {
return ::LoadShader(vsFileName.c_str(), fsFileName.c_str());
}
static ::Shader Load(const char* vsFileName, const char* fsFileName) {
return ::LoadShader(vsFileName, fsFileName);
}
/**
* Load a shader from memory.
*
* @see ::LoadShaderFromMemory
*/
static ::Shader LoadFromMemory(const std::string& vsCode, const std::string& fsCode) {
return ::LoadShaderFromMemory(vsCode.c_str(), fsCode.c_str());
}
static ::Shader LoadFromMemory(const char* vsCode, const char* fsCode) {
return ::LoadShaderFromMemory(vsCode, fsCode);
}
GETTERSETTER(unsigned int, Id, id)
GETTERSETTER(int*, Locs, locs)
Shader& operator=(const ::Shader& shader) {
set(shader);
return *this;
}
Shader& operator=(const Shader&) = delete;
Shader& operator=(Shader&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.id = 0;
other.locs = nullptr;
return *this;
}
/**
* Unload shader from GPU memory (VRAM)
*/
~Shader() {
Unload();
}
/**
* Unload shader from GPU memory (VRAM)
*/
void Unload() {
if (locs != nullptr) {
::UnloadShader(*this);
}
}
/**
* Begin custom shader drawing.
*/
inline Shader& BeginMode() {
::BeginShaderMode(*this);
return *this;
}
/**
* End custom shader drawing (use default shader).
*/
inline Shader& EndMode() {
::EndShaderMode();
return *this;
}
/**
* Get shader uniform location
*
* @see GetShaderLocation()
*/
inline int GetLocation(const std::string& uniformName) const {
return ::GetShaderLocation(*this, uniformName.c_str());
}
/**
* Get shader attribute location
*
* @see GetShaderLocationAttrib()
*/
inline int GetLocationAttrib(const std::string& attribName) const {
return ::GetShaderLocationAttrib(*this, attribName.c_str());
}
/**
* Set shader uniform value
*
* @see SetShaderValue()
*/
inline Shader& SetValue(int uniformLoc, const void* value, int uniformType) {
::SetShaderValue(*this, uniformLoc, value, uniformType);
return *this;
}
/**
* Set shader uniform value vector
*
* @see SetShaderValueV()
*/
inline Shader& SetValue(int uniformLoc, const void* value, int uniformType, int count) {
::SetShaderValueV(*this, uniformLoc, value, uniformType, count);
return *this;
}
/**
* Set shader uniform value (matrix 4x4)
*
* @see SetShaderValueMatrix()
*/
inline Shader& SetValue(int uniformLoc, const ::Matrix& mat) {
::SetShaderValueMatrix(*this, uniformLoc, mat);
return *this;
}
/**
* Set shader uniform value for texture
*
* @see SetShaderValueTexture()
*/
inline Shader& SetValue(int uniformLoc, const ::Texture2D& texture) {
::SetShaderValueTexture(*this, uniformLoc, texture);
return *this;
}
/**
* Retrieves whether or not the shader is ready.
*/
bool IsReady() const {
return id != 0 && locs != nullptr;
}
protected:
void set(const ::Shader& shader) {
id = shader.id;
locs = shader.locs;
}
};
} // namespace raylib
using RShader = raylib::Shader;
#endif // RAYLIB_CPP_INCLUDE_SHADER_HPP_

View File

@@ -0,0 +1,211 @@
#ifndef RAYLIB_CPP_INCLUDE_SOUND_HPP_
#define RAYLIB_CPP_INCLUDE_SOUND_HPP_
#include <string>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./RaylibException.hpp"
namespace raylib {
/**
* Wave/Sound management functions
*
* @code
* raylib::Sound boom("boom.wav");
* boom.Play();
* @endcode
*/
class Sound : public ::Sound {
public:
Sound(const Sound&) = delete;
Sound& operator=(const Sound&) = delete;
Sound() {
stream = { nullptr, nullptr, 0, 0, 0 };
frameCount = 0;
}
Sound(::AudioStream stream, unsigned int frameCount) : ::Sound{stream, frameCount} {
// Nothing.
}
Sound(Sound&& other) {
set(other);
other.stream = { nullptr, nullptr, 0, 0, 0 };
other.frameCount = 0;
}
/**
* Loads a sound from the given file.
*
* @throws raylib::RaylibException Throws if the Sound failed to load.
*/
Sound(const std::string& fileName) {
Load(fileName);
}
/**
* Loads a sound from the given Wave.
*
* @throws raylib::RaylibException Throws if the Sound failed to load.
*/
Sound(const ::Wave& wave) {
Load(wave);
}
~Sound() {
Unload();
}
GETTERSETTER(unsigned int, FrameCount, frameCount)
GETTERSETTER(::AudioStream, Stream, stream)
Sound& operator=(Sound&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.frameCount = 0;
other.stream = { nullptr, nullptr, 0, 0, 0 };
return *this;
}
/**
* Update sound buffer with new data
*/
inline Sound& Update(const void *data, int samplesCount) {
::UpdateSound(*this, data, samplesCount);
return *this;
}
/**
* Update sound buffer with new data, assuming it's the same sample count.
*/
inline Sound& Update(const void *data) {
::UpdateSound(*this, data, static_cast<int>(frameCount));
return *this;
}
/**
* Unload sound
*/
inline void Unload() {
// Protect against calling UnloadSound() twice.
if (frameCount != 0) {
::UnloadSound(*this);
frameCount = 0;
}
}
/**
* Play a sound
*/
inline Sound& Play() {
::PlaySound(*this);
return *this;
}
/**
* Stop playing a sound
*/
inline Sound& Stop() {
::StopSound(*this);
return *this;
}
/**
* Pause a sound
*/
inline Sound& Pause() {
::PauseSound(*this);
return *this;
}
/**
* Resume a paused sound
*/
inline Sound& Resume() {
::ResumeSound(*this);
return *this;
}
/**
* Check if a sound is currently playing
*/
inline bool IsPlaying() const {
return ::IsSoundPlaying(*this);
}
/**
* Set volume for a sound (1.0 is max level)
*/
inline Sound& SetVolume(float volume) {
::SetSoundVolume(*this, volume);
return *this;
}
/**
* Set pitch for a sound (1.0 is base level)
*/
inline Sound& SetPitch(float pitch) {
::SetSoundPitch(*this, pitch);
return *this;
}
/**
* Set pan for a sound (0.5 is center)
*/
inline Sound& SetPan(float pan = 0.5f) {
::SetSoundPan(*this, pan);
return *this;
}
/**
* Load a sound from the given file.
*
* @throws raylib::RaylibException Throws if the Sound failed to load.
*/
void Load(const std::string& fileName) {
set(::LoadSound(fileName.c_str()));
if (!IsReady()) {
throw new RaylibException("Failed to load Sound from file");
}
}
/**
* Loads the given Wave object into the Sound.
*
* @throws raylib::RaylibException Throws if the Sound failed to load.
*/
void Load(const ::Wave& wave) {
set(::LoadSoundFromWave(wave));
if (!IsReady()) {
throw new RaylibException("Failed to load Wave");
}
}
/**
* Retrieve whether or not the Sound buffer is loaded.
*
* @return True or false depending on whether the Sound buffer is loaded.
*/
bool IsReady() const {
return ::IsSoundReady(*this);
}
protected:
void set(const ::Sound& sound) {
frameCount = sound.frameCount;
stream = sound.stream;
}
};
} // namespace raylib
using RSound = raylib::Sound;
#endif // RAYLIB_CPP_INCLUDE_SOUND_HPP_

View File

@@ -0,0 +1,212 @@
#ifndef RAYLIB_CPP_INCLUDE_TEXT_HPP_
#define RAYLIB_CPP_INCLUDE_TEXT_HPP_
#include <string>
#include "./raylib.hpp"
#include "./RaylibException.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* Text Functions.
*/
class Text {
public:
/**
* The internal text.
*/
std::string text;
/**
* The size of the text.
*/
float fontSize;
/**
* The color of the text.
*/
::Color color;
/**
* The internal raylib font to use for the text.
*/
::Font font;
/**
* The character spacing for the text.
*/
float spacing;
/**
* Initializes a new Text object.
*
* @param text Text to initialize.
* @param fontSize The size of the text.
* @param color The color of the font.
* @param font Font to initialize.
* @param spacing The spacing of the text.
*/
Text(
const std::string& text = "",
float fontSize = 10,
const ::Color& color = WHITE,
const ::Font& font = ::GetFontDefault(),
float spacing = 0) :
text(text),
fontSize(fontSize),
color(color),
font(font),
spacing(spacing) {
// Nothing.
}
/**
* Initializes a new Text object with a custom font.
*
* @param font Font to initialize.
* @param text Text to initialize.
* @param fontSize The size of the text.
* @param spacing The spacing of the text.
* @param color The color of the font.
*/
Text(
const ::Font& font,
const std::string& text = "",
float fontSize = 10,
float spacing = 0,
const ::Color& color = WHITE) :
text(text),
fontSize(fontSize),
color(color),
font(font),
spacing(spacing) {
// Nothing.
}
GETTERSETTER(std::string, Text, text)
GETTERSETTER(float, FontSize, fontSize)
GETTERSETTER(::Font, Font, font)
GETTERSETTER(::Color, Color, color)
GETTERSETTER(float, Spacing, spacing)
/**
* Draw text with values in class.
*/
inline void Draw(const ::Vector2& position) const {
::DrawTextEx(font, text.c_str(), position, fontSize, spacing, color);
}
/**
* Draw text with values in class.
*/
inline void Draw(int posX, int posY) const {
::DrawTextEx(font,
text.c_str(),
{ static_cast<float>(posX), static_cast<float>(posY) },
fontSize,
spacing,
color);
}
/**
* Draw text using Font and pro parameters (rotation).
*
* @see DrawTextPro()
*/
inline void Draw(const ::Vector2& position, float rotation, const ::Vector2& origin = {0, 0}) const {
::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, color);
}
/**
* Measure string width for default font
*/
inline int Measure() const {
return ::MeasureText(text.c_str(), static_cast<int>(fontSize));
}
/**
* Measure string size for Font
*/
inline Vector2 MeasureEx() const {
return ::MeasureTextEx(font, text.c_str(), fontSize, spacing);
}
Text& operator=(const Text& other) {
if (this == &other) {
return *this;
}
text = other.text;
fontSize = other.fontSize;
color = other.color;
font = other.font;
spacing = other.spacing;
return *this;
}
/**
* Draw text using font and color
*
* @see ::DrawText
*/
static inline void Draw(
const std::string& text,
const int posX,
const int posY,
const int fontSize,
const ::Color& color) {
::DrawText(text.c_str(), posX, posY, fontSize, color);
}
/**
* Draw text using font and color, with position defined as Vector2
*
* @see ::DrawText
*/
static inline void Draw(
const std::string& text,
const ::Vector2& pos,
const int fontSize,
const ::Color& color) {
::DrawText(text.c_str(), static_cast<int>(pos.x), static_cast<int>(pos.y), fontSize, color);
}
/**
* Draw text using font, color, position, font size and spacing
*
* @see ::DrawTextEx
*/
static inline void Draw(
const ::Font& font,
const std::string& text,
const ::Vector2& position,
const float fontSize,
const float spacing,
const ::Color& color) {
::DrawTextEx(font, text.c_str(), position, fontSize, spacing, color);
}
/**
* Draw text using font, color, position, origin, font size and spacing
*
* @see ::DrawTextPro
*/
static inline void Draw(
const ::Font& font,
const std::string& text,
const ::Vector2& position,
const ::Vector2& origin,
const float rotation,
const float fontSize,
const float spacing,
const ::Color& color) {
::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, color);
}
};
} // namespace raylib
using RText = raylib::Text;
#endif // RAYLIB_CPP_INCLUDE_TEXT_HPP_

View File

@@ -0,0 +1,79 @@
#ifndef RAYLIB_CPP_INCLUDE_TEXTURE_HPP_
#define RAYLIB_CPP_INCLUDE_TEXTURE_HPP_
#include "./TextureUnmanaged.hpp"
namespace raylib {
/**
* Texture type
*
* The texture will be unloaded on object destruction. Use raylib::TextureUnmanaged if you're looking to not unload.
*
* @see raylib::TextureUnmanaged
*/
class Texture : public TextureUnmanaged {
public:
using TextureUnmanaged::TextureUnmanaged;
/**
* Explicitly forbid the copy constructor.
*/
Texture(const Texture&) = delete;
/**
* Explicitly forbid copy assignment.
*/
Texture& operator=(const Texture&) = delete;
/**
* Move constructor.
*/
Texture(Texture&& other) {
set(other);
other.id = 0;
other.width = 0;
other.height = 0;
other.mipmaps = 0;
other.format = 0;
}
/**
* On destruction, unload the Texture.
*/
~Texture() {
Unload();
}
/**
* Move assignment.
*/
Texture& operator=(Texture&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.id = 0;
other.width = 0;
other.height = 0;
other.mipmaps = 0;
other.format = 0;
return *this;
}
};
// Create the Texture aliases.
typedef Texture Texture2D;
typedef Texture TextureCubemap;
} // namespace raylib
using RTexture = raylib::Texture;
using RTexture2D = raylib::Texture2D;
using RTextureCubemap = raylib::TextureCubemap;
#endif // RAYLIB_CPP_INCLUDE_TEXTURE_HPP_

View File

@@ -0,0 +1,346 @@
#ifndef RAYLIB_CPP_INCLUDE_TEXTUREUNMANAGED_HPP_
#define RAYLIB_CPP_INCLUDE_TEXTUREUNMANAGED_HPP_
#include <string>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./Vector2.hpp"
#include "./Material.hpp"
#include "./RaylibException.hpp"
#include "./Image.hpp"
namespace raylib {
/**
* A Texture that is not managed by the C++ garbage collector.
*
* Make sure to Unload() this if needed, otherwise use raylib::Texture.
*
* @see raylib::Texture
*/
class TextureUnmanaged : public ::Texture {
public:
/**
* Default texture constructor.
*/
TextureUnmanaged() : ::Texture{0, 0, 0, 0, 0} {
// Nothing.
}
/**
* Move/Create a texture structure manually.
*/
TextureUnmanaged(unsigned int id,
int width, int height,
int mipmaps = 1,
int format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
: ::Texture{id, width, height, mipmaps, format} {
// Nothing.
}
/**
* Creates a texture object based on the given Texture struct data.
*/
TextureUnmanaged(const ::Texture& texture) :
::Texture{texture.id, texture.width, texture.height, texture.mipmaps, texture.format} {
// Nothing.
}
/**
* Creates a texture from the given Image.
*
* @throws raylib::RaylibException Throws if failed to create the texture from the given image.
*/
TextureUnmanaged(const ::Image& image) {
Load(image);
}
/**
* Load cubemap from image, multiple image cubemap layouts supported.
*
* @throws raylib::RaylibException Throws if failed to create the texture from the given cubemap.
*
* @see LoadTextureCubemap()
*/
TextureUnmanaged(const ::Image& image, int layout) {
Load(image, layout);
}
/**
* Load texture from file into GPU memory (VRAM)
*
* @throws raylib::RaylibException Throws if failed to create the texture from the given file.
*/
TextureUnmanaged(const std::string& fileName) {
Load(fileName);
}
TextureUnmanaged(::Texture&& other) :
::Texture{other.id, other.width, other.height, other.mipmaps, other.format} {
// Nothing.
}
GETTERSETTER(unsigned int, Id, id)
GETTERSETTER(int, Width, width)
GETTERSETTER(int, Height, height)
GETTERSETTER(int, Mipmaps, mipmaps)
GETTERSETTER(int, Format, format)
TextureUnmanaged& operator=(const ::Texture& texture) {
set(texture);
return *this;
}
/**
* Retrieve the width and height of the texture.
*/
inline ::Vector2 GetSize() const {
return {static_cast<float>(width), static_cast<float>(height)};
}
/**
* Load texture from image data
*/
void Load(const ::Image& image) {
set(::LoadTextureFromImage(image));
if (!IsReady()) {
throw RaylibException("Failed to load Texture from Image");
}
}
/**
* Load cubemap from image, multiple image cubemap layouts supported
*/
void Load(const ::Image& image, int layoutType) {
set(::LoadTextureCubemap(image, layoutType));
if (!IsReady()) {
throw RaylibException("Failed to load Texture from Cubemap");
}
}
/**
* Load texture from file into GPU memory (VRAM)
*/
void Load(const std::string& fileName) {
set(::LoadTexture(fileName.c_str()));
if (!IsReady()) {
throw RaylibException("Failed to load Texture from file: " + fileName);
}
}
/**
* Unload texture from GPU memory (VRAM)
*/
inline void Unload() {
// Protect against calling UnloadTexture() twice.
if (id != 0) {
::UnloadTexture(*this);
id = 0;
}
}
/**
* Update GPU texture with new data
*/
inline TextureUnmanaged& Update(const void *pixels) {
::UpdateTexture(*this, pixels);
return *this;
}
/**
* Update GPU texture rectangle with new data
*/
inline TextureUnmanaged& Update(::Rectangle rec, const void *pixels) {
UpdateTextureRec(*this, rec, pixels);
return *this;
}
/**
* Get pixel data from GPU texture and return an Image
*/
inline ::Image GetData() const {
return ::LoadImageFromTexture(*this);
}
/**
* Get pixel data from GPU texture and return an Image
*/
inline operator Image() {
return GetData();
}
/**
* Generate GPU mipmaps for a texture
*/
inline TextureUnmanaged& GenMipmaps() {
::GenTextureMipmaps(this);
return *this;
}
/**
* Set texture scaling filter mode
*/
inline TextureUnmanaged& SetFilter(int filterMode) {
::SetTextureFilter(*this, filterMode);
return *this;
}
/**
* Set texture wrapping mode
*/
inline TextureUnmanaged& SetWrap(int wrapMode) {
::SetTextureWrap(*this, wrapMode);
return *this;
}
/**
* Draw a Texture2D
*
* @see ::DrawTexture()
*/
inline void Draw(int posX = 0, int posY = 0, ::Color tint = {255, 255, 255, 255}) const {
::DrawTexture(*this, posX, posY, tint);
}
/**
* Draw a Texture2D with position defined as Vector2
*
* @see ::DrawTextureV()
*/
inline void Draw(::Vector2 position, ::Color tint = {255, 255, 255, 255}) const {
::DrawTextureV(*this, position, tint);
}
/**
* Draw a Texture2D with extended parameters
*
* @see ::DrawTextureEx()
*/
inline void Draw(::Vector2 position, float rotation, float scale = 1.0f,
::Color tint = {255, 255, 255, 255}) const {
::DrawTextureEx(*this, position, rotation, scale, tint);
}
/**
* Draw a part of a texture defined by a rectangle
*
* @see ::DrawTextureRec()
*/
inline void Draw(::Rectangle sourceRec, ::Vector2 position = {0, 0},
::Color tint = {255, 255, 255, 255}) const {
::DrawTextureRec(*this, sourceRec, position, tint);
}
/**
* Draw a part of a texture defined by a rectangle with 'pro' parameters
*
* @see ::DrawTexturePro()
*/
inline void Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin = {0, 0},
float rotation = 0, ::Color tint = {255, 255, 255, 255}) const {
::DrawTexturePro(*this, sourceRec, destRec, origin, rotation, tint);
}
/**
* Draws a texture (or part of it) that stretches or shrinks nicely
*
* @see ::DrawTextureNPatch()
*/
inline void Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin = {0, 0},
float rotation = 0, ::Color tint = {255, 255, 255, 255}) const {
::DrawTextureNPatch(*this, nPatchInfo, destRec, origin, rotation, tint);
}
/**
* Draw a billboard texture
*
* @see ::DrawBillboard()
*/
inline void DrawBillboard(const ::Camera& camera,
::Vector3 position, float size,
::Color tint = {255, 255, 255, 255}) const {
::DrawBillboard(camera, *this, position, size, tint);
}
/**
* Draw a billboard texture defined by source
*
* @see ::DrawBillboardRec()
*/
inline void DrawBillboard(const ::Camera& camera,
::Rectangle source, ::Vector3 position, ::Vector2 size,
::Color tint = {255, 255, 255, 255}) const {
DrawBillboardRec(camera, *this, source, position, size, tint);
}
/**
* Draw a billboard texture defined by source and rotation
*
* @see ::DrawBillboardPro()
*/
inline void DrawBillboard(const ::Camera& camera,
::Rectangle source, Vector3 position,
::Vector3 up, Vector2 size, Vector2 origin, float rotation = 0.0f,
::Color tint = {255, 255, 255, 255}) const {
DrawBillboardPro(camera, *this, source, position, up, size, origin, rotation, tint);
}
/**
* Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...)
*/
inline TextureUnmanaged& SetMaterial(::Material *material, int mapType = MATERIAL_MAP_NORMAL) {
::SetMaterialTexture(material, mapType, *this);
return *this;
}
inline TextureUnmanaged& SetMaterial(const ::Material& material, int mapType = MATERIAL_MAP_NORMAL) {
::SetMaterialTexture((::Material*)(&material), mapType, *this);
return *this;
}
/**
* Set texture and rectangle to be used on shapes drawing.
*/
inline TextureUnmanaged& SetShapes(const ::Rectangle& source) {
::SetShapesTexture(*this, source);
return *this;
}
/**
* Set shader uniform value for texture (sampler2d)
*/
inline TextureUnmanaged& SetShaderValue(const ::Shader& shader, int locIndex) {
::SetShaderValueTexture(shader, locIndex, *this);
return *this;
}
/**
* Determines whether or not the Texture has been loaded and is ready.
*
* @return True or false depending on whether the Texture has data.
*/
bool IsReady() const {
return id != 0;
}
protected:
void set(const ::Texture& texture) {
id = texture.id;
width = texture.width;
height = texture.height;
mipmaps = texture.mipmaps;
format = texture.format;
}
};
// Create the TextureUnmanaged aliases.
typedef TextureUnmanaged Texture2DUnmanaged;
typedef TextureUnmanaged TextureCubemapUnmanaged;
} // namespace raylib
using RTextureUnmanaged = raylib::TextureUnmanaged;
using RTexture2DUnmanaged = raylib::Texture2DUnmanaged;
using RTextureCubemapUnmanaged = raylib::TextureCubemapUnmanaged;
#endif // RAYLIB_CPP_INCLUDE_TEXTUREUNMANAGED_HPP_

View File

@@ -0,0 +1,51 @@
#ifndef RAYLIB_CPP_INCLUDE_TOUCH_HPP_
#define RAYLIB_CPP_INCLUDE_TOUCH_HPP_
#include "./raylib.hpp"
namespace raylib {
/**
* Input-related functions: touch
*/
class Touch {
public:
/**
* Get touch position X for touch point 0 (relative to screen size)
*/
inline static int GetX() {
return ::GetTouchX();
}
/**
* Get touch position Y for touch point 0 (relative to screen size)
*/
inline static int GetY() {
return ::GetTouchY();
}
/**
* Get touch position XY for a touch point index (relative to screen size)
*/
inline static Vector2 GetPosition(int index) {
return ::GetTouchPosition(index);
}
/**
* Get touch point identifier for given index
*/
inline static int GetPointId(int index) {
return ::GetTouchPointId(index);
}
/**
* Get number of touch points
*/
inline static int GetPointCount() {
return ::GetTouchPointCount();
}
};
} // namespace raylib
using RTouch = raylib::Touch;
#endif // RAYLIB_CPP_INCLUDE_TOUCH_HPP_

View File

@@ -0,0 +1,435 @@
#ifndef RAYLIB_CPP_INCLUDE_VECTOR2_HPP_
#define RAYLIB_CPP_INCLUDE_VECTOR2_HPP_
#ifndef RAYLIB_CPP_NO_MATH
#include <cmath>
#endif
#include <string>
#include "./raylib.hpp"
#include "./raymath.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* Vector2 type
*/
class Vector2 : public ::Vector2 {
public:
Vector2(const ::Vector2& vec) : ::Vector2{vec.x, vec.y} {}
Vector2(float x, float y) : ::Vector2{x, y} {}
Vector2(float x) : ::Vector2{x, 0} {}
Vector2() : ::Vector2{0, 0} {}
GETTERSETTER(float, X, x)
GETTERSETTER(float, Y, y)
/**
* Set the Vector2 to the same as the given Vector2.
*/
Vector2& operator=(const ::Vector2& vector2) {
set(vector2);
return *this;
}
/**
* Determine whether or not the vectors are equal.
*/
bool operator==(const ::Vector2& other) const {
return x == other.x
&& y == other.y;
}
/**
* Determines if the vectors are not equal.
*/
bool operator!=(const ::Vector2& other) const {
return !(*this == other);
}
inline std::string ToString() const {
return TextFormat("Vector2(%f, %f)", x, y);
}
inline operator std::string() const {
return ToString();
}
#ifndef RAYLIB_CPP_NO_MATH
/**
* Add two vectors (v1 + v2)
*/
inline Vector2 Add(const ::Vector2& vector2) const {
return Vector2Add(*this, vector2);
}
/**
* Add two vectors (v1 + v2)
*/
inline Vector2 operator+(const ::Vector2& vector2) const {
return Vector2Add(*this, vector2);
}
/**
* Add two vectors (v1 + v2)
*/
Vector2& operator+=(const ::Vector2& vector2) {
set(Vector2Add(*this, vector2));
return *this;
}
/**
* Subtract two vectors (v1 - v2)
*/
inline Vector2 Subtract(const ::Vector2& vector2) const {
return Vector2Subtract(*this, vector2);
}
/**
* Subtract two vectors (v1 - v2)
*/
inline Vector2 operator-(const ::Vector2& vector2) const {
return Vector2Subtract(*this, vector2);
}
/**
* Add two vectors (v1 + v2)
*/
Vector2& operator-=(const ::Vector2& vector2) {
set(Vector2Subtract(*this, vector2));
return *this;
}
/**
* Negate vector
*/
inline Vector2 Negate() const {
return Vector2Negate(*this);
}
/**
* Negate vector
*/
inline Vector2 operator-() const {
return Vector2Negate(*this);
}
/**
* Multiply vector by vector
*/
inline Vector2 Multiply(const ::Vector2& vector2) const {
return Vector2Multiply(*this, vector2);
}
/**
* Multiply vector by vector
*/
inline Vector2 operator*(const ::Vector2& vector2) const {
return Vector2Multiply(*this, vector2);
}
/**
* Multiply vector by vector
*/
Vector2& operator*=(const ::Vector2& vector2) {
set(Vector2Multiply(*this, vector2));
return *this;
}
/**
* Scale vector (multiply by value)
*/
inline Vector2 Scale(const float scale) const {
return Vector2Scale(*this, scale);
}
/**
* Scale vector (multiply by value)
*/
inline Vector2 operator*(const float scale) const {
return Vector2Scale(*this, scale);
}
/**
* Scale vector (multiply by value)
*/
Vector2& operator*=(const float scale) {
set(Vector2Scale(*this, scale));
return *this;
}
/**
* Divide vector by vector
*/
inline Vector2 Divide(const ::Vector2& vector2) const {
return Vector2Divide(*this, vector2);
}
/**
* Divide vector by vector
*/
inline Vector2 operator/(const ::Vector2& vector2) const {
return Vector2Divide(*this, vector2);
}
/**
* Divide vector by vector
*/
Vector2& operator/=(const ::Vector2& vector2) {
set(Vector2Divide(*this, vector2));
return *this;
}
/**
* Divide vector by value
*/
inline Vector2 Divide(const float div) const {
return ::Vector2{x / div, y / div};
}
/**
* Divide vector by value
*/
inline Vector2 operator/(const float div) const {
return Divide(div);
}
/**
* Divide vector by value
*/
Vector2& operator/=(const float div) {
this->x /= div;
this->y /= div;
return *this;
}
/**
* Normalize provided vector
*/
inline Vector2 Normalize() const {
return Vector2Normalize(*this);
}
/**
* Transforms a Vector2 by a given Matrix
*/
inline Vector2 Transform(::Matrix mat) const {
return ::Vector2Transform(*this, mat);
}
/**
* Calculate linear interpolation between two vectors
*/
inline Vector2 Lerp(const ::Vector2& vector2, float amount) const {
return Vector2Lerp(*this, vector2, amount);
}
/**
* Calculate reflected vector to normal
*/
inline Vector2 Reflect(const ::Vector2& normal) const {
return Vector2Reflect(*this, normal);
}
/**
* Rotate Vector by float in Degrees
*/
inline Vector2 Rotate(float degrees) const {
return Vector2Rotate(*this, degrees);
}
/**
* Move Vector towards target
*/
inline Vector2 MoveTowards(const ::Vector2& target, float maxDistance) const {
return Vector2MoveTowards(*this, target, maxDistance);
}
/**
* Invert the given vector
*/
inline Vector2 Invert() const {
return ::Vector2Invert(*this);
}
/**
* Clamp the components of the vector between
*/
inline Vector2 Clamp(::Vector2 min, ::Vector2 max) const {
return ::Vector2Clamp(*this, min, max);
}
/**
* // Clamp the magnitude of the vector between two min and max values
*/
inline Vector2 Clamp(float min, float max) const {
return ::Vector2ClampValue(*this, min, max);
}
/**
* Check whether two given vectors are almost equal
*/
inline int Equals(::Vector2 q) const {
return ::Vector2Equals(*this, q);
}
/**
* Calculate vector length
*/
inline float Length() const {
return Vector2Length(*this);
}
/**
* Calculate vector square length
*/
inline float LengthSqr() const {
return Vector2LengthSqr(*this);
}
/**
* Calculate two vectors dot product
*/
inline float DotProduct(const ::Vector2& vector2) const {
return Vector2DotProduct(*this, vector2);
}
/**
* Calculate distance between two vectors
*/
inline float Distance(const ::Vector2& vector2) const {
return Vector2Distance(*this, vector2);
}
/**
* Calculate square distance between two vectors
*/
inline float DistanceSqr(::Vector2 v2) const {
return ::Vector2DistanceSqr(*this, v2);
}
/**
* Calculate angle from two vectors in X-axis
*/
inline float Angle(const ::Vector2& vector2) const {
return Vector2Angle(*this, vector2);
}
/**
* Vector with components value 0.0f
*/
static inline Vector2 Zero() {
return Vector2Zero();
}
/**
* Vector with components value 1.0f
*/
static inline Vector2 One() {
return Vector2One();
}
#endif
inline void DrawPixel(::Color color = {0, 0, 0, 255}) const {
::DrawPixelV(*this, color);
}
inline void DrawLine(::Vector2 endPos, ::Color color = {0, 0, 0, 255}) const {
::DrawLineV(*this, endPos, color);
}
inline void DrawLine(::Vector2 endPos, float thick, ::Color color = {0, 0, 0, 255}) const {
::DrawLineEx(*this, endPos, thick, color);
}
inline void DrawLineBezier(::Vector2 endPos, float thick, ::Color color = {0, 0, 0, 255}) const {
::DrawLineBezier(*this, endPos, thick, color);
}
/**
* Draw a color-filled circle (Vector version)
*/
inline void DrawCircle(float radius, ::Color color = {0, 0, 0, 255}) const {
::DrawCircleV(*this, radius, color);
}
inline void DrawRectangle(::Vector2 size, ::Color color = {0, 0, 0, 255}) const {
::DrawRectangleV(*this, size, color);
}
inline void DrawPoly(int sides, float radius, float rotation, ::Color color = {0, 0, 0, 255}) const {
::DrawPoly(*this, sides, radius, rotation, color);
}
/**
* Check collision between two circles
*/
inline bool CheckCollisionCircle(float radius1, ::Vector2 center2, float radius2) const {
return ::CheckCollisionCircles(*this, radius1, center2, radius2);
}
/**
* Check collision between circle and rectangle
*/
inline bool CheckCollisionCircle(float radius, ::Rectangle rec) const {
return ::CheckCollisionCircleRec(*this, radius, rec);
}
/**
* Check if point is inside rectangle
*/
inline bool CheckCollision(::Rectangle rec) const {
return ::CheckCollisionPointRec(*this, rec);
}
/**
* Check if point is inside circle
*/
inline bool CheckCollision(::Vector2 center, float radius) const {
return ::CheckCollisionPointCircle(*this, center, radius);
}
/**
* Check if point is inside a triangle
*/
inline bool CheckCollision(::Vector2 p1, ::Vector2 p2, ::Vector2 p3) const {
return ::CheckCollisionPointTriangle(*this, p1, p2, p3);
}
/**
* Check the collision between two lines defined by two points each, returns collision point by reference
*/
inline bool CheckCollisionLines(
::Vector2 endPos1,
::Vector2 startPos2, ::Vector2 endPos2,
::Vector2 *collisionPoint) const {
return ::CheckCollisionLines(*this, endPos1, startPos2, endPos2, collisionPoint);
}
/**
* Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold]
*/
inline bool CheckCollisionPointLine(::Vector2 p1, ::Vector2 p2, int threshold = 1) const {
return ::CheckCollisionPointLine(*this, p1, p2, threshold);
}
protected:
void set(const ::Vector2& vec) {
x = vec.x;
y = vec.y;
}
};
} // namespace raylib
using RVector2 = raylib::Vector2;
#endif // RAYLIB_CPP_INCLUDE_VECTOR2_HPP_

View File

@@ -0,0 +1,353 @@
#ifndef RAYLIB_CPP_INCLUDE_VECTOR3_HPP_
#define RAYLIB_CPP_INCLUDE_VECTOR3_HPP_
#ifndef RAYLIB_CPP_NO_MATH
#include <cmath>
#endif
#include <string>
#include "./raylib.hpp"
#include "./raymath.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* Vector3 type
*/
class Vector3 : public ::Vector3 {
public:
Vector3(const ::Vector3& vec) : ::Vector3{vec.x, vec.y, vec.z} {}
Vector3(float x, float y, float z) : ::Vector3{x, y, z} {}
Vector3(float x, float y) : ::Vector3{x, y, 0} {}
Vector3(float x) : ::Vector3{x, 0, 0} {}
Vector3() {}
Vector3(::Color color) {
set(ColorToHSV(color));
}
GETTERSETTER(float, X, x)
GETTERSETTER(float, Y, y)
GETTERSETTER(float, Z, z)
Vector3& operator=(const ::Vector3& vector3) {
set(vector3);
return *this;
}
bool operator==(const ::Vector3& other) const {
return x == other.x
&& y == other.y
&& z == other.z;
}
bool operator!=(const ::Vector3& other) const {
return !(*this == other);
}
inline std::string ToString() const {
return TextFormat("Vector3(%f, %f, %f)", x, y, z);
}
inline operator std::string() const {
return ToString();
}
#ifndef RAYLIB_CPP_NO_MATH
/**
* Add two vectors
*/
inline Vector3 Add(const ::Vector3& vector3) const {
return Vector3Add(*this, vector3);
}
/**
* Add two vectors
*/
inline Vector3 operator+(const ::Vector3& vector3) const {
return Vector3Add(*this, vector3);
}
Vector3& operator+=(const ::Vector3& vector3) {
set(Vector3Add(*this, vector3));
return *this;
}
/**
* Subtract two vectors.
*/
inline Vector3 Subtract(const ::Vector3& vector3) const {
return Vector3Subtract(*this, vector3);
}
/**
* Subtract two vectors.
*/
inline Vector3 operator-(const ::Vector3& vector3) const {
return Vector3Subtract(*this, vector3);
}
Vector3& operator-=(const ::Vector3& vector3) {
set(Vector3Subtract(*this, vector3));
return *this;
}
/**
* Negate provided vector (invert direction)
*/
inline Vector3 Negate() const {
return Vector3Negate(*this);
}
/**
* Negate provided vector (invert direction)
*/
inline Vector3 operator-() const {
return Vector3Negate(*this);
}
/**
* Multiply vector by vector
*/
inline Vector3 Multiply(const ::Vector3& vector3) const {
return Vector3Multiply(*this, vector3);
}
/**
* Multiply vector by vector
*/
inline Vector3 operator*(const ::Vector3& vector3) const {
return Vector3Multiply(*this, vector3);
}
/**
* Multiply vector by vector
*/
Vector3& operator*=(const ::Vector3& vector3) {
set(Vector3Multiply(*this, vector3));
return *this;
}
/**
* Multiply vector by scalar
*/
inline Vector3 Scale(const float scaler) const {
return Vector3Scale(*this, scaler);
}
/**
* Multiply vector by scalar
*/
inline Vector3 operator*(const float scaler) const {
return Vector3Scale(*this, scaler);
}
/**
* Multiply vector by scalar
*/
Vector3& operator*=(const float scaler) {
set(Vector3Scale(*this, scaler));
return *this;
}
/**
* Divide vector by vector
*/
inline Vector3 Divide(const ::Vector3& vector3) const {
return Vector3Divide(*this, vector3);
}
/**
* Divide vector by vector
*/
inline Vector3 operator/(const ::Vector3& vector3) const {
return Vector3Divide(*this, vector3);
}
/**
* Divide vector by vector
*/
Vector3& operator/=(const ::Vector3& vector3) {
x /= vector3.x;
y /= vector3.y;
z /= vector3.z;
return *this;
}
/**
* Divide a vector by a value.
*/
inline Vector3 Divide(const float div) const {
return ::Vector3{x / div, y / div, z / div};
}
/**
* Divide a vector by a value.
*/
inline Vector3 operator/(const float div) const {
return Divide(div);
}
/**
* Divide a vector by a value.
*/
Vector3& operator/=(const float div) {
x /= div;
y /= div;
z /= div;
return *this;
}
/**
* Calculate vector length
*/
inline float Length() const {
return Vector3Length(*this);
}
inline Vector3 Normalize() const {
return Vector3Normalize(*this);
}
inline float DotProduct(const ::Vector3& vector3) const {
return Vector3DotProduct(*this, vector3);
}
inline float Distance(const ::Vector3& vector3) const {
return Vector3Distance(*this, vector3);
}
inline Vector3 Lerp(const ::Vector3& vector3, const float amount) const {
return Vector3Lerp(*this, vector3, amount);
}
inline Vector3 CrossProduct(const ::Vector3& vector3) const {
return Vector3CrossProduct(*this, vector3);
}
inline Vector3 Perpendicular() const {
return Vector3Perpendicular(*this);
}
inline void OrthoNormalize(::Vector3* vector3) {
Vector3OrthoNormalize(this, vector3);
}
inline Vector3 Transform(const ::Matrix& matrix) const {
return Vector3Transform(*this, matrix);
}
inline Vector3 RotateByQuaternion(const ::Quaternion& quaternion) const {
return Vector3RotateByQuaternion(*this, quaternion);
}
inline Vector3 Reflect(const ::Vector3& normal) const {
return Vector3Reflect(*this, normal);
}
inline Vector3 Min(const ::Vector3& vector3) const {
return Vector3Min(*this, vector3);
}
inline Vector3 Max(const ::Vector3& vector3) const {
return Vector3Max(*this, vector3);
}
inline Vector3 Barycenter(const ::Vector3& a, const ::Vector3& b, const ::Vector3& c) const {
return Vector3Barycenter(*this, a, b, c);
}
static inline Vector3 Zero() {
return Vector3Zero();
}
static inline Vector3 One() {
return Vector3One();
}
#endif
inline void DrawLine3D(const ::Vector3& endPos, ::Color color) const {
::DrawLine3D(*this, endPos, color);
}
inline void DrawPoint3D(::Color color) const {
::DrawPoint3D(*this, color);
}
inline void DrawCircle3D(
float radius,
const ::Vector3& rotationAxis,
float rotationAngle,
Color color) const {
::DrawCircle3D(*this, radius, rotationAxis, rotationAngle, color);
}
inline void DrawCube(float width, float height, float length, ::Color color) const {
::DrawCube(*this, width, height, length, color);
}
inline void DrawCube(const ::Vector3& size, ::Color color) const {
::DrawCubeV(*this, size, color);
}
inline void DrawCubeWires(float width, float height, float length, ::Color color) const {
::DrawCubeWires(*this, width, height, length, color);
}
inline void DrawCubeWires(const ::Vector3& size, ::Color color) const {
::DrawCubeWiresV(*this, size, color);
}
inline void DrawSphere(float radius, ::Color color) const {
::DrawSphere(*this, radius, color);
}
inline void DrawSphere(float radius, int rings, int slices, ::Color color) const {
::DrawSphereEx(*this, radius, rings, slices, color);
}
inline void DrawSphereWires(float radius, int rings, int slices, ::Color color) const {
::DrawSphereWires(*this, radius, rings, slices, color);
}
inline void DrawCylinder(float radiusTop, float radiusBottom, float height,
int slices, ::Color color) const {
::DrawCylinder(*this, radiusTop, radiusBottom, height, slices, color);
}
inline void DrawCylinderWires(float radiusTop, float radiusBottom, float height,
int slices, ::Color color) const {
::DrawCylinderWires(*this, radiusTop, radiusBottom, height, slices, color);
}
inline void DrawPlane(const ::Vector2& size, ::Color color) const {
::DrawPlane(*this, size, color);
}
/**
* Detect collision between two spheres
*/
inline bool CheckCollision(float radius1, const ::Vector3& center2, float radius2) const {
return CheckCollisionSpheres(*this, radius1, center2, radius2);
}
protected:
void set(const ::Vector3& vec) {
x = vec.x;
y = vec.y;
z = vec.z;
}
};
} // namespace raylib
using RVector3 = raylib::Vector3;
#endif // RAYLIB_CPP_INCLUDE_VECTOR3_HPP_

View File

@@ -0,0 +1,180 @@
#ifndef RAYLIB_CPP_INCLUDE_VECTOR4_HPP_
#define RAYLIB_CPP_INCLUDE_VECTOR4_HPP_
#ifndef RAYLIB_CPP_NO_MATH
#include <cmath>
#include <utility>
#endif
#include <string>
#include "./raylib.hpp"
#include "./raymath.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* Vector4 type
*/
class Vector4 : public ::Vector4 {
public:
Vector4(const ::Vector4& vec) : ::Vector4{vec.x, vec.y, vec.z, vec.w} {}
Vector4(float x, float y, float z, float w) : ::Vector4{x, y, z, w} {}
Vector4(float x, float y, float z) : ::Vector4{x, y, z, 0} {}
Vector4(float x, float y) : ::Vector4{x, y, 0, 0} {}
Vector4(float x) : ::Vector4{x, 0, 0, 0} {}
Vector4() : ::Vector4{0, 0, 0, 0} {}
Vector4(::Rectangle rectangle) : ::Vector4{rectangle.x, rectangle.y, rectangle.width, rectangle.height} {}
Vector4(::Color color) {
set(ColorNormalize(color));
}
GETTERSETTER(float, X, x)
GETTERSETTER(float, Y, y)
GETTERSETTER(float, Z, z)
GETTERSETTER(float, W, w)
Vector4& operator=(const ::Vector4& vector4) {
set(vector4);
return *this;
}
bool operator==(const ::Vector4& other) const {
return x == other.x
&& y == other.y
&& z == other.z
&& w == other.w;
}
bool operator!=(const ::Vector4& other) const {
return !(*this == other);
}
inline ::Rectangle ToRectangle() const {
return {x, y, z, w};
}
operator ::Rectangle() const {
return {x, y, z, w};
}
inline std::string ToString() const {
return TextFormat("Vector4(%f, %f, %f, %f)", x, y, z, w);
}
inline operator std::string() const {
return ToString();
}
#ifndef RAYLIB_CPP_NO_MATH
inline Vector4 Multiply(const ::Vector4& vector4) const {
return QuaternionMultiply(*this, vector4);
}
inline Vector4 operator*(const ::Vector4& vector4) const {
return QuaternionMultiply(*this, vector4);
}
inline Vector4 Lerp(const ::Vector4& vector4, float amount) const {
return QuaternionLerp(*this, vector4, amount);
}
inline Vector4 Nlerp(const ::Vector4& vector4, float amount) const {
return QuaternionNlerp(*this, vector4, amount);
}
inline Vector4 Slerp(const ::Vector4& vector4, float amount) const {
return QuaternionSlerp(*this, vector4, amount);
}
inline Matrix ToMatrix() const {
return QuaternionToMatrix(*this);
}
inline float Length() const {
return QuaternionLength(*this);
}
inline Vector4 Normalize() const {
return QuaternionNormalize(*this);
}
inline Vector4 Invert() const {
return QuaternionInvert(*this);
}
inline void ToAxisAngle(::Vector3 *outAxis, float *outAngle) const {
QuaternionToAxisAngle(*this, outAxis, outAngle);
}
/**
* Get the rotation angle and axis for a given quaternion
*/
std::pair<Vector3, float> ToAxisAngle() const {
Vector3 outAxis;
float outAngle;
QuaternionToAxisAngle(*this, &outAxis, &outAngle);
return std::pair<Vector3, float>(outAxis, outAngle);
}
inline Vector4 Transform(const ::Matrix& matrix) const {
return ::QuaternionTransform(*this, matrix);
}
static inline Vector4 Identity() {
return ::QuaternionIdentity();
}
static inline Vector4 FromVector3ToVector3(const ::Vector3& from , const ::Vector3& to) {
return ::QuaternionFromVector3ToVector3(from , to);
}
static inline Vector4 FromMatrix(const ::Matrix& matrix) {
return ::QuaternionFromMatrix(matrix);
}
static inline Vector4 FromAxisAngle(const ::Vector3& axis, const float angle) {
return ::QuaternionFromAxisAngle(axis, angle);
}
static inline Vector4 FromEuler(const float pitch, const float yaw, const float roll) {
return ::QuaternionFromEuler(pitch, yaw, roll);
}
static inline Vector4 FromEuler(const ::Vector3& vector3) {
return ::QuaternionFromEuler(vector3.x, vector3.y, vector3.z);
}
inline Vector3 ToEuler() const {
return ::QuaternionToEuler(*this);
}
#endif
inline Color ColorFromNormalized() const {
return ::ColorFromNormalized(*this);
}
operator Color() const {
return ColorFromNormalized();
}
protected:
void set(const ::Vector4& vec4) {
x = vec4.x;
y = vec4.y;
z = vec4.z;
w = vec4.w;
}
};
// Alias the Vector4 as Quaternion.
typedef Vector4 Quaternion;
} // namespace raylib
using RVector4 = raylib::Vector4;
using RQuaternion = raylib::Quaternion;
#endif // RAYLIB_CPP_INCLUDE_VECTOR4_HPP_

View File

@@ -0,0 +1,78 @@
#ifndef RAYLIB_CPP_INCLUDE_VRSTEREOCONFIG_HPP_
#define RAYLIB_CPP_INCLUDE_VRSTEREOCONFIG_HPP_
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* VR stereo config functions for VR simulator
*/
class VrStereoConfig : public ::VrStereoConfig {
public:
VrStereoConfig(const ::VrDeviceInfo& info) {
Load(info);
}
/**
* Load VR stereo config for VR simulator device parameters
*/
inline void Load(const ::VrDeviceInfo& info) {
set(LoadVrStereoConfig(info));
}
/**
* Unload VR stereo config
*/
~VrStereoConfig() {
Unload();
}
/**
* Begin stereo rendering
*/
inline VrStereoConfig& BeginMode() {
::BeginVrStereoMode(*this);
return *this;
}
/**
* End stereo rendering
*/
inline VrStereoConfig& EndMode() {
::EndVrStereoMode();
return *this;
}
/**
* Unload VR stereo config
*/
inline void Unload() {
::UnloadVrStereoConfig(*this);
}
protected:
void set(const ::VrStereoConfig& config) {
projection[0] = config.projection[0];
projection[1] = config.projection[1];
viewOffset[0] = config.viewOffset[0];
viewOffset[1] = config.viewOffset[1];
leftLensCenter[0] = config.leftLensCenter[0];
leftLensCenter[1] = config.leftLensCenter[1];
rightLensCenter[0] = config.rightLensCenter[0];
rightLensCenter[1] = config.rightLensCenter[1];
leftScreenCenter[0] = config.leftScreenCenter[0];
leftScreenCenter[1] = config.leftScreenCenter[1];
rightScreenCenter[0] = config.rightScreenCenter[0];
rightScreenCenter[1] = config.rightScreenCenter[1];
scale[0] = config.scale[0];
scale[1] = config.scale[1];
scaleIn[0] = config.scaleIn[0];
scaleIn[1] = config.scaleIn[1];
}
};
} // namespace raylib
using RVrStereoConfig = raylib::VrStereoConfig;
#endif // RAYLIB_CPP_INCLUDE_VRSTEREOCONFIG_HPP_

View File

@@ -0,0 +1,232 @@
#ifndef RAYLIB_CPP_INCLUDE_WAVE_HPP_
#define RAYLIB_CPP_INCLUDE_WAVE_HPP_
#include <string>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./RaylibException.hpp"
namespace raylib {
/**
* Wave type, defines audio wave data
*/
class Wave : public ::Wave {
public:
Wave(const ::Wave& wave) {
set(wave);
}
Wave(
unsigned int frameCount = 0,
unsigned int sampleRate = 0,
unsigned int sampleSize = 0,
unsigned int channels = 0,
void *data = nullptr) : ::Wave{frameCount, sampleRate, sampleSize, channels, data} {
// Nothing.
}
/**
* Load wave data from file
*
* @throws raylib::RaylibException Throws if the Wave failed to load.
*/
Wave(const std::string& fileName) {
Load(fileName);
}
/**
* Load wave from memory buffer, fileType refers to extension: i.e. "wav"
*
* @throws raylib::RaylibException Throws if the Wave failed to load.
*/
Wave(const std::string& fileType, const unsigned char *fileData, int dataSize) {
Load(fileType, fileData, dataSize);
}
Wave(const Wave& other) {
set(other.Copy());
}
Wave(Wave&& other) {
set(other);
other.frameCount = 0;
other.sampleRate = 0;
other.sampleSize = 0;
other.channels = 0;
other.data = nullptr;
}
/**
* Unload wave data
*/
~Wave() {
Unload();
}
GETTERSETTER(unsigned int, FrameCount, frameCount)
GETTERSETTER(unsigned int, SampleRate, sampleRate)
GETTERSETTER(unsigned int, SampleSize, sampleSize)
GETTERSETTER(unsigned int, Channels, channels)
GETTERSETTER(void *, Data, data)
Wave& operator=(const ::Wave& wave) {
set(wave);
return *this;
}
Wave& operator=(const Wave& other) {
if (this == &other) {
return *this;
}
Unload();
set(other.Copy());
return *this;
}
Wave& operator=(Wave&& other) noexcept {
if (this != &other) {
return *this;
}
Unload();
set(other);
other.frameCount = 0;
other.sampleRate = 0;
other.sampleSize = 0;
other.channels = 0;
other.data = nullptr;
return *this;
}
/**
* Copy a wave to a new wave
*/
inline ::Wave Copy() const {
return ::WaveCopy(*this);
}
/**
* Crop a wave to defined samples range
*/
inline Wave& Crop(int initSample, int finalSample) {
::WaveCrop(this, initSample, finalSample);
return *this;
}
/**
* Convert wave data to desired format
*/
inline Wave& Format(int SampleRate, int SampleSize, int Channels = 2) {
::WaveFormat(this, SampleRate, SampleSize, Channels);
return *this;
}
/**
* Load samples data from wave as a floats array
*/
inline float* LoadSamples() {
return ::LoadWaveSamples(*this);
}
/**
* Unload samples data loaded with LoadWaveSamples()
*/
inline static void UnloadSamples(float *samples) {
::UnloadWaveSamples(samples);
}
/**
* Export wave data to file, returns true on success
*/
inline bool Export(const std::string& fileName) {
// TODO(RobLoach): Throw exception on error.
return ::ExportWave(*this, fileName.c_str());
}
/**
* Export wave sample data to code (.h), returns true on success
*/
inline bool ExportAsCode(const std::string& fileName) {
// TODO(RobLoach): Throw exception on error.
return ::ExportWaveAsCode(*this, fileName.c_str());
}
/**
* Unload wave data
*/
void Unload() {
// Protect against calling UnloadWave() twice.
if (data != nullptr) {
::UnloadWave(*this);
data = nullptr;
}
}
/**
* Load sound from wave data
*/
inline ::Sound LoadSound() {
return ::LoadSoundFromWave(*this);
}
/**
* Load sound from wave data
*/
inline operator ::Sound() {
return LoadSound();
}
/**
* Load wave data from file.
*
* @throws raylib::RaylibException Throws if the Wave failed to load.
*/
void Load(const std::string& fileName) {
set(::LoadWave(fileName.c_str()));
if (!IsReady()) {
throw RaylibException("Failed to load Wave from file: " + fileName);
}
}
/**
* Load wave from memory buffer, fileType refers to extension: i.e. "wav"
*
* @throws raylib::RaylibException Throws if the Wave failed to load.
*/
void Load(const std::string& fileType, const unsigned char *fileData, int dataSize) {
set(::LoadWaveFromMemory(fileType.c_str(), fileData, dataSize));
if (!IsReady()) {
throw RaylibException("Failed to load Wave from file data of type: " + fileType);
}
}
/**
* Retrieve whether or not the Wave data has been loaded.
*
* @return True or false depending on whether the wave data has been loaded.
*/
inline bool IsReady() const {
return ::IsWaveReady(*this);
}
protected:
void set(const ::Wave& wave) {
frameCount = wave.frameCount;
sampleRate = wave.sampleRate;
sampleSize = wave.sampleSize;
channels = wave.channels;
data = wave.data;
}
};
} // namespace raylib
using RWave = raylib::Wave;
#endif // RAYLIB_CPP_INCLUDE_WAVE_HPP_

View File

@@ -0,0 +1,463 @@
#ifndef RAYLIB_CPP_INCLUDE_WINDOW_HPP_
#define RAYLIB_CPP_INCLUDE_WINDOW_HPP_
#include <string>
#include "./raylib.hpp"
#include "./RaylibException.hpp"
#include "./Vector2.hpp"
namespace raylib {
/**
* Window and Graphics Device Functions.
*/
class Window {
public:
/**
* Build a Window object, but defer the initialization. Ensure you call Init() manually.
*
* @see Init()
*/
Window() {
// Nothing.
}
/**
* Initialize window and OpenGL context.
*
* @param width The width of the window.
* @param height The height of the window.
* @param title The desired title of the window.
* @param flags The ConfigFlags to set prior to initializing the window. See SetConfigFlags for more details.
*
* @see ::SetConfigFlags()
* @see ConfigFlags
*
* @throws raylib::RaylibException Thrown if the window failed to initiate.
*/
Window(int width, int height, const std::string& title = "raylib", unsigned int flags = 0) {
Init(width, height, title, flags);
}
/**
* Close window and unload OpenGL context
*/
~Window() {
Close();
}
/**
* Initializes the window.
*
* @param width The width of the window.
* @param height The height of the window.
* @param title The desired title of the window.
* @param flags The ConfigFlags to set prior to initializing the window. See SetConfigFlags for more details.
*
* @see ::SetConfigFlags()
* @see ConfigFlags
*
* @throws raylib::RaylibException Thrown if the window failed to initiate.
*/
inline void Init(int width = 800, int height = 450, const std::string& title = "raylib", unsigned int flags = 0) {
if (flags != 0) {
::SetConfigFlags(flags);
}
::InitWindow(width, height, title.c_str());
if (!::IsWindowReady()) {
throw RaylibException("Failed to create Window");
}
}
/**
* Check if KEY_ESCAPE pressed or Close icon pressed
*/
inline bool ShouldClose() const {
return ::WindowShouldClose();
}
/**
* Close window and unload OpenGL context
*/
inline void Close() {
if (::IsWindowReady()) {
::CloseWindow();
}
}
/**
* Check if cursor is on the current screen
*/
inline bool IsCursorOnScreen() const {
return ::IsCursorOnScreen();
}
/**
* Check if window is currently fullscreen
*/
inline bool IsFullscreen() const {
return ::IsWindowFullscreen();
}
/**
* Check if window is currently hidden
*/
inline bool IsHidden() const {
return ::IsWindowHidden();
}
/**
* Check if window is currently minimized
*/
inline bool IsMinimized() const {
return ::IsWindowMinimized();
}
/**
* Check if window is currently minimized
*/
inline bool IsMaximized() const {
return ::IsWindowMaximized();
}
/**
* Check if window is currently focused
*/
inline bool IsFocused() const {
return ::IsWindowFocused();
}
/**
* Check if window has been resized last frame
*/
inline bool IsResized() const {
return ::IsWindowResized();
}
/**
* Check if one specific window flag is enabled
*/
inline bool IsState(unsigned int flag) const {
return ::IsWindowState(flag);
}
/**
* Set window configuration state using flags
*/
inline Window& SetState(unsigned int flag) {
::SetWindowState(flag);
return *this;
}
/**
* Clear window configuration state flags
*/
inline Window& ClearState(unsigned int flag) {
::ClearWindowState(flag);
return *this;
}
/**
* Clear window with given color.
*/
inline Window& ClearBackground(const ::Color& color = BLACK) {
::ClearBackground(color);
return *this;
}
/**
* Toggle window state: fullscreen/windowed
*/
inline Window& ToggleFullscreen() {
::ToggleFullscreen();
return *this;
}
/**
* Set whether or not the application should be fullscreen.
*/
inline Window& SetFullscreen(bool fullscreen) {
if (fullscreen) {
if (!IsFullscreen()) {
ToggleFullscreen();
}
} else {
if (IsFullscreen()) {
ToggleFullscreen();
}
}
return *this;
}
/**
* Toggle window state: borderless/windowed
*/
inline Window& ToggleBorderless() {
::ToggleBorderlessWindowed();
return *this;
}
/**
* Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
*/
inline Window& Maximize() {
::MaximizeWindow();
return *this;
}
/**
* Set window state: minimized, if resizable (only PLATFORM_DESKTOP)
*/
inline Window& Minimize() {
::MinimizeWindow();
return *this;
}
/**
* Set window state: not minimized/maximized (only PLATFORM_DESKTOP)
*/
inline Window& Restore() {
::RestoreWindow();
return *this;
}
/**
* Set icon for window
*/
inline Window& SetIcon(const ::Image& image) {
::SetWindowIcon(image);
return *this;
}
/**
* Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)
*/
inline Window& SetIcons(Image* images, int count) {
::SetWindowIcons(images, count);
return *this;
}
/**
* Set title for window
*/
inline Window& SetTitle(const std::string& title) {
::SetWindowTitle(title.c_str());
return *this;
}
/**
* Set window position on screen
*/
inline Window& SetPosition(int x, int y) {
::SetWindowPosition(x, y);
return *this;
}
/**
* Set window position on screen
*/
inline Window& SetPosition(const ::Vector2& position) {
return SetPosition(static_cast<int>(position.x), static_cast<int>(position.y));
}
/**
* Set monitor for the current window
*/
inline Window& SetMonitor(int monitor) {
::SetWindowMonitor(monitor);
return *this;
}
/**
* Set window minimum dimensions
*/
inline Window& SetMinSize(int width, int height) {
::SetWindowMinSize(width, height);
return *this;
}
/**
* Set window minimum dimensions
*/
inline Window& SetMinSize(const ::Vector2& size) {
::SetWindowMinSize(static_cast<int>(size.x), static_cast<int>(size.y));
return *this;
}
/**
* Set window dimensions
*/
inline Window& SetSize(int width, int height) {
::SetWindowSize(width, height);
return *this;
}
/**
* Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
*/
inline Window& SetOpacity(float opacity) {
::SetWindowOpacity(opacity);
return *this;
}
/**
* Set window focused (only PLATFORM_DESKTOP)
*/
inline Window& SetFocused() {
::SetWindowFocused();
return *this;
}
/**
* Set window dimensions
*/
inline Window& SetSize(const ::Vector2& size) {
return SetSize(static_cast<int>(size.x), static_cast<int>(size.y));
}
/**
* Get the screen's width and height.
*/
inline Vector2 GetSize() const {
return {static_cast<float>(GetWidth()), static_cast<float>(GetHeight())};
}
/**
* Get native window handle
*/
inline void* GetHandle() const {
return ::GetWindowHandle();
}
/**
* Setup canvas (framebuffer) to start drawing
*/
inline Window& BeginDrawing() {
::BeginDrawing();
return *this;
}
/**
* End canvas drawing and swap buffers (double buffering)
*/
inline Window& EndDrawing() {
::EndDrawing();
return *this;
}
/**
* Get current screen width
*/
inline int GetWidth() const {
return ::GetScreenWidth();
}
/**
* Get current screen height
*/
inline int GetHeight() const {
return ::GetScreenHeight();
}
/**
* Get current render width (it considers HiDPI)
*/
inline int GetRenderWidth() const {
return ::GetRenderWidth();
}
/**
* Get current render height (it considers HiDPI)
*/
inline int GetRenderHeight() const {
return ::GetRenderHeight();
}
/**
* Get window position XY on monitor
*/
inline Vector2 GetPosition() const {
return ::GetWindowPosition();
}
/**
* Get window scale DPI factor
*/
inline Vector2 GetScaleDPI() const {
return ::GetWindowScaleDPI();
}
/**
* Set clipboard text content
*/
inline void SetClipboardText(const std::string& text) {
::SetClipboardText(text.c_str());
}
/**
* Get clipboard text content
*/
inline const std::string GetClipboardText() {
return ::GetClipboardText();
}
/**
* Set target FPS (maximum)
*/
inline Window& SetTargetFPS(int fps) {
::SetTargetFPS(fps);
return *this;
}
/**
* Returns current FPS
*/
inline int GetFPS() const {
return ::GetFPS();
}
/**
* Draw current FPS
*/
inline void DrawFPS(int posX = 10, int posY = 10) const {
::DrawFPS(posX, posY);
}
/**
* Returns time in seconds for last frame drawn
*/
inline float GetFrameTime() const {
return ::GetFrameTime();
}
/**
* Returns elapsed time in seconds since InitWindow()
*/
inline double GetTime() const {
return ::GetTime();
}
/**
* Check if window has been initialized successfully
*/
inline static bool IsReady() {
return ::IsWindowReady();
}
/**
* Sets the configuration flags for raylib.
*
* @param flags The ConfigFlags to apply to the configuration.
*
* @see ::SetConfigFlags
*/
inline void SetConfigFlags(unsigned int flags) {
::SetConfigFlags(flags);
}
};
} // namespace raylib
using RWindow = raylib::Window;
#endif // RAYLIB_CPP_INCLUDE_WINDOW_HPP_

View File

@@ -0,0 +1,22 @@
/**
* Utility for raylib-cpp.
*/
#ifndef RAYLIB_CPP_INCLUDE_RAYLIB_CPP_UTILS_HPP_
#define RAYLIB_CPP_INCLUDE_RAYLIB_CPP_UTILS_HPP_
#ifndef GETTERSETTER
/**
* A utility to build get and set methods on top of a property.
*
* @param type The type of the property.
* @param method The human-readable name for the method.
* @param name The machine-readable name of the property.
*/
#define GETTERSETTER(type, method, name) \
/** Retrieves the name value for the object. @return The name value of the object. */ \
inline type Get##method() const { return name; } \
/** Sets the name value for the object. @param value The value of which to set name to. */ \
inline void Set##method(type value) { name = value; }
#endif
#endif // RAYLIB_CPP_INCLUDE_RAYLIB_CPP_UTILS_HPP_

View File

@@ -0,0 +1,76 @@
/**
* [raylib-cpp](https://github.com/RobLoach/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.
*
* @see raylib namespace for a list of all available classes.
* @mainpage raylib-cpp
* @include core_basic_window.cpp
* @author Rob Loach (RobLoach)
* @copyright zlib/libpng
*
* 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:
*
* Copyright 2020 Rob Loach (RobLoach)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose, including commercial
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that you
* wrote the original software. If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
* as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef RAYLIB_CPP_INCLUDE_RAYLIB_CPP_HPP_
#define RAYLIB_CPP_INCLUDE_RAYLIB_CPP_HPP_
#include "./AudioDevice.hpp"
#include "./AudioStream.hpp"
#include "./BoundingBox.hpp"
#include "./Camera2D.hpp"
#include "./Camera3D.hpp"
#include "./Color.hpp"
#include "./Font.hpp"
#include "./Functions.hpp"
#include "./Gamepad.hpp"
#include "./Image.hpp"
#include "./Material.hpp"
#include "./Matrix.hpp"
#include "./Mesh.hpp"
#include "./Model.hpp"
#include "./ModelAnimation.hpp"
#include "./Mouse.hpp"
#include "./Music.hpp"
#include "./Ray.hpp"
#include "./RaylibException.hpp"
#include "./RayCollision.hpp"
#include "./Rectangle.hpp"
#include "./RenderTexture.hpp"
#include "./Shader.hpp"
#include "./Sound.hpp"
#include "./Text.hpp"
#include "./Texture.hpp"
#include "./TextureUnmanaged.hpp"
#include "./Touch.hpp"
#include "./Vector2.hpp"
#include "./Vector3.hpp"
#include "./Vector4.hpp"
#include "./VrStereoConfig.hpp"
#include "./Wave.hpp"
#include "./Window.hpp"
/**
* All raylib-cpp classes and functions appear in the raylib namespace.
*/
namespace raylib {
// Nothing.
} // namespace raylib
#endif // RAYLIB_CPP_INCLUDE_RAYLIB_CPP_HPP_

View File

@@ -0,0 +1,31 @@
/**
* C++ header to wrap raylib.h.
*/
#ifndef RAYLIB_CPP_INCLUDE_RAYLIB_HPP_
#define RAYLIB_CPP_INCLUDE_RAYLIB_HPP_
#ifdef __cplusplus
extern "C" {
#endif
#ifndef RAYLIB_H_FILE
#define RAYLIB_H_FILE "raylib.h"
#endif
#include RAYLIB_H_FILE // NOLINT
#if !defined(RAYLIB_VERSION_MAJOR) || !defined(RAYLIB_VERSION_MINOR)
#if RAYLIB_VERSION_MAJOR < 5
#error "raylib-cpp requires at least raylib 5.0.0"
#endif
#endif
#if RAYLIB_VERSION_MAJOR > 5
#error "raylib-cpp targets raylib 5. Use the `next` branch for the next version of raylib."
#endif
#ifdef __cplusplus
}
#endif
#endif // RAYLIB_CPP_INCLUDE_RAYLIB_HPP_

View File

@@ -0,0 +1,27 @@
/**
* C++ header to wrap raymath.h.
*/
#ifndef RAYLIB_CPP_INCLUDE_RAYMATH_HPP_
#define RAYLIB_CPP_INCLUDE_RAYMATH_HPP_
#ifdef __cplusplus
extern "C" {
#endif
#ifndef RAYLIB_CPP_NO_MATH
#ifndef RAYMATH_STATIC_INLINE
#define RAYMATH_STATIC_INLINE
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push // These throw a warnings on visual studio, need to check if __GNUC__ is defined to use it.
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
#include "raymath.h" // NOLINT
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif // RAYLIB_CPP_INCLUDE_RAYMATH_HPP_