summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2019-05-14 15:34:23 +0200
committerRay <[email protected]>2019-05-14 15:34:23 +0200
commit424d3ca8d9c5d612606444b2a2099cfad37f1888 (patch)
tree873e8ec9dbd5965d828ed450a8c12feafe714597
parent2edec8ae288ba70630021b330fe61c9005bc03d9 (diff)
downloadraylib-424d3ca8d9c5d612606444b2a2099cfad37f1888.tar.gz
raylib-424d3ca8d9c5d612606444b2a2099cfad37f1888.zip
examples review
Redesigns, deletes and renames Also noted authors propertly on contributed examples
-rw-r--r--examples/core/core_3d_camera_mode.c (renamed from examples/core/core_3d_mode.c)10
-rw-r--r--examples/core/core_3d_camera_mode.png (renamed from examples/core/core_3d_mode.png)bin8492 -> 8492 bytes
-rw-r--r--examples/core/core_color_select.c94
-rw-r--r--examples/core/core_color_select.pngbin14328 -> 0 bytes
-rw-r--r--examples/core/core_custom_logging.c4
-rw-r--r--examples/core/core_input_gestures.c (renamed from examples/core/core_gestures_detection.c)4
-rw-r--r--examples/core/core_input_gestures.png (renamed from examples/core/core_gestures_detection.png)bin19480 -> 19480 bytes
-rw-r--r--examples/core/core_input_mouse_wheel.c (renamed from examples/core/core_mouse_wheel.c)4
-rw-r--r--examples/core/core_input_mouse_wheel.png (renamed from examples/core/core_mouse_wheel.png)bin15375 -> 15375 bytes
-rw-r--r--examples/core/core_input_multitouch.c4
-rw-r--r--examples/core/core_loading_thread.c88
-rw-r--r--examples/core/core_window_letterbox.c (renamed from examples/core/core_window_scale_letterbox.c)4
-rw-r--r--examples/core/core_window_letterbox.png (renamed from examples/core/core_window_scale_letterbox.png)bin17967 -> 17967 bytes
-rw-r--r--examples/models/models_orthographic_projection.c6
-rw-r--r--examples/models/models_yaw_pitch_roll.c4
-rw-r--r--examples/shaders/shaders_julia_set.c208
-rw-r--r--examples/shaders/shaders_palette_switch.c4
-rw-r--r--examples/shaders/shaders_texture_drawing.c2
-rw-r--r--examples/shaders/shaders_texture_waves.c4
-rw-r--r--examples/shapes/shapes_colors_palette.c114
-rw-r--r--examples/shapes/shapes_colors_palette.pngbin6591 -> 18089 bytes
-rw-r--r--examples/shapes/shapes_draw_circle_sector.c4
-rw-r--r--examples/shapes/shapes_draw_rectangle_rounded.c4
-rw-r--r--examples/shapes/shapes_draw_ring.c4
-rw-r--r--examples/shapes/shapes_rectangle_scaling.c (renamed from examples/shapes/shapes_rectangle_scaling_mouse.c)4
-rw-r--r--examples/shapes/shapes_rectangle_scaling.png (renamed from examples/shapes/shapes_rectangle_scaling_mouse.png)bin15191 -> 15191 bytes
-rw-r--r--examples/text/text_bmfont_ttf.c40
-rw-r--r--examples/text/text_bmfont_ttf.pngbin19542 -> 20086 bytes
-rw-r--r--examples/text/text_bmfont_unordered.c65
-rw-r--r--examples/text/text_bmfont_unordered.pngbin18713 -> 0 bytes
-rw-r--r--examples/text/text_rectangle_bounds.c (renamed from examples/text/text_draw_inside_rectangle.c)6
-rw-r--r--examples/text/text_rectangle_bounds.png (renamed from examples/text/text_draw_inside_rectangle.png)bin17844 -> 17844 bytes
-rw-r--r--examples/text/text_unicode.c2
-rw-r--r--examples/textures/textures_image_npatch.pngbin18306 -> 0 bytes
-rw-r--r--examples/textures/textures_npatch_drawing.c (renamed from examples/textures/textures_image_npatch.c)43
-rw-r--r--examples/textures/textures_npatch_drawing.pngbin0 -> 26858 bytes
36 files changed, 292 insertions, 434 deletions
diff --git a/examples/core/core_3d_mode.c b/examples/core/core_3d_camera_mode.c
index 39c0752a..a4962200 100644
--- a/examples/core/core_3d_mode.c
+++ b/examples/core/core_3d_camera_mode.c
@@ -1,6 +1,6 @@
/*******************************************************************************************
*
-* raylib [core] example - Initialize 3d mode
+* raylib [core] example - Initialize 3d camera mode
*
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
@@ -15,13 +15,13 @@ int main()
{
// Initialization
//--------------------------------------------------------------------------------------
- int screenWidth = 800;
- int screenHeight = 450;
+ const int screenWidth = 800;
+ const int screenHeight = 450;
- InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode");
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera mode");
// Define the camera to look into our 3d world
- Camera3D camera;
+ Camera3D camera = { 0 };
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
diff --git a/examples/core/core_3d_mode.png b/examples/core/core_3d_camera_mode.png
index de65daeb..de65daeb 100644
--- a/examples/core/core_3d_mode.png
+++ b/examples/core/core_3d_camera_mode.png
Binary files differ
diff --git a/examples/core/core_color_select.c b/examples/core/core_color_select.c
deleted file mode 100644
index 002a6931..00000000
--- a/examples/core/core_color_select.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/*******************************************************************************************
-*
-* raylib [core] example - Color selection by mouse (collision detection)
-*
-* This example has been created using raylib 1.0 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2014 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- int screenWidth = 800;
- int screenHeight = 450;
-
- InitWindow(screenWidth, screenHeight, "raylib [core] example - color selection (collision detection)");
-
- Color colors[21] = { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
- GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
- GREEN, SKYBLUE, PURPLE, BEIGE };
-
- Rectangle colorsRecs[21]; // Rectangles array
-
- // Fills colorsRecs data (for every rectangle)
- for (int i = 0; i < 21; i++)
- {
- colorsRecs[i].x = 20 + 100*(i%7) + 10*(i%7);
- colorsRecs[i].y = 60 + 100*(i/7) + 10*(i/7);
- colorsRecs[i].width = 100;
- colorsRecs[i].height = 100;
- }
-
- bool selected[21] = { false }; // Selected rectangles indicator
-
- Vector2 mousePoint;
-
- 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
- //----------------------------------------------------------------------------------
- mousePoint = GetMousePosition();
-
- for (int i = 0; i < 21; i++) // Iterate along all the rectangles
- {
- if (CheckCollisionPointRec(mousePoint, colorsRecs[i]))
- {
- colors[i].a = 120;
-
- if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selected[i] = !selected[i];
- }
- else colors[i].a = 255;
- }
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- for (int i = 0; i < 21; i++) // Draw all rectangles
- {
- DrawRectangleRec(colorsRecs[i], colors[i]);
-
- // Draw four rectangles around selected rectangle
- if (selected[i])
- {
- DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 100, 10, RAYWHITE); // Square top rectangle
- DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 10, 100, RAYWHITE); // Square left rectangle
- DrawRectangle(colorsRecs[i].x + 90, colorsRecs[i].y, 10, 100, RAYWHITE); // Square right rectangle
- DrawRectangle(colorsRecs[i].x, colorsRecs[i].y + 90, 100, 10, RAYWHITE); // Square bottom rectangle
- }
- }
-
- EndDrawing();
- //----------------------------------------------------------------------------------
- }
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-} \ No newline at end of file
diff --git a/examples/core/core_color_select.png b/examples/core/core_color_select.png
deleted file mode 100644
index 93ab83ae..00000000
--- a/examples/core/core_color_select.png
+++ /dev/null
Binary files differ
diff --git a/examples/core/core_custom_logging.c b/examples/core/core_custom_logging.c
index 4c4caf5d..cf1a601f 100644
--- a/examples/core/core_custom_logging.c
+++ b/examples/core/core_custom_logging.c
@@ -5,7 +5,9 @@
* This example has been created using raylib 2.1 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2018 Ramon Santamaria (@raysan5) and Pablo Marcos Oltra (@pamarcos)
+* Example contributed by Pablo Marcos Oltra (@pamarcos) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Pablo Marcos Oltra (@pamarcos) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/core/core_gestures_detection.c b/examples/core/core_input_gestures.c
index 63a1e6bd..ce2ed86c 100644
--- a/examples/core/core_gestures_detection.c
+++ b/examples/core/core_input_gestures.c
@@ -1,6 +1,6 @@
/*******************************************************************************************
*
-* raylib [core] example - Gestures Detection
+* raylib [core] example - Input Gestures Detection
*
* This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
@@ -21,7 +21,7 @@ int main()
int screenWidth = 800;
int screenHeight = 450;
- InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection");
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures");
Vector2 touchPosition = { 0, 0 };
Rectangle touchArea = { 220, 10, screenWidth - 230, screenHeight - 20 };
diff --git a/examples/core/core_gestures_detection.png b/examples/core/core_input_gestures.png
index d2bbb5d7..d2bbb5d7 100644
--- a/examples/core/core_gestures_detection.png
+++ b/examples/core/core_input_gestures.png
Binary files differ
diff --git a/examples/core/core_mouse_wheel.c b/examples/core/core_input_mouse_wheel.c
index 6a5252ee..48cf7042 100644
--- a/examples/core/core_mouse_wheel.c
+++ b/examples/core/core_input_mouse_wheel.c
@@ -1,6 +1,6 @@
/*******************************************************************************************
*
-* raylib [core] examples - Mouse wheel
+* raylib [core] examples - Mouse wheel input
*
* This test has been created using raylib 1.1 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
@@ -18,7 +18,7 @@ int main()
int screenWidth = 800;
int screenHeight = 450;
- InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel");
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - input mouse wheel");
int boxPositionY = screenHeight/2 - 40;
int scrollSpeed = 4; // Scrolling speed in pixels
diff --git a/examples/core/core_mouse_wheel.png b/examples/core/core_input_mouse_wheel.png
index 26a1f243..26a1f243 100644
--- a/examples/core/core_mouse_wheel.png
+++ b/examples/core/core_input_mouse_wheel.png
Binary files differ
diff --git a/examples/core/core_input_multitouch.c b/examples/core/core_input_multitouch.c
index ef8fa7ae..5baab271 100644
--- a/examples/core/core_input_multitouch.c
+++ b/examples/core/core_input_multitouch.c
@@ -5,7 +5,9 @@
* This example has been created using raylib 2.1 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2014-2019 Berni and Ramon Santamaria (@raysan5)
+* Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2019 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/core/core_loading_thread.c b/examples/core/core_loading_thread.c
index 4ffc9d0b..1dacd69f 100644
--- a/examples/core/core_loading_thread.c
+++ b/examples/core/core_loading_thread.c
@@ -15,10 +15,13 @@
#include "raylib.h"
#include "pthread.h" // POSIX style threads management
-#include <stdatomic.h>
-#include <time.h> // Required for clock() function
+#include <stdatomic.h> // C11 atomic data types
+#include <time.h> // Required for: clock()
+
+// Using C11 atomics for synchronization
+// NOTE: A plain bool (or any plain data type for that matter) can't be used for inter-thread synchronization
static atomic_bool dataLoaded = ATOMIC_VAR_INIT(false); // Data Loaded completion indicator
static void *LoadDataThread(void *arg); // Loading data thread function declaration
@@ -48,33 +51,37 @@ int main()
//----------------------------------------------------------------------------------
switch (state)
{
- case STATE_WAITING:
- if (IsKeyPressed(KEY_ENTER))
+ case STATE_WAITING:
{
- int error = pthread_create(&threadId, NULL, &LoadDataThread, NULL);
- if (error != 0) TraceLog(LOG_ERROR, "Error creating loading thread");
- else TraceLog(LOG_INFO, "Loading thread initialized successfully");
-
- state = STATE_LOADING;
- }
- break;
- case STATE_LOADING:
- framesCounter++;
- if (atomic_load(&dataLoaded))
+ if (IsKeyPressed(KEY_ENTER))
+ {
+ int error = pthread_create(&threadId, NULL, &LoadDataThread, NULL);
+ if (error != 0) TraceLog(LOG_ERROR, "Error creating loading thread");
+ else TraceLog(LOG_INFO, "Loading thread initialized successfully");
+
+ state = STATE_LOADING;
+ }
+ } break;
+ case STATE_LOADING:
{
- framesCounter = 0;
- state = STATE_FINISHED;
- }
- break;
- case STATE_FINISHED:
- if (IsKeyPressed(KEY_ENTER))
+ framesCounter++;
+ if (atomic_load(&dataLoaded))
+ {
+ framesCounter = 0;
+ state = STATE_FINISHED;
+ }
+ } break;
+ case STATE_FINISHED:
{
- // Reset everything to launch again
- atomic_store(&dataLoaded, false);
- dataProgress = 0;
- state = STATE_WAITING;
- }
- break;
+ if (IsKeyPressed(KEY_ENTER))
+ {
+ // Reset everything to launch again
+ atomic_store(&dataLoaded, false);
+ dataProgress = 0;
+ state = STATE_WAITING;
+ }
+ } break;
+ default: break;
}
//----------------------------------------------------------------------------------
@@ -84,19 +91,22 @@ int main()
ClearBackground(RAYWHITE);
- switch(state) {
- case STATE_WAITING:
- 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);
- break;
- case STATE_FINISHED:
- DrawRectangle(150, 200, 500, 60, LIME);
- DrawText("DATA LOADED!", 250, 210, 40, GREEN);
- break;
+ switch (state)
+ {
+ case STATE_WAITING: 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);
+
+ } break;
+ case STATE_FINISHED:
+ {
+ DrawRectangle(150, 200, 500, 60, LIME);
+ DrawText("DATA LOADED!", 250, 210, 40, GREEN);
+
+ } break;
+ default: break;
}
DrawRectangleLines(150, 200, 500, 60, DARKGRAY);
diff --git a/examples/core/core_window_scale_letterbox.c b/examples/core/core_window_letterbox.c
index ea4a375a..8c0843d2 100644
--- a/examples/core/core_window_scale_letterbox.c
+++ b/examples/core/core_window_letterbox.c
@@ -5,7 +5,9 @@
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2019 Anata and Ramon Santamaria (@raysan5)
+* Example contributed by Anata (@anatagawa) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2019 Anata (@anatagawa) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/core/core_window_scale_letterbox.png b/examples/core/core_window_letterbox.png
index 5acf2d7c..5acf2d7c 100644
--- a/examples/core/core_window_scale_letterbox.png
+++ b/examples/core/core_window_letterbox.png
Binary files differ
diff --git a/examples/models/models_orthographic_projection.c b/examples/models/models_orthographic_projection.c
index f9b54b6d..3ad32b60 100644
--- a/examples/models/models_orthographic_projection.c
+++ b/examples/models/models_orthographic_projection.c
@@ -4,10 +4,12 @@
*
* This program is heavily based on the geometric objects example
*
-* This example has been created using raylib 1.9.7 (www.raylib.com)
+* This example has been created using raylib 2.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2018 Max Danielsson & Ramon Santamaria (@raysan5)
+* Example contributed by Max Danielsson (@autious) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Max Danielsson (@autious) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/models/models_yaw_pitch_roll.c b/examples/models/models_yaw_pitch_roll.c
index 7eaaf0be..658be084 100644
--- a/examples/models/models_yaw_pitch_roll.c
+++ b/examples/models/models_yaw_pitch_roll.c
@@ -5,9 +5,9 @@
* This example has been created using raylib 1.8 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Example based on Berni work on Raspberry Pi.
+* Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5)
*
-* Copyright (c) 2017 Ramon Santamaria (@raysan5)
+* Copyright (c) 2017 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/shaders/shaders_julia_set.c b/examples/shaders/shaders_julia_set.c
index 381cd33e..c4dac6d2 100644
--- a/examples/shaders/shaders_julia_set.c
+++ b/examples/shaders/shaders_julia_set.c
@@ -1,6 +1,6 @@
/*******************************************************************************************
*
-* raylib [shaders] example - Render julia sets using a shader.
+* raylib [shaders] example - julia sets
*
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
@@ -10,73 +10,68 @@
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Author: eggmund (https://github.com/eggmund)
+* Example contributed by eggmund (@eggmund) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2019 eggmund (@eggmund) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
-#include <string.h> // For memcpy
-// Speed when using auto
-const float AUTO_SPEED = 0.0005;
+#include "raymath.h"
// A few good julia sets
const float POINTS_OF_INTEREST[6][2] =
{
- {-0.348827, 0.607167},
- {-0.786268, 0.169728},
- {-0.8, 0.156},
- {0.285, 0.0},
- {-0.835, -0.2321},
- {-0.70176, -0.3842},
+ { -0.348827, 0.607167 },
+ { -0.786268, 0.169728 },
+ { -0.8, 0.156 },
+ { 0.285, 0.0 },
+ { -0.835, -0.2321 },
+ { -0.70176, -0.3842 },
};
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
- int screenWidth = 1280;
- int screenHeight = 720;
-
- InitWindow(screenWidth, screenHeight, "raylib [shaders] example - julia set renderer");
-
- // If julia set is rendered for this frame.
- bool rendered = false;
-
- bool showControls = true;
-
- // Multiplier of speed to change c value. Set to 3 to start off with.
- int incrementSpeed = 3;
-
- // Offset and zoom to draw the julia set at. (centered on screen and 1.6 times smaller)
- float offset[2] = { -(float)screenWidth/2, -(float)screenHeight/2 };
- float zoom = 1.6;
+ const int screenWidth = 800;
+ const int screenHeight = 450;
- // c constant to use in z^2 + c
- float c[2];
- // Copy a point of interest into the c variable. 4 bytes per float (32 bits).
- memcpy(c, &POINTS_OF_INTEREST[0], 8);
+ InitWindow(screenWidth, screenHeight, "raylib [shaders] example - julia sets");
// Load julia set shader
// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
Shader shader = LoadShader(0, "resources/shaders/glsl330/julia_shader.fs");
- // Get variable (uniform) location on the shader to connect with the program
+ // c constant to use in z^2 + c
+ float c[2] = { POINTS_OF_INTEREST[0][0], POINTS_OF_INTEREST[0][1] };
+
+ // Offset and zoom to draw the julia set at. (centered on screen and 1.6 times smaller)
+ float offset[2] = { -(float)screenWidth/2, -(float)screenHeight/2 };
+ float zoom = 1.6f;
+
+ // Get variable (uniform) locations on the shader to connect with the program
// NOTE: If uniform variable could not be found in the shader, function returns -1
- // The location of c will be stored since we will need to change this whenever c changes
int cLoc = GetShaderLocation(shader, "c");
+ int zoomLoc = GetShaderLocation(shader, "zoom");
+ int offsetLoc = GetShaderLocation(shader, "offset");
// Tell the shader what the screen dimensions, zoom, offset and c are
float screenDims[2] = { (float)screenWidth, (float)screenHeight };
SetShaderValue(shader, GetShaderLocation(shader, "screenDims"), screenDims, UNIFORM_VEC2);
- SetShaderValue(shader, GetShaderLocation(shader, "zoom"), &zoom, UNIFORM_FLOAT);
- SetShaderValue(shader, GetShaderLocation(shader, "offset"), offset, UNIFORM_VEC2);
-
- SetShaderValue(shader, cLoc, c, UNIFORM_VEC2);
+ SetShaderValue(shader, cLoc, c, UNIFORM_VEC2);
+ SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT);
+ SetShaderValue(shader, offsetLoc, offset, UNIFORM_VEC2);
+
// Create a RenderTexture2D to be used for render to texture
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
+ int incrementSpeed = 3; // Multiplier of speed to change c value
+ bool showControls = true; // Show controls
+ bool pause = false; // Pause animation
+
SetTargetFPS(60); // Set the window to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -86,115 +81,86 @@ int main()
// Update
//----------------------------------------------------------------------------------
- // Get input
- //----------------------------------------------------------------------------------
-
- // Press 1 - 6 to reset c to a point of interest.
- if (IsKeyPressed(KEY_ONE) || IsKeyPressed(KEY_TWO) || IsKeyPressed(KEY_THREE) || IsKeyPressed(KEY_FOUR) || IsKeyPressed(KEY_FIVE) || IsKeyPressed(KEY_SIX))
+ // Press [1 - 6] to reset c to a point of interest
+ if (IsKeyPressed(KEY_ONE) ||
+ IsKeyPressed(KEY_TWO) ||
+ IsKeyPressed(KEY_THREE) ||
+ IsKeyPressed(KEY_FOUR) ||
+ IsKeyPressed(KEY_FIVE) ||
+ IsKeyPressed(KEY_SIX))
{
- if (IsKeyPressed(KEY_ONE))
- {
- memcpy(c, &POINTS_OF_INTEREST[0], 8);
- }
- else if (IsKeyPressed(KEY_TWO))
- {
- memcpy(c, &POINTS_OF_INTEREST[1], 8);
- }
- else if (IsKeyPressed(KEY_THREE))
- {
- memcpy(c, &POINTS_OF_INTEREST[2], 8);
- }
- else if (IsKeyPressed(KEY_FOUR))
- {
- memcpy(c, &POINTS_OF_INTEREST[3], 8);
- }
- else if (IsKeyPressed(KEY_FIVE))
- {
- memcpy(c, &POINTS_OF_INTEREST[4], 8);
- }
- else if (IsKeyPressed(KEY_SIX))
- {
- memcpy(c, &POINTS_OF_INTEREST[5], 8);
- }
- SetShaderValue(shader, cLoc, c, UNIFORM_VEC2);
- rendered = false; // c value has changed, so render the set again.
- }
+ if (IsKeyPressed(KEY_ONE)) c[0] = POINTS_OF_INTEREST[0][0], c[1] = POINTS_OF_INTEREST[0][1];
+ else if (IsKeyPressed(KEY_TWO)) c[0] = POINTS_OF_INTEREST[1][0], c[1] = POINTS_OF_INTEREST[1][1];
+ else if (IsKeyPressed(KEY_THREE)) c[0] = POINTS_OF_INTEREST[2][0], c[1] = POINTS_OF_INTEREST[2][1];
+ else if (IsKeyPressed(KEY_FOUR)) c[0] = POINTS_OF_INTEREST[3][0], c[1] = POINTS_OF_INTEREST[3][1];
+ else if (IsKeyPressed(KEY_FIVE)) c[0] = POINTS_OF_INTEREST[4][0], c[1] = POINTS_OF_INTEREST[4][1];
+ else if (IsKeyPressed(KEY_SIX)) c[0] = POINTS_OF_INTEREST[5][0], c[1] = POINTS_OF_INTEREST[5][1];
- // Press "r" to stop changing c
- if (IsKeyPressed(KEY_R))
- {
- incrementSpeed = 0;
+ SetShaderValue(shader, cLoc, c, UNIFORM_VEC2);
}
- // Toggle whether or not to show controls
- if (IsKeyPressed(KEY_H))
+ if (IsKeyPressed(KEY_P)) pause = !pause; // Pause animation (c change)
+ if (IsKeyPressed(KEY_F1)) showControls = !showControls; // Toggle whether or not to show controls
+
+ if (!pause)
{
- showControls = !showControls;
- }
+ if (IsKeyDown(KEY_RIGHT)) incrementSpeed++;
+ else if (IsKeyDown(KEY_LEFT)) incrementSpeed--;
- // Scroll to change c increment speed.
- int mouseMv = GetMouseWheelMove(); // Get the amount the mouse has moved this frame
- if (mouseMv != 0)
- {
- if (IsKeyDown(KEY_LEFT_SHIFT))
- {
- incrementSpeed += mouseMv * 10;
- }
- else
+ // Use mouse wheel to change zoom
+ zoom -= (float)GetMouseWheelMove()/10.f;
+ SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT);
+
+ // Use mouse button to change offset
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
{
- incrementSpeed += mouseMv;
+ // TODO: Logic is not correct, the idea is getting zoom focus to pointed area
+ Vector2 mousePos = GetMousePosition();
+
+ offset[0] = mousePos.x -(float)screenWidth;
+ offset[1] = mousePos.y -(float)screenHeight;
+
+ SetShaderValue(shader, offsetLoc, offset, UNIFORM_VEC2);
}
- rendered = false;
- }
- if (incrementSpeed != 0)
- {
- float amount = GetFrameTime() * incrementSpeed * AUTO_SPEED;
+ // Increment c value with time
+ float amount = GetFrameTime()*incrementSpeed*0.0005f;
c[0] += amount;
c[1] += amount;
- // Update the c value in the shader.
SetShaderValue(shader, cLoc, c, UNIFORM_VEC2);
- rendered = false;
}
-
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
- ClearBackground(BLACK); // Clear the screen of the previous frame.
+ ClearBackground(BLACK); // Clear the screen of the previous frame.
- // If the c value has changed, redraw the julia set using the shader, onto the render texture.
- if (!rendered)
- {
- BeginTextureMode(target); // Enable drawing to texture
-
- ClearBackground(BLACK); // Clear the last frame drawn on the texture.
-
- // Draw a rectangle in shader mode. This acts as a canvas for the shader to draw on.
- BeginShaderMode(shader);
- DrawRectangle(0, 0, screenWidth, screenHeight, BLACK);
- EndShaderMode();
-
- EndTextureMode();
-
- rendered = true; // The set is now rendered, so do not compute it again until it next changes.
- }
-
- // Draw the saved texture (rendered julia set).
- DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, target.texture.height }, (Vector2){ 0, 0 }, WHITE);
+ // Using a render texture to draw Julia set
+ BeginTextureMode(target); // Enable drawing to texture
+ ClearBackground(BLACK); // Clear the render texture
+
+ // Draw a rectangle in shader mode
+ // NOTE: This acts as a canvas for the shader to draw on
+ BeginShaderMode(shader);
+ DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
+ EndShaderMode();
+ EndTextureMode();
+
+ // Draw the saved texture (rendered julia set)
+ DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, Vector2Zero(), WHITE);
- // Print information.
- DrawText( FormatText("cx: %f\ncy: %f\nspeed: %d", c[0], c[1], incrementSpeed), 10, 10, 20, RAYWHITE );
+ // Draw information
+ //DrawText( FormatText("cx: %f\ncy: %f\nspeed: %d", c[0], c[1], incrementSpeed), 10, 10, 10, RAYWHITE);
if (showControls)
{
- DrawText("Press keys 1 - 6 to change point of interest.", 10, screenHeight - 88, 20, RAYWHITE);
- DrawText("Use the scroll wheel to auto increment the c value. Hold shift while scrolling to increase speed by 10.", 10, screenHeight - 66, 20, RAYWHITE);
- DrawText("Press 'r' to reset speed.", 10, screenHeight - 44, 20, RAYWHITE);
- DrawText("Press 'h' to hide these controls.", 10, screenHeight - 22, 20, RAYWHITE);
+ DrawText("Press keys [1 - 6] to change point of interest", 10, GetScreenHeight() - 60, 10, RAYWHITE);
+ DrawText("Press KEY_LEFT | KEY_RIGHT to change speed", 10, GetScreenHeight() - 45, 10, RAYWHITE);
+ DrawText("Press KEY_P to pause movement animation", 10, GetScreenHeight() - 30, 10, RAYWHITE);
+ DrawText("Press KEY_F1 to toggle these controls", 10, GetScreenHeight() - 15, 10, RAYWHITE);
}
EndDrawing();
diff --git a/examples/shaders/shaders_palette_switch.c b/examples/shaders/shaders_palette_switch.c
index a2fa0b27..fa0bafaf 100644
--- a/examples/shaders/shaders_palette_switch.c
+++ b/examples/shaders/shaders_palette_switch.c
@@ -12,7 +12,9 @@
* This example has been created using raylib 2.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2019 Ramon Santamaria (@raysan5)
+* Example contributed by Marco Lizza (@MarcoLizza) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2019 Marco Lizza (@MarcoLizza) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/shaders/shaders_texture_drawing.c b/examples/shaders/shaders_texture_drawing.c
index f5758273..3a540098 100644
--- a/examples/shaders/shaders_texture_drawing.c
+++ b/examples/shaders/shaders_texture_drawing.c
@@ -7,6 +7,8 @@
* This example has been created using raylib 2.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
+* Example contributed by Michał Ciesielski and reviewed by Ramon Santamaria (@raysan5)
+*
* Copyright (c) 2019 Michał Ciesielski and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/shaders/shaders_texture_waves.c b/examples/shaders/shaders_texture_waves.c
index 03c62deb..bc677c78 100644
--- a/examples/shaders/shaders_texture_waves.c
+++ b/examples/shaders/shaders_texture_waves.c
@@ -12,7 +12,9 @@
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2019 Anata (creator) and Ramon Santamaria (review) (@raysan5)
+* Example contributed by Anata (@anatagawa) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2019 Anata (@anatagawa) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/shapes/shapes_colors_palette.c b/examples/shapes/shapes_colors_palette.c
index dcab862e..d6ac30a9 100644
--- a/examples/shapes/shapes_colors_palette.c
+++ b/examples/shapes/shapes_colors_palette.c
@@ -1,26 +1,53 @@
/*******************************************************************************************
*
-* raylib [shapes] example - Draw raylib custom color palette
+* raylib [shapes] example - Colors palette
*
-* This example has been created using raylib 1.0 (www.raylib.com)
+* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2014 Ramon Santamaria (@raysan5)
+* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
+#define MAX_COLORS_COUNT 21 // Number of colors available
+
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
- int screenWidth = 800;
- int screenHeight = 450;
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - colors palette");
+
+ Color colors[MAX_COLORS_COUNT] = {
+ DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
+ GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
+ GREEN, SKYBLUE, PURPLE, BEIGE };
+
+ const char *colorNames[MAX_COLORS_COUNT] = {
+ "DARKGRAY", "MAROON", "ORANGE", "DARKGREEN", "DARKBLUE", "DARKPURPLE",
+ "DARKBROWN", "GRAY", "RED", "GOLD", "LIME", "BLUE", "VIOLET", "BROWN",
+ "LIGHTGRAY", "PINK", "YELLOW", "GREEN", "SKYBLUE", "PURPLE", "BEIGE" };
+
+ Rectangle colorsRecs[MAX_COLORS_COUNT] = { 0 }; // Rectangles array
+
+ // Fills colorsRecs data (for every rectangle)
+ for (int i = 0; i < MAX_COLORS_COUNT; i++)
+ {
+ colorsRecs[i].x = 20 + 100*(i%7) + 10*(i%7);
+ colorsRecs[i].y = 80 + 100*(i/7) + 10*(i/7);
+ colorsRecs[i].width = 100;
+ colorsRecs[i].height = 100;
+ }
+
+ int colorState[MAX_COLORS_COUNT] = { 0 }; // Color state: 0-DEFAULT, 1-MOUSE_HOVER
- InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette");
-
- SetTargetFPS(60);
+ Vector2 mousePoint;
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
@@ -28,7 +55,13 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
- // TODO: Update your variables here
+ mousePoint = GetMousePosition();
+
+ for (int i = 0; i < MAX_COLORS_COUNT; i++)
+ {
+ if (CheckCollisionPointRec(mousePoint, colorsRecs[i])) colorState[i] = 1;
+ else colorState[i] = 0;
+ }
//----------------------------------------------------------------------------------
// Draw
@@ -36,53 +69,22 @@ int main()
BeginDrawing();
ClearBackground(RAYWHITE);
+
+ DrawText("raylib colors palette", 28, 42, 20, BLACK);
+ DrawText("press SPACE to see all colors", GetScreenWidth() - 180, GetScreenHeight() - 40, 10, GRAY);
- DrawText("raylib color palette", 28, 42, 20, BLACK);
-
- DrawRectangle(26, 80, 100, 100, DARKGRAY);
- DrawRectangle(26, 188, 100, 100, GRAY);
- DrawRectangle(26, 296, 100, 100, LIGHTGRAY);
- DrawRectangle(134, 80, 100, 100, MAROON);
- DrawRectangle(134, 188, 100, 100, RED);
- DrawRectangle(134, 296, 100, 100, PINK);
- DrawRectangle(242, 80, 100, 100, ORANGE);
- DrawRectangle(242, 188, 100, 100, GOLD);
- DrawRectangle(242, 296, 100, 100, YELLOW);
- DrawRectangle(350, 80, 100, 100, DARKGREEN);
- DrawRectangle(350, 188, 100, 100, LIME);
- DrawRectangle(350, 296, 100, 100, GREEN);
- DrawRectangle(458, 80, 100, 100, DARKBLUE);
- DrawRectangle(458, 188, 100, 100, BLUE);
- DrawRectangle(458, 296, 100, 100, SKYBLUE);
- DrawRectangle(566, 80, 100, 100, DARKPURPLE);
- DrawRectangle(566, 188, 100, 100, VIOLET);
- DrawRectangle(566, 296, 100, 100, PURPLE);
- DrawRectangle(674, 80, 100, 100, DARKBROWN);
- DrawRectangle(674, 188, 100, 100, BROWN);
- DrawRectangle(674, 296, 100, 100, BEIGE);
-
-
- DrawText("DARKGRAY", 65, 166, 10, BLACK);
- DrawText("GRAY", 93, 274, 10, BLACK);
- DrawText("LIGHTGRAY", 61, 382, 10, BLACK);
- DrawText("MAROON", 186, 166, 10, BLACK);
- DrawText("RED", 208, 274, 10, BLACK);
- DrawText("PINK", 204, 382, 10, BLACK);
- DrawText("ORANGE", 295, 166, 10, BLACK);
- DrawText("GOLD", 310, 274, 10, BLACK);
- DrawText("YELLOW", 300, 382, 10, BLACK);
- DrawText("DARKGREEN", 382, 166, 10, BLACK);
- DrawText("LIME", 420, 274, 10, BLACK);
- DrawText("GREEN", 410, 382, 10, BLACK);
- DrawText("DARKBLUE", 498, 166, 10, BLACK);
- DrawText("BLUE", 526, 274, 10, BLACK);
- DrawText("SKYBLUE", 505, 382, 10, BLACK);
- DrawText("DARKPURPLE", 592, 166, 10, BLACK);
- DrawText("VIOLET", 621, 274, 10, BLACK);
- DrawText("PURPLE", 620, 382, 10, BLACK);
- DrawText("DARKBROWN", 705, 166, 10, BLACK);
- DrawText("BROWN", 733, 274, 10, BLACK);
- DrawText("BEIGE", 737, 382, 10, BLACK);
+ for (int i = 0; i < MAX_COLORS_COUNT; i++) // Draw all rectangles
+ {
+ DrawRectangleRec(colorsRecs[i], Fade(colors[i], colorState[i]? 0.6f : 1.0f));
+
+ if (IsKeyDown(KEY_SPACE) || colorState[i])
+ {
+ DrawRectangle(colorsRecs[i].x, colorsRecs[i].y + colorsRecs[i].height - 26, colorsRecs[i].width, 20, BLACK);
+ DrawRectangleLinesEx(colorsRecs[i], 6, Fade(BLACK, 0.3f));
+ DrawText(colorNames[i], colorsRecs[i].x + colorsRecs[i].width - MeasureText(colorNames[i], 10) - 12,
+ colorsRecs[i].y + colorsRecs[i].height - 20, 10, colors[i]);
+ }
+ }
EndDrawing();
//----------------------------------------------------------------------------------
@@ -90,7 +92,7 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
- CloseWindow(); // Close window and OpenGL context
+ CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
diff --git a/examples/shapes/shapes_colors_palette.png b/examples/shapes/shapes_colors_palette.png
index 4073b670..b68e497e 100644
--- a/examples/shapes/shapes_colors_palette.png
+++ b/examples/shapes/shapes_colors_palette.png
Binary files differ
diff --git a/examples/shapes/shapes_draw_circle_sector.c b/examples/shapes/shapes_draw_circle_sector.c
index a88a59d5..597b85a7 100644
--- a/examples/shapes/shapes_draw_circle_sector.c
+++ b/examples/shapes/shapes_draw_circle_sector.c
@@ -5,7 +5,9 @@
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2019 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5)
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/shapes/shapes_draw_rectangle_rounded.c b/examples/shapes/shapes_draw_rectangle_rounded.c
index 35fe63fb..e36e2731 100644
--- a/examples/shapes/shapes_draw_rectangle_rounded.c
+++ b/examples/shapes/shapes_draw_rectangle_rounded.c
@@ -5,7 +5,9 @@
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2019 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5)
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/shapes/shapes_draw_ring.c b/examples/shapes/shapes_draw_ring.c
index d56b9c2e..44a3ec5f 100644
--- a/examples/shapes/shapes_draw_ring.c
+++ b/examples/shapes/shapes_draw_ring.c
@@ -5,7 +5,9 @@
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2019 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5)
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/shapes/shapes_rectangle_scaling_mouse.c b/examples/shapes/shapes_rectangle_scaling.c
index d8c521ca..036a1dd4 100644
--- a/examples/shapes/shapes_rectangle_scaling_mouse.c
+++ b/examples/shapes/shapes_rectangle_scaling.c
@@ -5,7 +5,9 @@
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2019 Demioz and Ramon Santamaria (@raysan5)
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/shapes/shapes_rectangle_scaling_mouse.png b/examples/shapes/shapes_rectangle_scaling.png
index 83d67de9..83d67de9 100644
--- a/examples/shapes/shapes_rectangle_scaling_mouse.png
+++ b/examples/shapes/shapes_rectangle_scaling.png
Binary files differ
diff --git a/examples/text/text_bmfont_ttf.c b/examples/text/text_bmfont_ttf.c
index f71f5ddb..ca26b2cf 100644
--- a/examples/text/text_bmfont_ttf.c
+++ b/examples/text/text_bmfont_ttf.c
@@ -20,17 +20,20 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading");
- const char msgBm[64] = "THIS IS AN AngelCode SPRITE FONT";
- const char msgTtf[64] = "THIS SPRITE FONT has been GENERATED from a TTF";
+ // Define characters to draw
+ // NOTE: raylib supports UTF-8 encoding, following list is actually codified as UTF8 internally
+ const char msg[256] = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI\nJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmn\nopqrstuvwxyz{|}~¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓ\nÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷\nøùúûüýþÿ";
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
- Font fontBm = LoadFont("resources/bmfont.fnt"); // BMFont (AngelCode)
- Font fontTtf = LoadFont("resources/pixantiqua.ttf"); // TTF font
-
- Vector2 fontPosition;
-
- fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.baseSize, 0).x/2;
- fontPosition.y = screenHeight/2 - fontBm.baseSize/2 - 80;
+
+ // BMFont (AngelCode) : Font data and image atlas have been generated using external program
+ Font fontBm = LoadFont("resources/pixantiqua.fnt");
+
+ // TTF font : Font data and atlas are generated directly from TTF
+ // NOTE: We define a font base size of 32 pixels tall and up-to 250 characters
+ Font fontTtf = LoadFontEx("resources/pixantiqua.ttf", 32, 0, 250);
+
+ bool useTtf = false;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@@ -40,7 +43,8 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
- // TODO: Update variables here...
+ if (IsKeyDown(KEY_SPACE)) useTtf = true;
+ else useTtf = false;
//----------------------------------------------------------------------------------
// Draw
@@ -48,9 +52,19 @@ int main()
BeginDrawing();
ClearBackground(RAYWHITE);
-
- DrawTextEx(fontBm, msgBm, fontPosition, fontBm.baseSize, 0, MAROON);
- DrawTextEx(fontTtf, msgTtf, (Vector2){ 75.0f, 240.0f }, fontTtf.baseSize*0.8f, 2, LIME);
+
+ DrawText("Press SPACE to use TTF generated font", 20, 20, 20, LIGHTGRAY);
+
+ if (!useTtf)
+ {
+ DrawTextEx(fontBm, msg, (Vector2){ 20.0f, 100.0f }, fontBm.baseSize, 2, MAROON);
+ DrawText("Using BMFont (Angelcode) imported", 20, GetScreenHeight() - 30, 20, GRAY);
+ }
+ else
+ {
+ DrawTextEx(fontTtf, msg, (Vector2){ 20.0f, 100.0f }, fontTtf.baseSize, 2, LIME);
+ DrawText("Using TTF font generated", 20, GetScreenHeight() - 30, 20, GRAY);
+ }
EndDrawing();
//----------------------------------------------------------------------------------
diff --git a/examples/text/text_bmfont_ttf.png b/examples/text/text_bmfont_ttf.png
index 8305d36b..a99027ad 100644
--- a/examples/text/text_bmfont_ttf.png
+++ b/examples/text/text_bmfont_ttf.png
Binary files differ
diff --git a/examples/text/text_bmfont_unordered.c b/examples/text/text_bmfont_unordered.c
deleted file mode 100644
index a5147619..00000000
--- a/examples/text/text_bmfont_unordered.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************************
-*
-* raylib [text] example - BMFont unordered chars loading and drawing
-*
-* This example has been created using raylib 1.4 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2016 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-int main()
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- int screenWidth = 800;
- int screenHeight = 450;
-
- InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont unordered loading and drawing");
-
- // NOTE: Using chars outside the [32..127] limits!
- // NOTE: If a character is not found in the font, it just renders a space
- const char msg[256] = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
-
- // NOTE: Loaded font has an unordered list of characters (chars in the range 32..255)
- Font font = LoadFont("resources/pixantiqua.fnt"); // BMFont (AngelCode)
-
- SetTargetFPS(60);
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- // TODO: Update variables here...
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY);
- DrawText(FormatText("Font base size: %i", font.baseSize), 40, 80, 20, GRAY);
- DrawText(FormatText("Font chars number: %i", font.charsCount), 40, 110, 20, GRAY);
-
- DrawTextEx(font, msg, (Vector2){ 40, 180 }, font.baseSize, 0, MAROON);
-
- EndDrawing();
- //----------------------------------------------------------------------------------
- }
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadFont(font); // AngelCode Font unloading
-
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-} \ No newline at end of file
diff --git a/examples/text/text_bmfont_unordered.png b/examples/text/text_bmfont_unordered.png
deleted file mode 100644
index c6767567..00000000
--- a/examples/text/text_bmfont_unordered.png
+++ /dev/null
Binary files differ
diff --git a/examples/text/text_draw_inside_rectangle.c b/examples/text/text_rectangle_bounds.c
index e60fa5e5..d4cd240a 100644
--- a/examples/text/text_draw_inside_rectangle.c
+++ b/examples/text/text_rectangle_bounds.c
@@ -5,7 +5,9 @@
* This example has been created using raylib 2.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2018 Vlad Adrian (@demizdor)
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@@ -37,9 +39,7 @@ int main()
const int maxHeight = screenHeight - 160;
Vector2 lastMouse = { 0, 0 }; // Stores last mouse coordinates
-
Color borderColor = MAROON; // Container border color
-
Font font = GetFontDefault(); // Get default system font
SetTargetFPS(60);
diff --git a/examples/text/text_draw_inside_rectangle.png b/examples/text/text_rectangle_bounds.png
index f46b1096..f46b1096 100644
--- a/examples/text/text_draw_inside_rectangle.png
+++ b/examples/text/text_rectangle_bounds.png
Binary files differ
diff --git a/examples/text/text_unicode.c b/examples/text/text_unicode.c
index b6c6db30..6b456a75 100644
--- a/examples/text/text_unicode.c
+++ b/examples/text/text_unicode.c
@@ -5,6 +5,8 @@
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
* Copyright (c) 2019 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
diff --git a/examples/textures/textures_image_npatch.png b/examples/textures/textures_image_npatch.png
deleted file mode 100644
index 5258811b..00000000
--- a/examples/textures/textures_image_npatch.png
+++ /dev/null
Binary files differ
diff --git a/examples/textures/textures_image_npatch.c b/examples/textures/textures_npatch_drawing.c
index 357b8a98..0514efe7 100644
--- a/examples/textures/textures_image_npatch.c
+++ b/examples/textures/textures_npatch_drawing.c
@@ -7,7 +7,9 @@
* This example has been created using raylib 2.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2016 Ramon Santamaria (@raysan5)
+* Example contributed by Jorge A. Gomes (@overdev) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Jorge A. Gomes (@overdev) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
@@ -24,22 +26,25 @@ int main()
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Texture2D nPatchTexture = LoadTexture("resources/ninepatch_button.png");
- Vector2 mousePosition;
- Vector2 origin = {0.0f, 0.0f};
+
+ Vector2 mousePosition = { 0 };
+ Vector2 origin = { 0.0f, 0.0f };
- // The location and size of the n-patches.
- Rectangle dstRec1 = {480.0f, 160.0f, 32.0f, 32.0f};
- Rectangle dstRec2 = {160.0f, 160.0f, 32.0f, 32.0f};
- Rectangle dstRecH = {160.0f, 93.0f, 32.0f, 32.0f}; // this rec's height is ignored
- Rectangle dstRecV = {92.0f, 160.0f, 32.0f, 32.0f}; // this rec's width is ignored
+ // Position and size of the n-patches
+ Rectangle dstRec1 = { 480.0f, 160.0f, 32.0f, 32.0f };
+ Rectangle dstRec2 = { 160.0f, 160.0f, 32.0f, 32.0f };
+ Rectangle dstRecH = { 160.0f, 93.0f, 32.0f, 32.0f };
+ Rectangle dstRecV = { 92.0f, 160.0f, 32.0f, 32.0f };
// A 9-patch (NPT_9PATCH) changes its sizes in both axis
- NPatchInfo ninePatchInfo1 = {(Rectangle){0.0f, 0.0f, 64.0f, 64.0f}, 12, 40, 12, 12, NPT_9PATCH };
- NPatchInfo ninePatchInfo2 = {(Rectangle){0.0f, 128.0f, 64.0f, 64.0f}, 16, 16, 16, 16, NPT_9PATCH };
+ NPatchInfo ninePatchInfo1 = { (Rectangle){ 0.0f, 0.0f, 64.0f, 64.0f }, 12, 40, 12, 12, NPT_9PATCH };
+ NPatchInfo ninePatchInfo2 = { (Rectangle){ 0.0f, 128.0f, 64.0f, 64.0f }, 16, 16, 16, 16, NPT_9PATCH };
+
// A horizontal 3-patch (NPT_3PATCH_HORIZONTAL) changes its sizes along the x axis only
- NPatchInfo h3PatchInfo = {(Rectangle){0.0f, 64.0f, 64.0f, 64.0f}, 8, 8, 8, 8, NPT_3PATCH_HORIZONTAL };
+ NPatchInfo h3PatchInfo = { (Rectangle){ 0.0f, 64.0f, 64.0f, 64.0f }, 8, 8, 8, 8, NPT_3PATCH_HORIZONTAL };
+
// A vertical 3-patch (NPT_3PATCH_VERTICAL) changes its sizes along the y axis only
- NPatchInfo v3PatchInfo = {(Rectangle){0.0f, 192.0f, 64.0f, 64.0f}, 6, 6, 6, 6, NPT_3PATCH_VERTICAL };
+ NPatchInfo v3PatchInfo = { (Rectangle){ 0.0f, 192.0f, 64.0f, 64.0f }, 6, 6, 6, 6, NPT_3PATCH_VERTICAL };
SetTargetFPS(60);
//---------------------------------------------------------------------------------------
@@ -50,7 +55,8 @@ int main()
// Update
//----------------------------------------------------------------------------------
mousePosition = GetMousePosition();
- // resize the n-patches based on mouse position.
+
+ // Resize the n-patches based on mouse position
dstRec1.width = mousePosition.x - dstRec1.x;
dstRec1.height = mousePosition.y - dstRec1.y;
dstRec2.width = mousePosition.x - dstRec2.x;
@@ -58,7 +64,7 @@ int main()
dstRecH.width = mousePosition.x - dstRecH.x;
dstRecV.height = mousePosition.y - dstRecV.y;
- // set a minimum width and/or height
+ // Set a minimum width and/or height
if (dstRec1.width < 1.0f) dstRec1.width = 1.0f;
if (dstRec1.width > 300.0f) dstRec1.width = 300.0f;
if (dstRec1.height < 1.0f) dstRec1.height = 1.0f;
@@ -82,16 +88,11 @@ int main()
DrawTextureNPatch(nPatchTexture, v3PatchInfo, dstRecV, origin, 0.0f, WHITE);
// Draw the source texture
- DrawRectangleLines( 5, 88, 74, 266, BLUE);
+ DrawRectangleLines(5, 88, 74, 266, BLUE);
DrawTexture(nPatchTexture, 10, 93, WHITE);
DrawText("TEXTURE", 15, 360, 10, DARKGRAY);
- DrawRectangle( 10, 10, 250, 73, Fade(SKYBLUE, 0.5));
- DrawRectangleLines( 10, 10, 250, 73, BLUE);
-
- DrawText("9-Patch and 3-Patch example", 20, 20, 10, BLACK);
- DrawText(" Move the mouse to stretch or", 40, 40, 10, DARKGRAY);
- DrawText(" shrink the n-patches.", 40, 60, 10, DARKGRAY);
+ DrawText("Move the mouse to stretch or shrink the n-patches", 10, 20, 20, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
diff --git a/examples/textures/textures_npatch_drawing.png b/examples/textures/textures_npatch_drawing.png
new file mode 100644
index 00000000..21df9caa
--- /dev/null
+++ b/examples/textures/textures_npatch_drawing.png
Binary files differ