mirror of
https://github.com/allankoechke/raylib-cpp.git
synced 2026-12-05 17:25:42 +00:00
Add shader example and clean up (#152)
* Add shader example * Remove unused shaders * Clean up
This commit is contained in:
@@ -34,7 +34,6 @@ install(FILES
|
||||
RenderTexture.hpp
|
||||
Shader.hpp
|
||||
Sound.hpp
|
||||
Text.hpp
|
||||
Texture.hpp
|
||||
Vector2.hpp
|
||||
Vector3.hpp
|
||||
|
||||
@@ -243,6 +243,50 @@ RLCPPAPI inline bool ExportImageAsCode(const Image& image, const std::string& fi
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
} // namespace raylib
|
||||
|
||||
#endif // RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
|
||||
|
||||
@@ -618,6 +618,15 @@ class Image : public ::Image {
|
||||
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 IsLoaded() const {
|
||||
return data != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
inline void set(const ::Image& image) {
|
||||
data = image.data;
|
||||
|
||||
@@ -171,6 +171,15 @@ class Music : public ::Music {
|
||||
return ::GetMusicTimePlayed(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve whether or not the Music has been loaded.
|
||||
*
|
||||
* @return True or false depending on whether the music has been loaded.
|
||||
*/
|
||||
inline bool IsLoaded() const {
|
||||
return stream.buffer != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
inline void set(const ::Music& music) {
|
||||
ctxType = music.ctxType;
|
||||
|
||||
@@ -23,6 +23,10 @@ class Shader : public ::Shader {
|
||||
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) {
|
||||
@@ -34,11 +38,18 @@ class Shader : public ::Shader {
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
@@ -116,8 +127,8 @@ class Shader : public ::Shader {
|
||||
*
|
||||
* @see SetShaderValue()
|
||||
*/
|
||||
inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType) {
|
||||
::SetShaderValue(*this, uniformLoc, value.c_str(), uniformType);
|
||||
inline Shader& SetValue(int uniformLoc, const void* value, int uniformType) {
|
||||
::SetShaderValue(*this, uniformLoc, value, uniformType);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -126,8 +137,8 @@ class Shader : public ::Shader {
|
||||
*
|
||||
* @see SetShaderValueV()
|
||||
*/
|
||||
inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType, int count) {
|
||||
::SetShaderValueV(*this, uniformLoc, value.c_str(), uniformType, count);
|
||||
inline Shader& SetValue(int uniformLoc, const void* value, int uniformType, int count) {
|
||||
::SetShaderValueV(*this, uniformLoc, value, uniformType, count);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,15 @@ class Sound : public ::Sound {
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve whether or not the Sound buffer is loaded.
|
||||
*
|
||||
* @return True or false depending on whether the Sound buffer is loaded.
|
||||
*/
|
||||
bool IsLoaded() {
|
||||
return stream.buffer != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
inline void set(const ::Sound& sound) {
|
||||
frameCount = sound.frameCount;
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* Text drawing functions
|
||||
*/
|
||||
#ifndef RAYLIB_CPP_INCLUDE_TEXT_HPP_
|
||||
#define RAYLIB_CPP_INCLUDE_TEXT_HPP_
|
||||
|
||||
#include <string>
|
||||
|
||||
#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 {
|
||||
|
||||
/**
|
||||
* Draw text (using default font)
|
||||
*/
|
||||
RLCPPAPI inline void DrawText(
|
||||
const std::string& title,
|
||||
int posX,
|
||||
int posY,
|
||||
int fontSize,
|
||||
::Color color) {
|
||||
::DrawText(title.c_str(), posX, posY, fontSize, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
// TODO(RobLoach): Add remaining raylib C functions with string c_str() wrappers.
|
||||
|
||||
} // namespace raylib
|
||||
|
||||
#endif // RAYLIB_CPP_INCLUDE_TEXT_HPP_
|
||||
@@ -174,6 +174,15 @@ class Wave : public ::Wave {
|
||||
return LoadSound();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 IsLoaded() const {
|
||||
return data != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
inline void set(const ::Wave& wave) {
|
||||
frameCount = wave.frameCount;
|
||||
|
||||
@@ -54,7 +54,6 @@
|
||||
#include "./RenderTexture.hpp"
|
||||
#include "./Shader.hpp"
|
||||
#include "./Sound.hpp"
|
||||
#include "./Text.hpp"
|
||||
#include "./Texture.hpp"
|
||||
#include "./Vector2.hpp"
|
||||
#include "./Vector3.hpp"
|
||||
|
||||
Reference in New Issue
Block a user