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