Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clib.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"include/RenderTexture.hpp",
"include/Shader.hpp",
"include/Sound.hpp",
"include/Text.hpp",
"include/Texture.hpp",
"include/Vector2.hpp",
"include/Vector3.hpp",
Expand Down
6 changes: 3 additions & 3 deletions examples/core/core_3d_camera_first_person.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ int main() {
DrawRectangle(10, 10, 220, 70, raylib::Color::SkyBlue().Fade(0.5f));
DrawRectangleLines(10, 10, 220, 70, BLUE);

DrawText("First person camera default controls:", 20, 20, 10, BLACK);
DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY);
DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY);
raylib::DrawText("First person camera default controls:", 20, 20, 10, BLACK);
raylib::DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY);
raylib::DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY);
}
EndDrawing();
//----------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/core/core_basic_window_web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void UpdateDrawFrame(void)

ClearBackground(RAYWHITE);

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

EndDrawing();
//----------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions examples/core/core_drop_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ int main() {

// Check if there are files to process.
if (droppedFiles.empty()) {
DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY);
raylib::DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY);
} else {
DrawText("Dropped files:", 100, 40, 20, DARKGRAY);
raylib::DrawText("Dropped files:", 100, 40, 20, DARKGRAY);

// Iterate through all the dropped files.
for (int i = 0; i < droppedFiles.size(); i++) {
Expand All @@ -53,10 +53,10 @@ int main() {
DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f));

// Display the path to the dropped file.
DrawText(droppedFiles[i].c_str(), 120, 100 + 40 * i, 10, GRAY);
raylib::DrawText(droppedFiles[i].c_str(), 120, 100 + 40 * i, 10, GRAY);
}

DrawText("Drop new files...", 100, 110 + 40 * droppedFiles.size(), 20, DARKGRAY);
raylib::DrawText("Drop new files...", 100, 110 + 40 * droppedFiles.size(), 20, DARKGRAY);
}
}
EndDrawing();
Expand Down
6 changes: 3 additions & 3 deletions examples/core/core_loading_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ int main(void)
switch (state)
{
case STATE_WAITING:
DrawText("PRESS ENTER to START LOADING DATA",
raylib::DrawText("PRESS ENTER to START LOADING DATA",
150, 170, 20, DARKGRAY);
break;

case STATE_LOADING:
DrawRectangle(150, 200, dataProgress, 60, SKYBLUE);
if ((framesCounter/15)%2)
DrawText("LOADING DATA...", 240, 210, 40, DARKBLUE);
raylib::DrawText("LOADING DATA...", 240, 210, 40, DARKBLUE);
break;

case STATE_FINISHED:
DrawRectangle(150, 200, 500, 60, LIME);
DrawText("DATA LOADED!", 250, 210, 40, GREEN);
raylib::DrawText("DATA LOADED!", 250, 210, 40, GREEN);
break;
}

Expand Down
4 changes: 2 additions & 2 deletions examples/core/core_random_values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ int main() {
{
window.ClearBackground(RAYWHITE);

DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON);
raylib::DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON);

DrawText(TextFormat("%i", randValue), 360, 180, 80, LIGHTGRAY);
raylib::DrawText(TextFormat("%i", randValue), 360, 180, 80, LIGHTGRAY);
}
EndDrawing();
//----------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions examples/core/core_world_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ int main() {
}
camera.EndMode();

DrawText("Enemy: 100 / 100",
raylib::DrawText("Enemy: 100 / 100",
cubeScreenPosition.x - MeasureText("Enemy: 100/100", 20) / 2,
cubeScreenPosition.y, 20,
BLACK);
DrawText("Text is always on top of the cube",
raylib::DrawText("Text is always on top of the cube",
(screenWidth - MeasureText("Text is always on top of the cube", 20)) / 2,
25, 20, GRAY);
}
Expand Down
10 changes: 5 additions & 5 deletions examples/physics/physics_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ int main(void)
}
}

DrawText("Left mouse button to create a polygon", 10, 10, 10, WHITE);
DrawText("Right mouse button to create a circle", 10, 25, 10, WHITE);
DrawText("Press 'R' to reset example", 10, 40, 10, WHITE);
raylib::DrawText("Left mouse button to create a polygon", 10, 10, 10, WHITE);
raylib::DrawText("Right mouse button to create a circle", 10, 25, 10, WHITE);
raylib::DrawText("Press 'R' to reset example", 10, 40, 10, WHITE);

DrawText("Physac", logoX, logoY, 30, WHITE);
DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
raylib::DrawText("Physac", logoX, logoY, 30, WHITE);
raylib::DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
}
EndDrawing();
//----------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions examples/shapes/shapes_collision_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ int main(void)
boxCollision.Draw(LIME);

// Draw collision message
DrawText("COLLISION!", GetScreenWidth()/2 - MeasureText("COLLISION!", 20)/2, screenUpperLimit/2 - 10, 20, BLACK);
raylib::DrawText("COLLISION!", GetScreenWidth()/2 - MeasureText("COLLISION!", 20)/2, screenUpperLimit/2 - 10, 20, BLACK);

// Draw collision area
DrawText(TextFormat("Collision Area: %i", (int)boxCollision.width*(int)boxCollision.height), GetScreenWidth()/2 - 100, screenUpperLimit + 10, 20, BLACK);
raylib::DrawText(TextFormat("Collision Area: %i", (int)boxCollision.width*(int)boxCollision.height), GetScreenWidth()/2 - 100, screenUpperLimit + 10, 20, BLACK);
}

DrawFPS(10, 10);
Expand Down
Binary file added examples/text/resources/KAISG.ttf
Binary file not shown.
114 changes: 114 additions & 0 deletions examples/text/text_font_filters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*******************************************************************************************
*
* raylib [text] example - Font filters
*
* After font loading, font texture atlas filter could be configured for a softer
* display of the font when scaling it to different sizes, that way, it's not required
* to generate multiple fonts at multiple sizes (as long as the scaling is not very different)
*
* This example has been created using raylib 1.3.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
*
********************************************************************************************/

#include "raylib-cpp.hpp"

int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;

raylib::Window window(screenWidth, screenHeight, "raylib [text] example - font filters");

// TTF Font loading with custom generation parameters
raylib::Font font("resources/KAISG.ttf", 96);

// Generate mipmap levels to use trilinear filtering
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
GenTextureMipmaps(&font.texture);

raylib::Text msg("Loaded Font", font.GetBaseSize(), BLACK, font);

Vector2 fontPosition = { 40.0f, screenHeight/2.0f - 80.0f };
Vector2 textSize = { 0.0f, 0.0f };

// Setup texture scaling filter
SetTextureFilter(font.texture, TEXTURE_FILTER_POINT);
int currentFontFilter = 0; // TEXTURE_FILTER_POINT

SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------

// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
msg.fontSize += GetMouseWheelMove() * 4.0f;

// Choose font texture filter method
if (IsKeyPressed(KEY_ONE))
{
SetTextureFilter(font.texture, TEXTURE_FILTER_POINT);
currentFontFilter = 0;
}
else if (IsKeyPressed(KEY_TWO))
{
SetTextureFilter(font.texture, TEXTURE_FILTER_BILINEAR);
currentFontFilter = 1;
}
else if (IsKeyPressed(KEY_THREE))
{
// NOTE: Trilinear filter won't be noticed on 2D drawing
SetTextureFilter(font.texture, TEXTURE_FILTER_TRILINEAR);
currentFontFilter = 2;
}

textSize = msg.MeasureEx();

if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10;
else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10;

// Load a dropped TTF file dynamically (at current fontSize)
for (const auto& file : raylib::GetDroppedFiles()) {
if (raylib::IsFileExtension(file, ".ttf")) {
msg.font = font = raylib::Font(file, font.GetBaseSize());
}
}
//----------------------------------------------------------------------------------

// Draw
//----------------------------------------------------------------------------------
BeginDrawing();

ClearBackground(RAYWHITE);

DrawText("Use mouse wheel to change font size", 20, 20, 10, GRAY);
DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, GRAY);
DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, GRAY);
DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, DARKGRAY);

msg.Draw(fontPosition);

// TODO: It seems texSize measurement is not accurate due to chars offsets...
//DrawRectangleLines(fontPosition.x, fontPosition.y, textSize.x, textSize.y, RED);

DrawRectangle(0, screenHeight - 80, screenWidth, 80, LIGHTGRAY);
DrawText(TextFormat("Font size: %02.02f", msg.GetFontSize()), 20, screenHeight - 50, 10, DARKGRAY);
DrawText(TextFormat("Text size: [%02.02f, %02.02f]", textSize.x, textSize.y), 20, screenHeight - 30, 10, DARKGRAY);
DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, GRAY);

if (currentFontFilter == 0) DrawText("POINT", 570, 400, 20, BLACK);
else if (currentFontFilter == 1) DrawText("BILINEAR", 570, 400, 20, BLACK);
else if (currentFontFilter == 2) DrawText("TRILINEAR", 570, 400, 20, BLACK);

EndDrawing();
//----------------------------------------------------------------------------------
}

return 0;
}
6 changes: 3 additions & 3 deletions examples/text/text_font_loading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ int main() {

window.ClearBackground(RAYWHITE);

DrawText("Hold SPACE to use TTF generated font", 20, 20, 20, LIGHTGRAY);
raylib::DrawText("Hold SPACE to use TTF generated font", 20, 20, 20, LIGHTGRAY);

if (!useTtf)
{
fontBm.DrawText(msg, Vector2{ 20.0f, 100.0f }, fontBm.baseSize, 2, MAROON);
DrawText("Using BMFont (Angelcode) imported", 20, GetScreenHeight() - 30, 20, GRAY);
raylib::DrawText("Using BMFont (Angelcode) imported", 20, GetScreenHeight() - 30, 20, GRAY);
}
else
{
fontTtf.DrawText(msg, Vector2{ 20.0f, 100.0f }, fontTtf.baseSize, 2, LIME);
DrawText("Using TTF font generated", 20, GetScreenHeight() - 30, 20, GRAY);
raylib::DrawText("Using TTF font generated", 20, GetScreenHeight() - 30, 20, GRAY);
}
}
window.EndDrawing();
Expand Down
4 changes: 2 additions & 2 deletions examples/textures/textures_bunnymark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ int main(void)
}

DrawRectangle(0, 0, screenWidth, 40, BLACK);
DrawText(TextFormat("bunnies: %i", bunnies.size()), 120, 10, 20, GREEN);
DrawText(TextFormat("batched draw calls: %i", 1 + bunnies.size()/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON);
raylib::DrawText(TextFormat("bunnies: %i", bunnies.size()), 120, 10, 20, GREEN);
raylib::DrawText(TextFormat("batched draw calls: %i", 1 + bunnies.size()/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON);

DrawFPS(10, 10);
}
Expand Down
1 change: 1 addition & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ install(FILES
RenderTexture.hpp
Shader.hpp
Sound.hpp
Text.hpp
Texture.hpp
Vector2.hpp
Vector3.hpp
Expand Down
3 changes: 2 additions & 1 deletion include/Font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Font : public ::Font {
*
* @see ::LoadFontEx
*/
Font(const std::string& fileName, int fontSize, int* fontChars, int charCount) {
Font(const std::string& fileName, int fontSize, int* fontChars = 0, int charCount = 0) {
if (!Load(fileName, fontSize, fontChars, charCount)) {
throw RaylibException("Failed to load font from font with extras");
}
Expand Down Expand Up @@ -116,6 +116,7 @@ class Font : public ::Font {
GETTERSETTER(::GlyphInfo*, Glyphs, glyphs)

Font& operator=(const ::Font& font) {
Unload();
set(font);
return *this;
}
Expand Down
Loading