From 6fc97643bf564ec2f616ba3114230c78ed1c265e Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 11 Apr 2019 16:53:02 +0200 Subject: new example: textures_background_scrolling --- .../resources/cyberpunk_street_background.png | Bin 0 -> 7800 bytes .../resources/cyberpunk_street_foreground.png | Bin 0 -> 18100 bytes .../resources/cyberpunk_street_midground.png | Bin 0 -> 7867 bytes examples/textures/textures_background_scrolling.c | 87 +++++++++++++++++++++ .../textures/textures_background_scrolling.png | Bin 0 -> 42935 bytes 5 files changed, 87 insertions(+) create mode 100644 examples/textures/resources/cyberpunk_street_background.png create mode 100644 examples/textures/resources/cyberpunk_street_foreground.png create mode 100644 examples/textures/resources/cyberpunk_street_midground.png create mode 100644 examples/textures/textures_background_scrolling.c create mode 100644 examples/textures/textures_background_scrolling.png (limited to 'examples/textures') diff --git a/examples/textures/resources/cyberpunk_street_background.png b/examples/textures/resources/cyberpunk_street_background.png new file mode 100644 index 00000000..624a4b14 Binary files /dev/null and b/examples/textures/resources/cyberpunk_street_background.png differ diff --git a/examples/textures/resources/cyberpunk_street_foreground.png b/examples/textures/resources/cyberpunk_street_foreground.png new file mode 100644 index 00000000..fb622db6 Binary files /dev/null and b/examples/textures/resources/cyberpunk_street_foreground.png differ diff --git a/examples/textures/resources/cyberpunk_street_midground.png b/examples/textures/resources/cyberpunk_street_midground.png new file mode 100644 index 00000000..643a85e7 Binary files /dev/null and b/examples/textures/resources/cyberpunk_street_midground.png differ diff --git a/examples/textures/textures_background_scrolling.c b/examples/textures/textures_background_scrolling.c new file mode 100644 index 00000000..2be0810a --- /dev/null +++ b/examples/textures/textures_background_scrolling.c @@ -0,0 +1,87 @@ +/******************************************************************************************* +* +* raylib [textures] example - Background scrolling +* +* 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) 2019 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - background scrolling"); + + // NOTE: Be careful, background width must be equal or bigger than screen width + // if not, texture should be draw more than two times for scrolling effect + Texture2D background = LoadTexture("resources/cyberpunk_street_background.png"); + Texture2D midground = LoadTexture("resources/cyberpunk_street_midground.png"); + Texture2D foreground = LoadTexture("resources/cyberpunk_street_foreground.png"); + + float scrollingBack = 0; + float scrollingMid = 0; + float scrollingFore = 0; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + scrollingBack -= 0.1f; + scrollingMid -= 0.5f; + scrollingFore -= 1.0f; + + // NOTE: Texture is scaled twice its size, so it sould be considered on scrolling + if (scrollingBack <= -background.width*2) scrollingBack = 0; + if (scrollingMid <= -midground.width*2) scrollingMid = 0; + if (scrollingFore <= -foreground.width*2) scrollingFore = 0; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(GetColor(0x052c46ff)); + + // Draw background image twice + // NOTE: Texture is scaled twice its size + DrawTextureEx(background, (Vector2){ scrollingBack, 20 }, 0.0f, 2.0f, WHITE); + DrawTextureEx(background, (Vector2){ background.width*2 + scrollingBack, 20 }, 0.0f, 2.0f, WHITE); + + // Draw midground image twice + DrawTextureEx(midground, (Vector2){ scrollingMid, 20 }, 0.0f, 2.0f, WHITE); + DrawTextureEx(midground, (Vector2){ midground.width*2 + scrollingMid, 20 }, 0.0f, 2.0f, WHITE); + + // Draw foreground image twice + DrawTextureEx(foreground, (Vector2){ scrollingFore, 70 }, 0.0f, 2.0f, WHITE); + DrawTextureEx(foreground, (Vector2){ foreground.width*2 + scrollingFore, 70 }, 0.0f, 2.0f, WHITE); + + DrawText("BACKGROUND SCROLLING & PARALLAX", 10, 10, 20, RED); + DrawText("(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)", screenWidth - 330, screenHeight - 20, 10, RAYWHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(background); // Unload background texture + UnloadTexture(midground); // Unload midground texture + UnloadTexture(foreground); // Unload foreground texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/textures/textures_background_scrolling.png b/examples/textures/textures_background_scrolling.png new file mode 100644 index 00000000..d21e269d Binary files /dev/null and b/examples/textures/textures_background_scrolling.png differ -- cgit v1.2.3 From 99537efccf077c0425c1de1188df632bfe96d125 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 12 Apr 2019 13:29:53 +0200 Subject: Review some examples --- examples/textures/textures_srcrec_dstrec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'examples/textures') diff --git a/examples/textures/textures_srcrec_dstrec.c b/examples/textures/textures_srcrec_dstrec.c index cc08eb58..298a0c65 100644 --- a/examples/textures/textures_srcrec_dstrec.c +++ b/examples/textures/textures_srcrec_dstrec.c @@ -27,13 +27,13 @@ int main() int frameHeight = scarfy.height; // NOTE: Source rectangle (part of the texture to use for drawing) - Rectangle sourceRec = { 0.0f, 0.0f, (float)frameWidth, (float)frameHeight }; + Rectangle sourceRec = { 0.0f, 0.0f, frameWidth, frameHeight }; // NOTE: Destination rectangle (screen rectangle where drawing part of texture) - Rectangle destRec = { (float)screenWidth/2, (float)screenHeight/2, (float)frameWidth*2, (float)frameHeight*2 }; + Rectangle destRec = { screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2 }; // NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size - Vector2 origin = { (float)frameWidth, (float)frameHeight }; + Vector2 origin = { frameWidth, frameHeight }; int rotation = 0; @@ -61,7 +61,7 @@ int main() // rotation defines the texture rotation (using origin as rotation point) DrawTexturePro(scarfy, sourceRec, destRec, origin, (float)rotation, WHITE); - DrawLine((int) destRec.x, 0, (int) destRec.x, screenHeight, GRAY); + DrawLine((int)destRec.x, 0, (int)destRec.x, screenHeight, GRAY); DrawLine(0, (int)destRec.y, screenWidth, (int)destRec.y, GRAY); DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); -- cgit v1.2.3 From a9ebf8e10d9d7903b140918c726a58f7317b3d19 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 2 May 2019 13:01:36 +0200 Subject: new example: textures_sprite_button --- examples/textures/resources/button.png | Bin 0 -> 48365 bytes examples/textures/resources/buttonfx.wav | Bin 0 -> 57364 bytes examples/textures/textures_sprite_button.c | 97 +++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 examples/textures/resources/button.png create mode 100644 examples/textures/resources/buttonfx.wav create mode 100644 examples/textures/textures_sprite_button.c (limited to 'examples/textures') diff --git a/examples/textures/resources/button.png b/examples/textures/resources/button.png new file mode 100644 index 00000000..54609e23 Binary files /dev/null and b/examples/textures/resources/button.png differ diff --git a/examples/textures/resources/buttonfx.wav b/examples/textures/resources/buttonfx.wav new file mode 100644 index 00000000..7d161ad7 Binary files /dev/null and b/examples/textures/resources/buttonfx.wav differ diff --git a/examples/textures/textures_sprite_button.c b/examples/textures/textures_sprite_button.c new file mode 100644 index 00000000..bbd57328 --- /dev/null +++ b/examples/textures/textures_sprite_button.c @@ -0,0 +1,97 @@ +/******************************************************************************************* +* +* raylib [textures] example - sprite button +* +* 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 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define NUM_FRAMES 3 // Number of frames (rectangles) for the button sprite texture + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite button"); + + InitAudioDevice(); // Initialize audio device + + Sound fxButton = LoadSound("resources/buttonfx.wav"); // Load button sound + Texture2D button = LoadTexture("resources/button.png"); // Load button texture + + // Define frame rectangle for drawing + int frameHeight = button.height/NUM_FRAMES; + Rectangle sourceRec = { 0, 0, button.width, frameHeight }; + + // Define button bounds on screen + Rectangle btnBounds = { screenWidth/2 - button.width/2, screenHeight/2 - button.height/NUM_FRAMES/2, button.width, frameHeight }; + + int btnState = 0; // Button state: 0-NORMAL, 1-MOUSE_HOVER, 2-PRESSED + bool btnAction = false; // Button action should be activated + + Vector2 mousePoint = { 0.0f, 0.0f }; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + mousePoint = GetMousePosition(); + btnAction = false; + + // Check button state + if (CheckCollisionPointRec(mousePoint, btnBounds)) + { + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) btnState = 2; + else btnState = 1; + + if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) btnAction = true; + } + else btnState = 0; + + if (btnAction) + { + PlaySound(fxButton); + + // TODO: Any desired action + } + + // Calculate button frame rectangle to draw depending on button state + sourceRec.y = btnState*frameHeight; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTextureRec(button, sourceRec, (Vector2){ btnBounds.x, btnBounds.y }, WHITE); // Draw button frame + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(button); // Unload button texture + UnloadSound(fxButton); // Unload sound + + CloseAudioDevice(); // Close audio device + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file -- cgit v1.2.3 From 0c53360a3abd923a7421ffc435fbb0ef76a08db1 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 3 May 2019 15:56:07 +0200 Subject: new example: textures_sprite_explosion --- examples/textures/resources/boom.wav | Bin 0 -> 13663 bytes examples/textures/resources/explosion.png | Bin 0 -> 1095038 bytes examples/textures/textures_sprite_explosion.c | 120 ++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 examples/textures/resources/boom.wav create mode 100644 examples/textures/resources/explosion.png create mode 100644 examples/textures/textures_sprite_explosion.c (limited to 'examples/textures') diff --git a/examples/textures/resources/boom.wav b/examples/textures/resources/boom.wav new file mode 100644 index 00000000..fd18137d Binary files /dev/null and b/examples/textures/resources/boom.wav differ diff --git a/examples/textures/resources/explosion.png b/examples/textures/resources/explosion.png new file mode 100644 index 00000000..46f98504 Binary files /dev/null and b/examples/textures/resources/explosion.png differ diff --git a/examples/textures/textures_sprite_explosion.c b/examples/textures/textures_sprite_explosion.c new file mode 100644 index 00000000..aa10a76c --- /dev/null +++ b/examples/textures/textures_sprite_explosion.c @@ -0,0 +1,120 @@ +/******************************************************************************************* +* +* raylib [textures] example - sprite explosion +* +* 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) +* +********************************************************************************************/ + +#include "raylib.h" + +#define NUM_FRAMES 8 +#define NUM_LINES 6 + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite explosion"); + + InitAudioDevice(); + + // Load explosion sound + Sound fxBoom = LoadSound("resources/boom.wav"); + + // Load explosion texture + Texture2D explosion = LoadTexture("resources/explosion2.png"); + + // Init variables for animation + int frameWidth = explosion.width/NUM_FRAMES; // Sprite one frame rectangle width + int frameHeight = explosion.height/NUM_LINES; // Sprite one frame rectangle height + int currentFrame = 0; + int currentLine = 0; + + Rectangle frameRec = { 0, 0, frameWidth, frameHeight }; + Vector2 position = { 0, 0 }; + + bool active = false; + int framesCounter = 0; + + SetTargetFPS(120); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + + // Check for mouse button pressed and activate explosion (if not active) + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !active) + { + position = GetMousePosition(); + active = true; + + position.x -= frameWidth/2; + position.y -= frameHeight/2; + + PlaySound(fxBoom); + } + + // Compute explosion animation frames + if (active) + { + framesCounter++; + + if (framesCounter > 2) + { + currentFrame++; + + if (currentFrame >= NUM_FRAMES) + { + currentFrame = 0; + currentLine++; + + if (currentLine >= NUM_LINES) + { + currentLine = 0; + active = false; + } + } + + framesCounter = 0; + } + } + + frameRec.x = frameWidth*currentFrame; + frameRec.y = frameHeight*currentLine; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // Draw explosion required frame rectangle + if (active) DrawTextureRec(explosion, frameRec, position, WHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(explosion); // Unload texture + UnloadSound(fxBoom); // Unload sound + + CloseAudioDevice(); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file -- cgit v1.2.3 From 621965cb8cbb743820dd66bdde61fc3c79b156a8 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 6 May 2019 16:38:58 +0200 Subject: Move bunnymark example to another module --- examples/textures/resources/wabbit_alpha.png | Bin 0 -> 561 bytes examples/textures/textures_bunnymark.c | 116 +++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 examples/textures/resources/wabbit_alpha.png create mode 100644 examples/textures/textures_bunnymark.c (limited to 'examples/textures') diff --git a/examples/textures/resources/wabbit_alpha.png b/examples/textures/resources/wabbit_alpha.png new file mode 100644 index 00000000..1a5eb0b4 Binary files /dev/null and b/examples/textures/resources/wabbit_alpha.png differ diff --git a/examples/textures/textures_bunnymark.c b/examples/textures/textures_bunnymark.c new file mode 100644 index 00000000..76078838 --- /dev/null +++ b/examples/textures/textures_bunnymark.c @@ -0,0 +1,116 @@ +/******************************************************************************************* +* +* raylib [textures] example - Bunnymark +* +* This example has been created using raylib 1.6 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include // Required for: malloc(), free() + +#define MAX_BUNNIES 100000 // 100K bunnies limit + +// This is the maximum amount of elements (quads) per batch +// NOTE: This value is defined in [rlgl] module and can be changed there +#define MAX_BATCH_ELEMENTS 8192 + +typedef struct Bunny { + Vector2 position; + Vector2 speed; + Color color; +} Bunny; + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - bunnymark"); + + Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png"); + + Bunny *bunnies = (Bunny *)malloc(MAX_BUNNIES*sizeof(Bunny)); // Bunnies array + + int bunniesCount = 0; // Bunnies counter + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + { + // Create more bunnies + for (int i = 0; i < 100; i++) + { + bunnies[bunniesCount].position = GetMousePosition(); + bunnies[bunniesCount].speed.x = (float)GetRandomValue(-250, 250)/60.0f; + bunnies[bunniesCount].speed.y = (float)GetRandomValue(-250, 250)/60.0f; + bunnies[bunniesCount].color = (Color){ GetRandomValue(50, 240), + GetRandomValue(80, 240), + GetRandomValue(100, 240), 255 }; + bunniesCount++; + } + } + + // Update bunnies + for (int i = 0; i < bunniesCount; i++) + { + bunnies[i].position.x += bunnies[i].speed.x; + bunnies[i].position.y += bunnies[i].speed.y; + + if (((bunnies[i].position.x + texBunny.width/2) > GetScreenWidth()) || + ((bunnies[i].position.x + texBunny.width/2) < 0)) bunnies[i].speed.x *= -1; + if (((bunnies[i].position.y + texBunny.height/2) > GetScreenHeight()) || + ((bunnies[i].position.y + texBunny.height/2 - 40) < 0)) bunnies[i].speed.y *= -1; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + for (int i = 0; i < bunniesCount; i++) + { + // NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS), + // a draw call is launched and buffer starts being filled again; + // before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU... + // Process of sending data is costly and it could happen that GPU data has not been completely + // processed for drawing while new data is tried to be sent (updating current in-use buffers) + // it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies + DrawTexture(texBunny, bunnies[i].position.x, bunnies[i].position.y, bunnies[i].color); + } + + DrawRectangle(0, 0, screenWidth, 40, BLACK); + DrawText(FormatText("bunnies: %i", bunniesCount), 120, 10, 20, GREEN); + DrawText(FormatText("batched draw calls: %i", 1 + bunniesCount/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON); + + DrawFPS(10, 10); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + free(bunnies); // Unload bunnies data array + + UnloadTexture(texBunny); // Unload bunny texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} -- cgit v1.2.3 From 424d3ca8d9c5d612606444b2a2099cfad37f1888 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 14 May 2019 15:34:23 +0200 Subject: examples review Redesigns, deletes and renames Also noted authors propertly on contributed examples --- examples/textures/textures_image_npatch.c | 108 ------------------------- examples/textures/textures_image_npatch.png | Bin 18306 -> 0 bytes examples/textures/textures_npatch_drawing.c | 109 ++++++++++++++++++++++++++ examples/textures/textures_npatch_drawing.png | Bin 0 -> 26858 bytes 4 files changed, 109 insertions(+), 108 deletions(-) delete mode 100644 examples/textures/textures_image_npatch.c delete mode 100644 examples/textures/textures_image_npatch.png create mode 100644 examples/textures/textures_npatch_drawing.c create mode 100644 examples/textures/textures_npatch_drawing.png (limited to 'examples/textures') diff --git a/examples/textures/textures_image_npatch.c b/examples/textures/textures_image_npatch.c deleted file mode 100644 index 357b8a98..00000000 --- a/examples/textures/textures_image_npatch.c +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - N-patch drawing -* -* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) -* -* 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) -* -********************************************************************************************/ - -#include "raylib.h" - -int main() -{ - // Initialization - //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [textures] example - N-patch drawing"); - - // 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}; - - // 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 - - // 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 }; - // 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 }; - // 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 }; - - SetTargetFPS(60); - //--------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - mousePosition = GetMousePosition(); - // 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; - dstRec2.height = mousePosition.y - dstRec2.y; - dstRecH.width = mousePosition.x - dstRecH.x; - dstRecV.height = mousePosition.y - dstRecV.y; - - // 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; - if (dstRec2.width < 1.0f) dstRec2.width = 1.0f; - if (dstRec2.width > 300.0f) dstRec2.width = 300.0f; - if (dstRec2.height < 1.0f) dstRec2.height = 1.0f; - if (dstRecH.width < 1.0f) dstRecH.width = 1.0f; - if (dstRecV.height < 1.0f) dstRecV.height = 1.0f; - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - // Draw the n-patches - DrawTextureNPatch(nPatchTexture, ninePatchInfo2, dstRec2, origin, 0.0f, WHITE); - DrawTextureNPatch(nPatchTexture, ninePatchInfo1, dstRec1, origin, 0.0f, WHITE); - DrawTextureNPatch(nPatchTexture, h3PatchInfo, dstRecH, origin, 0.0f, WHITE); - DrawTextureNPatch(nPatchTexture, v3PatchInfo, dstRecV, origin, 0.0f, WHITE); - - // Draw the source texture - 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); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(nPatchTexture); // Texture unloading - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/textures/textures_image_npatch.png b/examples/textures/textures_image_npatch.png deleted file mode 100644 index 5258811b..00000000 Binary files a/examples/textures/textures_image_npatch.png and /dev/null differ diff --git a/examples/textures/textures_npatch_drawing.c b/examples/textures/textures_npatch_drawing.c new file mode 100644 index 00000000..0514efe7 --- /dev/null +++ b/examples/textures/textures_npatch_drawing.c @@ -0,0 +1,109 @@ +/******************************************************************************************* +* +* raylib [textures] example - N-patch drawing +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* 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 Jorge A. Gomes (@overdev) and reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2018 Jorge A. Gomes (@overdev) and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - N-patch drawing"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Texture2D nPatchTexture = LoadTexture("resources/ninepatch_button.png"); + + Vector2 mousePosition = { 0 }; + Vector2 origin = { 0.0f, 0.0f }; + + // 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 }; + + // 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 }; + + // 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 }; + + SetTargetFPS(60); + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + mousePosition = GetMousePosition(); + + // 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; + dstRec2.height = mousePosition.y - dstRec2.y; + dstRecH.width = mousePosition.x - dstRecH.x; + dstRecV.height = mousePosition.y - dstRecV.y; + + // 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; + if (dstRec2.width < 1.0f) dstRec2.width = 1.0f; + if (dstRec2.width > 300.0f) dstRec2.width = 300.0f; + if (dstRec2.height < 1.0f) dstRec2.height = 1.0f; + if (dstRecH.width < 1.0f) dstRecH.width = 1.0f; + if (dstRecV.height < 1.0f) dstRecV.height = 1.0f; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // Draw the n-patches + DrawTextureNPatch(nPatchTexture, ninePatchInfo2, dstRec2, origin, 0.0f, WHITE); + DrawTextureNPatch(nPatchTexture, ninePatchInfo1, dstRec1, origin, 0.0f, WHITE); + DrawTextureNPatch(nPatchTexture, h3PatchInfo, dstRecH, origin, 0.0f, WHITE); + DrawTextureNPatch(nPatchTexture, v3PatchInfo, dstRecV, origin, 0.0f, WHITE); + + // Draw the source texture + DrawRectangleLines(5, 88, 74, 266, BLUE); + DrawTexture(nPatchTexture, 10, 93, WHITE); + DrawText("TEXTURE", 15, 360, 10, DARKGRAY); + + DrawText("Move the mouse to stretch or shrink the n-patches", 10, 20, 20, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(nPatchTexture); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/textures/textures_npatch_drawing.png b/examples/textures/textures_npatch_drawing.png new file mode 100644 index 00000000..21df9caa Binary files /dev/null and b/examples/textures/textures_npatch_drawing.png differ -- cgit v1.2.3 From 970f1e8ff15424ca2d96d89bf2871f0246835e9b Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 17 May 2019 01:17:40 +0200 Subject: examples review --- examples/textures/textures_bunnymark.png | Bin 0 -> 436989 bytes examples/textures/textures_sprite_button.png | Bin 0 -> 30194 bytes examples/textures/textures_sprite_explosion.c | 2 +- examples/textures/textures_sprite_explosion.png | Bin 0 -> 48293 bytes 4 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 examples/textures/textures_bunnymark.png create mode 100644 examples/textures/textures_sprite_button.png create mode 100644 examples/textures/textures_sprite_explosion.png (limited to 'examples/textures') diff --git a/examples/textures/textures_bunnymark.png b/examples/textures/textures_bunnymark.png new file mode 100644 index 00000000..4431ccec Binary files /dev/null and b/examples/textures/textures_bunnymark.png differ diff --git a/examples/textures/textures_sprite_button.png b/examples/textures/textures_sprite_button.png new file mode 100644 index 00000000..dac519d4 Binary files /dev/null and b/examples/textures/textures_sprite_button.png differ diff --git a/examples/textures/textures_sprite_explosion.c b/examples/textures/textures_sprite_explosion.c index aa10a76c..47c994b0 100644 --- a/examples/textures/textures_sprite_explosion.c +++ b/examples/textures/textures_sprite_explosion.c @@ -29,7 +29,7 @@ int main() Sound fxBoom = LoadSound("resources/boom.wav"); // Load explosion texture - Texture2D explosion = LoadTexture("resources/explosion2.png"); + Texture2D explosion = LoadTexture("resources/explosion.png"); // Init variables for animation int frameWidth = explosion.width/NUM_FRAMES; // Sprite one frame rectangle width diff --git a/examples/textures/textures_sprite_explosion.png b/examples/textures/textures_sprite_explosion.png new file mode 100644 index 00000000..8a439c35 Binary files /dev/null and b/examples/textures/textures_sprite_explosion.png differ -- cgit v1.2.3 From b525039e0ab8bcaa2fd6bde34c72a6405f88ae49 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 20 May 2019 16:36:42 +0200 Subject: Review ALL examples --- examples/textures/textures_background_scrolling.c | 22 ++++----- examples/textures/textures_bunnymark.c | 25 +++++----- examples/textures/textures_image_drawing.c | 20 ++++---- examples/textures/textures_image_generation.c | 28 ++++++------ examples/textures/textures_image_loading.c | 6 +-- examples/textures/textures_image_processing.c | 46 +++++++++---------- examples/textures/textures_image_text.c | 28 ++++++------ examples/textures/textures_logo_raylib.c | 6 +-- examples/textures/textures_npatch_drawing.c | 18 ++++---- examples/textures/textures_particles_blending.c | 40 ++++++++-------- examples/textures/textures_raw_data.c | 30 ++++++------ examples/textures/textures_rectangle.c | 28 ++++++------ examples/textures/textures_sprite_button.c | 36 +++++++-------- examples/textures/textures_sprite_explosion.c | 56 +++++++++++------------ examples/textures/textures_srcrec_dstrec.c | 21 +++++---- examples/textures/textures_to_image.c | 12 ++--- 16 files changed, 212 insertions(+), 210 deletions(-) (limited to 'examples/textures') diff --git a/examples/textures/textures_background_scrolling.c b/examples/textures/textures_background_scrolling.c index 2be0810a..d91b2585 100644 --- a/examples/textures/textures_background_scrolling.c +++ b/examples/textures/textures_background_scrolling.c @@ -11,26 +11,26 @@ #include "raylib.h" -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [textures] example - background scrolling"); - + // NOTE: Be careful, background width must be equal or bigger than screen width // if not, texture should be draw more than two times for scrolling effect Texture2D background = LoadTexture("resources/cyberpunk_street_background.png"); Texture2D midground = LoadTexture("resources/cyberpunk_street_midground.png"); Texture2D foreground = LoadTexture("resources/cyberpunk_street_foreground.png"); - + float scrollingBack = 0; float scrollingMid = 0; float scrollingFore = 0; - - SetTargetFPS(60); + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop @@ -41,7 +41,7 @@ int main() scrollingBack -= 0.1f; scrollingMid -= 0.5f; scrollingFore -= 1.0f; - + // NOTE: Texture is scaled twice its size, so it sould be considered on scrolling if (scrollingBack <= -background.width*2) scrollingBack = 0; if (scrollingMid <= -midground.width*2) scrollingMid = 0; @@ -58,15 +58,15 @@ int main() // NOTE: Texture is scaled twice its size DrawTextureEx(background, (Vector2){ scrollingBack, 20 }, 0.0f, 2.0f, WHITE); DrawTextureEx(background, (Vector2){ background.width*2 + scrollingBack, 20 }, 0.0f, 2.0f, WHITE); - + // Draw midground image twice DrawTextureEx(midground, (Vector2){ scrollingMid, 20 }, 0.0f, 2.0f, WHITE); DrawTextureEx(midground, (Vector2){ midground.width*2 + scrollingMid, 20 }, 0.0f, 2.0f, WHITE); - + // Draw foreground image twice DrawTextureEx(foreground, (Vector2){ scrollingFore, 70 }, 0.0f, 2.0f, WHITE); DrawTextureEx(foreground, (Vector2){ foreground.width*2 + scrollingFore, 70 }, 0.0f, 2.0f, WHITE); - + DrawText("BACKGROUND SCROLLING & PARALLAX", 10, 10, 20, RED); DrawText("(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)", screenWidth - 330, screenHeight - 20, 10, RAYWHITE); diff --git a/examples/textures/textures_bunnymark.c b/examples/textures/textures_bunnymark.c index 76078838..6b91d646 100644 --- a/examples/textures/textures_bunnymark.c +++ b/examples/textures/textures_bunnymark.c @@ -25,7 +25,7 @@ typedef struct Bunny { Color color; } Bunny; -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- @@ -34,13 +34,14 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [textures] example - bunnymark"); + // Load bunny texture Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png"); - Bunny *bunnies = (Bunny *)malloc(MAX_BUNNIES*sizeof(Bunny)); // Bunnies array + Bunny *bunnies = (Bunny *)malloc(MAX_BUNNIES*sizeof(Bunny)); // Bunnies array - int bunniesCount = 0; // Bunnies counter + int bunniesCount = 0; // Bunnies counter - SetTargetFPS(60); + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop @@ -56,8 +57,8 @@ int main() bunnies[bunniesCount].position = GetMousePosition(); bunnies[bunniesCount].speed.x = (float)GetRandomValue(-250, 250)/60.0f; bunnies[bunniesCount].speed.y = (float)GetRandomValue(-250, 250)/60.0f; - bunnies[bunniesCount].color = (Color){ GetRandomValue(50, 240), - GetRandomValue(80, 240), + bunnies[bunniesCount].color = (Color){ GetRandomValue(50, 240), + GetRandomValue(80, 240), GetRandomValue(100, 240), 255 }; bunniesCount++; } @@ -69,9 +70,9 @@ int main() bunnies[i].position.x += bunnies[i].speed.x; bunnies[i].position.y += bunnies[i].speed.y; - if (((bunnies[i].position.x + texBunny.width/2) > GetScreenWidth()) || + if (((bunnies[i].position.x + texBunny.width/2) > GetScreenWidth()) || ((bunnies[i].position.x + texBunny.width/2) < 0)) bunnies[i].speed.x *= -1; - if (((bunnies[i].position.y + texBunny.height/2) > GetScreenHeight()) || + if (((bunnies[i].position.y + texBunny.height/2) > GetScreenHeight()) || ((bunnies[i].position.y + texBunny.height/2 - 40) < 0)) bunnies[i].speed.y *= -1; } //---------------------------------------------------------------------------------- @@ -84,9 +85,9 @@ int main() for (int i = 0; i < bunniesCount; i++) { - // NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS), + // NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS), // a draw call is launched and buffer starts being filled again; - // before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU... + // before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU... // Process of sending data is costly and it could happen that GPU data has not been completely // processed for drawing while new data is tried to be sent (updating current in-use buffers) // it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies @@ -96,7 +97,7 @@ int main() DrawRectangle(0, 0, screenWidth, 40, BLACK); DrawText(FormatText("bunnies: %i", bunniesCount), 120, 10, 20, GREEN); DrawText(FormatText("batched draw calls: %i", 1 + bunniesCount/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON); - + DrawFPS(10, 10); EndDrawing(); @@ -106,7 +107,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- free(bunnies); // Unload bunnies data array - + UnloadTexture(texBunny); // Unload bunny texture CloseWindow(); // Close window and OpenGL context diff --git a/examples/textures/textures_image_drawing.c b/examples/textures/textures_image_drawing.c index b179612d..f5c3c85d 100644 --- a/examples/textures/textures_image_drawing.c +++ b/examples/textures/textures_image_drawing.c @@ -13,12 +13,12 @@ #include "raylib.h" -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [textures] example - image drawing"); @@ -28,26 +28,26 @@ int main() ImageCrop(&cat, (Rectangle){ 100, 10, 280, 380 }); // Crop an image piece ImageFlipHorizontal(&cat); // Flip cropped image horizontally ImageResize(&cat, 150, 200); // Resize flipped-cropped image - + Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) - + // Draw one image over the other with a scaling of 1.5f ImageDraw(&parrots, cat, (Rectangle){ 0, 0, cat.width, cat.height }, (Rectangle){ 30, 40, cat.width*1.5f, cat.height*1.5f }); ImageCrop(&parrots, (Rectangle){ 0, 50, parrots.width, parrots.height - 100 }); // Crop resulting image - + UnloadImage(cat); // Unload image from RAM - + // Load custom font for frawing on image Font font = LoadFont("resources/custom_jupiter_crash.png"); - + // Draw over image using custom font ImageDrawTextEx(&parrots, (Vector2){ 300, 230 }, font, "PARROTS & CAT", font.baseSize, -2, WHITE); - + UnloadFont(font); // Unload custom spritefont (already drawn used on image) Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM) UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM - + SetTargetFPS(60); //--------------------------------------------------------------------------------------- diff --git a/examples/textures/textures_image_generation.c b/examples/textures/textures_image_generation.c index b9608c89..d9a39a25 100644 --- a/examples/textures/textures_image_generation.c +++ b/examples/textures/textures_image_generation.c @@ -13,12 +13,12 @@ #define NUM_TEXTURES 7 // Currently we have 7 generation algorithms -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [textures] example - procedural images generation"); @@ -38,7 +38,7 @@ int main() textures[4] = LoadTextureFromImage(whiteNoise); textures[5] = LoadTextureFromImage(perlinNoise); textures[6] = LoadTextureFromImage(cellular); - + // Unload image data (CPU RAM) UnloadImage(verticalGradient); UnloadImage(horizontalGradient); @@ -49,10 +49,10 @@ int main() UnloadImage(cellular); int currentTexture = 0; - + SetTargetFPS(60); //--------------------------------------------------------------------------------------- - + // Main game loop while (!WindowShouldClose()) { @@ -67,15 +67,15 @@ int main() // Draw //---------------------------------------------------------------------------------- BeginDrawing(); - + ClearBackground(RAYWHITE); - + DrawTexture(textures[currentTexture], 0, 0, WHITE); - + DrawRectangle(30, 400, 325, 30, Fade(SKYBLUE, 0.5f)); DrawRectangleLines(30, 400, 325, 30, Fade(WHITE, 0.5f)); DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, WHITE); - + switch(currentTexture) { case 0: DrawText("VERTICAL GRADIENT", 560, 10, 20, RAYWHITE); break; @@ -87,19 +87,19 @@ int main() case 6: DrawText("CELLULAR", 670, 10, 20, RAYWHITE); break; default: break; } - + EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- - + // Unload textures data (GPU VRAM) for (int i = 0; i < NUM_TEXTURES; i++) UnloadTexture(textures[i]); - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- - + return 0; } diff --git a/examples/textures/textures_image_loading.c b/examples/textures/textures_image_loading.c index 54c73586..265cab44 100644 --- a/examples/textures/textures_image_loading.c +++ b/examples/textures/textures_image_loading.c @@ -13,12 +13,12 @@ #include "raylib.h" -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading"); diff --git a/examples/textures/textures_image_processing.c b/examples/textures/textures_image_processing.c index 6d33d95b..b9ed51d7 100644 --- a/examples/textures/textures_image_processing.c +++ b/examples/textures/textures_image_processing.c @@ -13,19 +13,19 @@ #include "raylib.h" -#include // Required for: free() +#include // Required for: free() #define NUM_PROCESSES 8 -typedef enum { - NONE = 0, - COLOR_GRAYSCALE, - COLOR_TINT, - COLOR_INVERT, - COLOR_CONTRAST, - COLOR_BRIGHTNESS, - FLIP_VERTICAL, - FLIP_HORIZONTAL +typedef enum { + NONE = 0, + COLOR_GRAYSCALE, + COLOR_TINT, + COLOR_INVERT, + COLOR_CONTRAST, + COLOR_BRIGHTNESS, + FLIP_VERTICAL, + FLIP_HORIZONTAL } ImageProcess; static const char *processText[] = { @@ -39,12 +39,12 @@ static const char *processText[] = { "FLIP HORIZONTAL" }; -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing"); @@ -58,9 +58,9 @@ int main() bool textureReload = false; Rectangle selectRecs[NUM_PROCESSES]; - + for (int i = 0; i < NUM_PROCESSES; i++) selectRecs[i] = (Rectangle){ 40.0f, (float)(50 + 32*i), 150.0f, 30.0f }; - + SetTargetFPS(60); //--------------------------------------------------------------------------------------- @@ -81,14 +81,14 @@ int main() if (currentProcess < 0) currentProcess = 7; textureReload = true; } - + if (textureReload) { UnloadImage(image); // Unload current image data image = LoadImage("resources/parrots.png"); // Re-load image data - // NOTE: Image processing is a costly CPU process to be done every frame, - // If image processing is required in a frame-basis, it should be done + // NOTE: Image processing is a costly CPU process to be done every frame, + // If image processing is required in a frame-basis, it should be done // with a texture and by shaders switch (currentProcess) { @@ -101,11 +101,11 @@ int main() case FLIP_HORIZONTAL: ImageFlipHorizontal(&image); break; default: break; } - + Color *pixels = GetImageData(image); // Get pixel data from image (RGBA 32bit) UpdateTexture(texture, pixels); // Update texture with new image data free(pixels); // Unload pixels data from RAM - + textureReload = false; } //---------------------------------------------------------------------------------- @@ -115,9 +115,9 @@ int main() BeginDrawing(); ClearBackground(RAYWHITE); - + DrawText("IMAGE PROCESSING:", 40, 30, 10, DARKGRAY); - + // Draw rectangles for (int i = 0; i < NUM_PROCESSES; i++) { @@ -128,7 +128,7 @@ int main() DrawTexture(texture, screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, WHITE); DrawRectangleLines(screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, texture.width, texture.height, BLACK); - + EndDrawing(); //---------------------------------------------------------------------------------- } diff --git a/examples/textures/textures_image_text.c b/examples/textures/textures_image_text.c index ce91fbf2..c8dfe458 100644 --- a/examples/textures/textures_image_text.c +++ b/examples/textures/textures_image_text.c @@ -11,28 +11,28 @@ #include "raylib.h" -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [texture] example - image text drawing"); + Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) + // TTF Font loading with custom generation parameters Font font = LoadFontEx("resources/KAISG.ttf", 64, 0, 0); - - Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) // Draw over image using custom font ImageDrawTextEx(&parrots, (Vector2){ 20.0f, 20.0f }, font, "[Parrots font drawing]", (float)font.baseSize, 0.0f, RED); Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM) UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM - + Vector2 position = { (float)(screenWidth/2 - texture.width/2), (float)(screenHeight/2 - texture.height/2 - 20) }; - + bool showFont = false; SetTargetFPS(60); @@ -57,15 +57,15 @@ int main() { // Draw texture with text already drawn inside DrawTextureV(texture, position, WHITE); - + // Draw text directly using sprite font - DrawTextEx(font, "[Parrots font drawing]", (Vector2){ position.x + 20, + DrawTextEx(font, "[Parrots font drawing]", (Vector2){ position.x + 20, position.y + 20 + 280 }, (float)font.baseSize, 0.0f, WHITE); } else DrawTexture(font.texture, screenWidth/2 - font.texture.width/2, 50, BLACK); - + DrawText("PRESS SPACE to SEE USED SPRITEFONT ", 290, 420, 10, DARKGRAY); - + EndDrawing(); //---------------------------------------------------------------------------------- } @@ -73,9 +73,9 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- UnloadTexture(texture); // Texture unloading - - UnloadFont(font); // Unload custom spritefont - + + UnloadFont(font); // Unload custom spritefont + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/textures/textures_logo_raylib.c b/examples/textures/textures_logo_raylib.c index f2f93128..de8bb2ae 100644 --- a/examples/textures/textures_logo_raylib.c +++ b/examples/textures/textures_logo_raylib.c @@ -11,12 +11,12 @@ #include "raylib.h" -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing"); diff --git a/examples/textures/textures_npatch_drawing.c b/examples/textures/textures_npatch_drawing.c index 0514efe7..1c57e2e7 100644 --- a/examples/textures/textures_npatch_drawing.c +++ b/examples/textures/textures_npatch_drawing.c @@ -15,18 +15,18 @@ #include "raylib.h" -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [textures] example - N-patch drawing"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) Texture2D nPatchTexture = LoadTexture("resources/ninepatch_button.png"); - + Vector2 mousePosition = { 0 }; Vector2 origin = { 0.0f, 0.0f }; @@ -39,13 +39,13 @@ int main() // 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 }; - + // 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 }; - + // 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 }; - + SetTargetFPS(60); //--------------------------------------------------------------------------------------- @@ -55,7 +55,7 @@ int main() // Update //---------------------------------------------------------------------------------- mousePosition = GetMousePosition(); - + // Resize the n-patches based on mouse position dstRec1.width = mousePosition.x - dstRec1.x; dstRec1.height = mousePosition.y - dstRec1.y; @@ -86,7 +86,7 @@ int main() DrawTextureNPatch(nPatchTexture, ninePatchInfo1, dstRec1, origin, 0.0f, WHITE); DrawTextureNPatch(nPatchTexture, h3PatchInfo, dstRecH, origin, 0.0f, WHITE); DrawTextureNPatch(nPatchTexture, v3PatchInfo, dstRecV, origin, 0.0f, WHITE); - + // Draw the source texture DrawRectangleLines(5, 88, 74, 266, BLUE); DrawTexture(nPatchTexture, 10, 93, WHITE); diff --git a/examples/textures/textures_particles_blending.c b/examples/textures/textures_particles_blending.c index 3b7dcaa3..75287ea7 100644 --- a/examples/textures/textures_particles_blending.c +++ b/examples/textures/textures_particles_blending.c @@ -23,18 +23,18 @@ typedef struct { bool active; // NOTE: Use it to activate/deactive particle } Particle; -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending"); - + // Particles pool, reuse them! - Particle mouseTail[MAX_PARTICLES]; - + Particle mouseTail[MAX_PARTICLES]; + // Initialize particles for (int i = 0; i < MAX_PARTICLES; i++) { @@ -45,13 +45,13 @@ int main() mouseTail[i].rotation = (float)GetRandomValue(0, 360); mouseTail[i].active = false; } - + float gravity = 3.0f; Texture2D smoke = LoadTexture("resources/smoke.png"); - + int blending = BLEND_ALPHA; - + SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -60,7 +60,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - + // Activate one particle every frame and Update active particles // NOTE: Particles initial position should be mouse position when activated // NOTE: Particles fall down with gravity and rotation... and disappear after 2 seconds (alpha = 0) @@ -82,13 +82,13 @@ int main() { mouseTail[i].position.y += gravity; mouseTail[i].alpha -= 0.01f; - + if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false; - + mouseTail[i].rotation += 5.0f; } } - + if (IsKeyPressed(KEY_SPACE)) { if (blending == BLEND_ALPHA) blending = BLEND_ADDITIVE; @@ -101,25 +101,25 @@ int main() BeginDrawing(); ClearBackground(DARKGRAY); - + BeginBlendMode(blending); // Draw active particles for (int i = 0; i < MAX_PARTICLES; i++) { - if (mouseTail[i].active) DrawTexturePro(smoke, (Rectangle){ 0.0f, 0.0f, (float)smoke.width, (float)smoke.height }, + if (mouseTail[i].active) DrawTexturePro(smoke, (Rectangle){ 0.0f, 0.0f, (float)smoke.width, (float)smoke.height }, (Rectangle){ mouseTail[i].position.x, mouseTail[i].position.y, smoke.width*mouseTail[i].size, smoke.height*mouseTail[i].size }, (Vector2){ (float)(smoke.width*mouseTail[i].size/2.0f), (float)(smoke.height*mouseTail[i].size/2.0f) }, mouseTail[i].rotation, Fade(mouseTail[i].color, mouseTail[i].alpha)); } - + EndBlendMode(); - + DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, BLACK); - + if (blending == BLEND_ALPHA) DrawText("ALPHA BLENDING", 290, screenHeight - 40, 20, BLACK); else DrawText("ADDITIVE BLENDING", 280, screenHeight - 40, 20, RAYWHITE); - + EndDrawing(); //---------------------------------------------------------------------------------- } @@ -127,7 +127,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- UnloadTexture(smoke); - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/textures/textures_raw_data.c b/examples/textures/textures_raw_data.c index 481bd66a..17604bde 100644 --- a/examples/textures/textures_raw_data.c +++ b/examples/textures/textures_raw_data.c @@ -13,31 +13,31 @@ #include "raylib.h" -#include // Required for malloc() and free() +#include // Required for: malloc() and free() -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - + // Load RAW image data (512x512, 32bit RGBA, no file header) Image fudesumiRaw = LoadImageRaw("resources/fudesumi.raw", 384, 512, UNCOMPRESSED_R8G8B8A8, 0); - Texture2D fudesumi = LoadTextureFromImage(fudesumiRaw); // Upload CPU (RAM) image to GPU (VRAM) - UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data - + Texture2D fudesumi = LoadTextureFromImage(fudesumiRaw); // Upload CPU (RAM) image to GPU (VRAM) + UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data + // Generate a checked texture by code (1024x1024 pixels) int width = 960; int height = 480; - + // Dynamic memory allocation to store pixels data (Color type) Color *pixels = (Color *)malloc(width*height*sizeof(Color)); - + for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) @@ -46,14 +46,14 @@ int main() else pixels[y*width + x] = GOLD; } } - + // Load pixels data into an image structure and create texture Image checkedIm = LoadImageEx(pixels, width, height); Texture2D checked = LoadTextureFromImage(checkedIm); - UnloadImage(checkedIm); // Unload CPU (RAM) image data - + UnloadImage(checkedIm); // Unload CPU (RAM) image data + // Dynamic memory must be freed after using it - free(pixels); // Unload CPU (RAM) pixels data + free(pixels); // Unload CPU (RAM) pixels data //--------------------------------------------------------------------------------------- // Main game loop @@ -76,7 +76,7 @@ int main() DrawText("CHECKED TEXTURE ", 84, 85, 30, BROWN); DrawText("GENERATED by CODE", 72, 148, 30, BROWN); DrawText("and RAW IMAGE LOADING", 46, 210, 30, BROWN); - + DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screenHeight - 20, 10, BROWN); EndDrawing(); diff --git a/examples/textures/textures_rectangle.c b/examples/textures/textures_rectangle.c index e1247746..8be647a2 100644 --- a/examples/textures/textures_rectangle.c +++ b/examples/textures/textures_rectangle.c @@ -14,12 +14,12 @@ #define MAX_FRAME_SPEED 15 #define MIN_FRAME_SPEED 1 -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle"); @@ -29,10 +29,10 @@ int main() Vector2 position = { 350.0f, 280.0f }; Rectangle frameRec = { 0.0f, 0.0f, (float)scarfy.width/6, (float)scarfy.height }; int currentFrame = 0; - + int framesCounter = 0; - int framesSpeed = 8; // Number of spritesheet frames shown by second - + int framesSpeed = 8; // Number of spritesheet frames shown by second + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -42,20 +42,20 @@ int main() // Update //---------------------------------------------------------------------------------- framesCounter++; - + if (framesCounter >= (60/framesSpeed)) { framesCounter = 0; currentFrame++; - + if (currentFrame > 5) currentFrame = 0; - + frameRec.x = (float)currentFrame*(float)scarfy.width/6; } - + if (IsKeyPressed(KEY_RIGHT)) framesSpeed++; else if (IsKeyPressed(KEY_LEFT)) framesSpeed--; - + if (framesSpeed > MAX_FRAME_SPEED) framesSpeed = MAX_FRAME_SPEED; else if (framesSpeed < MIN_FRAME_SPEED) framesSpeed = MIN_FRAME_SPEED; //---------------------------------------------------------------------------------- @@ -69,17 +69,17 @@ int main() DrawTexture(scarfy, 15, 40, WHITE); DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME); DrawRectangleLines(15 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED); - + DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY); DrawText(FormatText("%02i FPS", framesSpeed), 575, 210, 10, DARKGRAY); DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, DARKGRAY); - + for (int i = 0; i < MAX_FRAME_SPEED; i++) { if (i < framesSpeed) DrawRectangle(250 + 21*i, 205, 20, 20, RED); DrawRectangleLines(250 + 21*i, 205, 20, 20, MAROON); } - + DrawTextureRec(scarfy, frameRec, position, WHITE); // Draw part of the texture DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); diff --git a/examples/textures/textures_sprite_button.c b/examples/textures/textures_sprite_button.c index bbd57328..a5b2d8d1 100644 --- a/examples/textures/textures_sprite_button.c +++ b/examples/textures/textures_sprite_button.c @@ -13,35 +13,35 @@ #define NUM_FRAMES 3 // Number of frames (rectangles) for the button sprite texture -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; - + InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite button"); InitAudioDevice(); // Initialize audio device - + Sound fxButton = LoadSound("resources/buttonfx.wav"); // Load button sound Texture2D button = LoadTexture("resources/button.png"); // Load button texture - + // Define frame rectangle for drawing int frameHeight = button.height/NUM_FRAMES; Rectangle sourceRec = { 0, 0, button.width, frameHeight }; - + // Define button bounds on screen Rectangle btnBounds = { screenWidth/2 - button.width/2, screenHeight/2 - button.height/NUM_FRAMES/2, button.width, frameHeight }; - + int btnState = 0; // Button state: 0-NORMAL, 1-MOUSE_HOVER, 2-PRESSED bool btnAction = false; // Button action should be activated - + Vector2 mousePoint = { 0.0f, 0.0f }; - + SetTargetFPS(60); //-------------------------------------------------------------------------------------- - + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { @@ -49,7 +49,7 @@ int main() //---------------------------------------------------------------------------------- mousePoint = GetMousePosition(); btnAction = false; - + // Check button state if (CheckCollisionPointRec(mousePoint, btnBounds)) { @@ -59,26 +59,26 @@ int main() if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) btnAction = true; } else btnState = 0; - + if (btnAction) { PlaySound(fxButton); - + // TODO: Any desired action } - + // Calculate button frame rectangle to draw depending on button state sourceRec.y = btnState*frameHeight; //---------------------------------------------------------------------------------- - + // Draw //---------------------------------------------------------------------------------- BeginDrawing(); - + ClearBackground(RAYWHITE); DrawTextureRec(button, sourceRec, (Vector2){ btnBounds.x, btnBounds.y }, WHITE); // Draw button frame - + EndDrawing(); //---------------------------------------------------------------------------------- } @@ -89,9 +89,9 @@ int main() UnloadSound(fxButton); // Unload sound CloseAudioDevice(); // Close audio device - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- - + return 0; } \ No newline at end of file diff --git a/examples/textures/textures_sprite_explosion.c b/examples/textures/textures_sprite_explosion.c index 47c994b0..58a8f6fc 100644 --- a/examples/textures/textures_sprite_explosion.c +++ b/examples/textures/textures_sprite_explosion.c @@ -11,23 +11,23 @@ #include "raylib.h" -#define NUM_FRAMES 8 -#define NUM_LINES 6 +#define NUM_FRAMES 8 +#define NUM_LINES 6 -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; - + InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite explosion"); - + InitAudioDevice(); - + // Load explosion sound Sound fxBoom = LoadSound("resources/boom.wav"); - + // Load explosion texture Texture2D explosion = LoadTexture("resources/explosion.png"); @@ -36,72 +36,72 @@ int main() int frameHeight = explosion.height/NUM_LINES; // Sprite one frame rectangle height int currentFrame = 0; int currentLine = 0; - + Rectangle frameRec = { 0, 0, frameWidth, frameHeight }; Vector2 position = { 0, 0 }; - + bool active = false; int framesCounter = 0; - + SetTargetFPS(120); //-------------------------------------------------------------------------------------- - + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- - + // Check for mouse button pressed and activate explosion (if not active) if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !active) { position = GetMousePosition(); active = true; - + position.x -= frameWidth/2; position.y -= frameHeight/2; - + PlaySound(fxBoom); } - + // Compute explosion animation frames if (active) { framesCounter++; - + if (framesCounter > 2) { currentFrame++; - + if (currentFrame >= NUM_FRAMES) { currentFrame = 0; currentLine++; - + if (currentLine >= NUM_LINES) { currentLine = 0; active = false; } } - + framesCounter = 0; } } - + frameRec.x = frameWidth*currentFrame; frameRec.y = frameHeight*currentLine; //---------------------------------------------------------------------------------- - + // Draw //---------------------------------------------------------------------------------- BeginDrawing(); - + ClearBackground(RAYWHITE); - + // Draw explosion required frame rectangle if (active) DrawTextureRec(explosion, frameRec, position, WHITE); - + EndDrawing(); //---------------------------------------------------------------------------------- } @@ -109,12 +109,12 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- UnloadTexture(explosion); // Unload texture - UnloadSound(fxBoom); // Unload sound - + UnloadSound(fxBoom); // Unload sound + CloseAudioDevice(); - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- - + return 0; } \ No newline at end of file diff --git a/examples/textures/textures_srcrec_dstrec.c b/examples/textures/textures_srcrec_dstrec.c index 298a0c65..e86b729d 100644 --- a/examples/textures/textures_srcrec_dstrec.c +++ b/examples/textures/textures_srcrec_dstrec.c @@ -11,32 +11,33 @@ #include "raylib.h" -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading int frameWidth = scarfy.width/6; int frameHeight = scarfy.height; - - // NOTE: Source rectangle (part of the texture to use for drawing) + + // Source rectangle (part of the texture to use for drawing) Rectangle sourceRec = { 0.0f, 0.0f, frameWidth, frameHeight }; - // NOTE: Destination rectangle (screen rectangle where drawing part of texture) + // Destination rectangle (screen rectangle where drawing part of texture) Rectangle destRec = { screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2 }; - // NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size + // Origin of the texture (rotation/scale point), it's relative to destination rectangle size Vector2 origin = { frameWidth, frameHeight }; - + int rotation = 0; - + SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -63,7 +64,7 @@ int main() DrawLine((int)destRec.x, 0, (int)destRec.x, screenHeight, GRAY); DrawLine(0, (int)destRec.y, screenWidth, (int)destRec.y, GRAY); - + DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); EndDrawing(); diff --git a/examples/textures/textures_to_image.c b/examples/textures/textures_to_image.c index 37c3b5a0..c0989baf 100644 --- a/examples/textures/textures_to_image.c +++ b/examples/textures/textures_to_image.c @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raylib [textures] example - Retrieve image data from texture: GetTextureData() +* raylib [textures] example - Retrieve image data from texture: GetTextureData() * * NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) * @@ -13,12 +13,12 @@ #include "raylib.h" -int main() +int main(void) { // Initialization //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; + const int screenWidth = 800; + const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image"); @@ -27,10 +27,10 @@ int main() Image image = LoadImage("resources/raylib_logo.png"); // Load image data into CPU memory (RAM) Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (RAM -> VRAM) UnloadImage(image); // Unload image data from CPU memory (RAM) - + image = GetTextureData(texture); // Retrieve image data from GPU memory (VRAM -> RAM) UnloadTexture(texture); // Unload texture from GPU memory (VRAM) - + texture = LoadTextureFromImage(image); // Recreate texture from retrieved image data (RAM -> VRAM) UnloadImage(image); // Unload retrieved image data from CPU memory (RAM) //--------------------------------------------------------------------------------------- -- cgit v1.2.3 From 87774a0a21f8d2998b4dc13e989005270476ae92 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 27 May 2019 00:18:15 +0200 Subject: Review variables initialization --- examples/textures/textures_background_scrolling.c | 6 +++--- examples/textures/textures_image_generation.c | 3 ++- examples/textures/textures_image_processing.c | 2 +- examples/textures/textures_particles_blending.c | 2 +- examples/textures/textures_raw_data.c | 2 +- examples/textures/textures_sprite_explosion.c | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) (limited to 'examples/textures') diff --git a/examples/textures/textures_background_scrolling.c b/examples/textures/textures_background_scrolling.c index d91b2585..c2e5ac80 100644 --- a/examples/textures/textures_background_scrolling.c +++ b/examples/textures/textures_background_scrolling.c @@ -26,9 +26,9 @@ int main(void) Texture2D midground = LoadTexture("resources/cyberpunk_street_midground.png"); Texture2D foreground = LoadTexture("resources/cyberpunk_street_foreground.png"); - float scrollingBack = 0; - float scrollingMid = 0; - float scrollingFore = 0; + float scrollingBack = 0.0f; + float scrollingMid = 0.0f; + float scrollingFore = 0.0f; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- diff --git a/examples/textures/textures_image_generation.c b/examples/textures/textures_image_generation.c index d9a39a25..0bb10583 100644 --- a/examples/textures/textures_image_generation.c +++ b/examples/textures/textures_image_generation.c @@ -30,7 +30,8 @@ int main(void) Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0f); Image cellular = GenImageCellular(screenWidth, screenHeight, 32); - Texture2D textures[NUM_TEXTURES]; + Texture2D textures[NUM_TEXTURES] = { 0 }; + textures[0] = LoadTextureFromImage(verticalGradient); textures[1] = LoadTextureFromImage(horizontalGradient); textures[2] = LoadTextureFromImage(radialGradient); diff --git a/examples/textures/textures_image_processing.c b/examples/textures/textures_image_processing.c index b9ed51d7..14442290 100644 --- a/examples/textures/textures_image_processing.c +++ b/examples/textures/textures_image_processing.c @@ -57,7 +57,7 @@ int main(void) int currentProcess = NONE; bool textureReload = false; - Rectangle selectRecs[NUM_PROCESSES]; + Rectangle selectRecs[NUM_PROCESSES] = { 0 }; for (int i = 0; i < NUM_PROCESSES; i++) selectRecs[i] = (Rectangle){ 40.0f, (float)(50 + 32*i), 150.0f, 30.0f }; diff --git a/examples/textures/textures_particles_blending.c b/examples/textures/textures_particles_blending.c index 75287ea7..d094c6c2 100644 --- a/examples/textures/textures_particles_blending.c +++ b/examples/textures/textures_particles_blending.c @@ -33,7 +33,7 @@ int main(void) InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending"); // Particles pool, reuse them! - Particle mouseTail[MAX_PARTICLES]; + Particle mouseTail[MAX_PARTICLES] = { 0 }; // Initialize particles for (int i = 0; i < MAX_PARTICLES; i++) diff --git a/examples/textures/textures_raw_data.c b/examples/textures/textures_raw_data.c index 17604bde..08269bf7 100644 --- a/examples/textures/textures_raw_data.c +++ b/examples/textures/textures_raw_data.c @@ -31,7 +31,7 @@ int main(void) Texture2D fudesumi = LoadTextureFromImage(fudesumiRaw); // Upload CPU (RAM) image to GPU (VRAM) UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data - // Generate a checked texture by code (1024x1024 pixels) + // Generate a checked texture by code int width = 960; int height = 480; diff --git a/examples/textures/textures_sprite_explosion.c b/examples/textures/textures_sprite_explosion.c index 58a8f6fc..823c1b8a 100644 --- a/examples/textures/textures_sprite_explosion.c +++ b/examples/textures/textures_sprite_explosion.c @@ -38,7 +38,7 @@ int main(void) int currentLine = 0; Rectangle frameRec = { 0, 0, frameWidth, frameHeight }; - Vector2 position = { 0, 0 }; + Vector2 position = { 0.0f, 0.0f }; bool active = false; int framesCounter = 0; -- cgit v1.2.3 From 42d57bbe00c99fe3cf6a0819b9a2bf4bf3b64873 Mon Sep 17 00:00:00 2001 From: Chris Dill Date: Wed, 29 May 2019 13:58:31 +0100 Subject: Added array bounds check to textures_bunnymark --- examples/textures/textures_bunnymark.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'examples/textures') diff --git a/examples/textures/textures_bunnymark.c b/examples/textures/textures_bunnymark.c index 6b91d646..784417d2 100644 --- a/examples/textures/textures_bunnymark.c +++ b/examples/textures/textures_bunnymark.c @@ -54,13 +54,16 @@ int main(void) // Create more bunnies for (int i = 0; i < 100; i++) { - bunnies[bunniesCount].position = GetMousePosition(); - bunnies[bunniesCount].speed.x = (float)GetRandomValue(-250, 250)/60.0f; - bunnies[bunniesCount].speed.y = (float)GetRandomValue(-250, 250)/60.0f; - bunnies[bunniesCount].color = (Color){ GetRandomValue(50, 240), + if (bunniesCount < MAX_BUNNIES) + { + bunnies[bunniesCount].position = GetMousePosition(); + bunnies[bunniesCount].speed.x = (float)GetRandomValue(-250, 250)/60.0f; + bunnies[bunniesCount].speed.y = (float)GetRandomValue(-250, 250)/60.0f; + bunnies[bunniesCount].color = (Color){ GetRandomValue(50, 240), GetRandomValue(80, 240), GetRandomValue(100, 240), 255 }; - bunniesCount++; + bunniesCount++; + } } } -- cgit v1.2.3