diff options
| author | Ray <[email protected]> | 2019-05-21 17:03:01 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2019-05-21 17:03:01 +0200 |
| commit | 6f4a27cc61f12d3789729413bed69e86226911cf (patch) | |
| tree | 92a23884870826e6deaf560743ebbdae8bce94ba /examples/src/textures | |
| parent | 2141d7943b6b65fa66f583f0819bb27fee815189 (diff) | |
| download | raylib.com-6f4a27cc61f12d3789729413bed69e86226911cf.tar.gz raylib.com-6f4a27cc61f12d3789729413bed69e86226911cf.zip | |
Remove examples default code
Code is directly fetched form raylib repo, this way we avoid duplicate code!
Diffstat (limited to 'examples/src/textures')
| -rw-r--r-- | examples/src/textures/textures_background_scrolling.c | 87 | ||||
| -rw-r--r-- | examples/src/textures/textures_bunnymark.c | 117 | ||||
| -rw-r--r-- | examples/src/textures/textures_image_drawing.c | 86 | ||||
| -rw-r--r-- | examples/src/textures/textures_image_generation.c | 105 | ||||
| -rw-r--r-- | examples/src/textures/textures_image_loading.c | 63 | ||||
| -rw-r--r-- | examples/src/textures/textures_image_processing.c | 145 | ||||
| -rw-r--r-- | examples/src/textures/textures_image_text.c | 83 | ||||
| -rw-r--r-- | examples/src/textures/textures_logo_raylib.c | 57 | ||||
| -rw-r--r-- | examples/src/textures/textures_npatch_drawing.c | 109 | ||||
| -rw-r--r-- | examples/src/textures/textures_particles_blending.c | 135 | ||||
| -rw-r--r-- | examples/src/textures/textures_raw_data.c | 95 | ||||
| -rw-r--r-- | examples/src/textures/textures_rectangle.c | 99 | ||||
| -rw-r--r-- | examples/src/textures/textures_sprite_button.c | 97 | ||||
| -rw-r--r-- | examples/src/textures/textures_sprite_explosion.c | 120 | ||||
| -rw-r--r-- | examples/src/textures/textures_srcrec_dstrec.c | 82 | ||||
| -rw-r--r-- | examples/src/textures/textures_to_image.c | 68 |
16 files changed, 0 insertions, 1548 deletions
diff --git a/examples/src/textures/textures_background_scrolling.c b/examples/src/textures/textures_background_scrolling.c deleted file mode 100644 index d91b258..0000000 --- a/examples/src/textures/textures_background_scrolling.c +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************************* -* -* 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(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - 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); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // 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/src/textures/textures_bunnymark.c b/examples/src/textures/textures_bunnymark.c deleted file mode 100644 index 6b91d64..0000000 --- a/examples/src/textures/textures_bunnymark.c +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************************* -* -* 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 <stdlib.h> // 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(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - 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 - - int bunniesCount = 0; // Bunnies counter - - 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 - //---------------------------------------------------------------------------------- - 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; -} diff --git a/examples/src/textures/textures_image_drawing.c b/examples/src/textures/textures_image_drawing.c deleted file mode 100644 index f5c3c85..0000000 --- a/examples/src/textures/textures_image_drawing.c +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - Image loading and drawing on it -* -* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) -* -* 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(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [textures] example - image drawing"); - - // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - - Image cat = LoadImage("resources/cat.png"); // Load image in CPU memory (RAM) - 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); - //--------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - // TODO: Update your variables here - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, WHITE); - DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, texture.width, texture.height, DARKGRAY); - - DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, DARKGRAY); - DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, DARKGRAY); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Texture unloading - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/textures/textures_image_generation.c b/examples/src/textures/textures_image_generation.c deleted file mode 100644 index d9a39a2..0000000 --- a/examples/src/textures/textures_image_generation.c +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - Procedural images generation -* -* 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) -* -* Copyright (c) 2O17 Wilhem Barbier (@nounoursheureux) -* -********************************************************************************************/ - -#include "raylib.h" - -#define NUM_TEXTURES 7 // Currently we have 7 generation algorithms - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [textures] example - procedural images generation"); - - Image verticalGradient = GenImageGradientV(screenWidth, screenHeight, RED, BLUE); - Image horizontalGradient = GenImageGradientH(screenWidth, screenHeight, RED, BLUE); - Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.0f, WHITE, BLACK); - Image checked = GenImageChecked(screenWidth, screenHeight, 32, 32, RED, BLUE); - Image whiteNoise = GenImageWhiteNoise(screenWidth, screenHeight, 0.5f); - Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0f); - Image cellular = GenImageCellular(screenWidth, screenHeight, 32); - - Texture2D textures[NUM_TEXTURES]; - textures[0] = LoadTextureFromImage(verticalGradient); - textures[1] = LoadTextureFromImage(horizontalGradient); - textures[2] = LoadTextureFromImage(radialGradient); - textures[3] = LoadTextureFromImage(checked); - textures[4] = LoadTextureFromImage(whiteNoise); - textures[5] = LoadTextureFromImage(perlinNoise); - textures[6] = LoadTextureFromImage(cellular); - - // Unload image data (CPU RAM) - UnloadImage(verticalGradient); - UnloadImage(horizontalGradient); - UnloadImage(radialGradient); - UnloadImage(checked); - UnloadImage(whiteNoise); - UnloadImage(perlinNoise); - UnloadImage(cellular); - - int currentTexture = 0; - - SetTargetFPS(60); - //--------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) - { - // Update - //---------------------------------------------------------------------------------- - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsKeyPressed(KEY_RIGHT)) - { - currentTexture = (currentTexture + 1)%NUM_TEXTURES; // Cycle between the textures - } - //---------------------------------------------------------------------------------- - - // 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; - case 1: DrawText("HORIZONTAL GRADIENT", 540, 10, 20, RAYWHITE); break; - case 2: DrawText("RADIAL GRADIENT", 580, 10, 20, LIGHTGRAY); break; - case 3: DrawText("CHECKED", 680, 10, 20, RAYWHITE); break; - case 4: DrawText("WHITE NOISE", 640, 10, 20, RED); break; - case 5: DrawText("PERLIN NOISE", 630, 10, 20, RAYWHITE); break; - 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/src/textures/textures_image_loading.c b/examples/src/textures/textures_image_loading.c deleted file mode 100644 index 265cab4..0000000 --- a/examples/src/textures/textures_image_loading.c +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - Image loading and texture creation -* -* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) -* -* This example has been created using raylib 1.3 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2015 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading"); - - // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - - Image image = LoadImage("resources/raylib_logo.png"); // Loaded in CPU memory (RAM) - Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM) - - UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM - //--------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - // TODO: Update your variables here - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); - - DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Texture unloading - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/textures/textures_image_processing.c b/examples/src/textures/textures_image_processing.c deleted file mode 100644 index b9ed51d..0000000 --- a/examples/src/textures/textures_image_processing.c +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - Image processing -* -* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) -* -* 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" - -#include <stdlib.h> // 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 -} ImageProcess; - -static const char *processText[] = { - "NO PROCESSING", - "COLOR GRAYSCALE", - "COLOR TINT", - "COLOR INVERT", - "COLOR CONTRAST", - "COLOR BRIGHTNESS", - "FLIP VERTICAL", - "FLIP HORIZONTAL" -}; - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing"); - - // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - - Image image = LoadImage("resources/parrots.png"); // Loaded in CPU memory (RAM) - ImageFormat(&image, UNCOMPRESSED_R8G8B8A8); // Format image to RGBA 32bit (required for texture update) <-- ISSUE - Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM) - - int currentProcess = NONE; - 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); - //--------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - if (IsKeyPressed(KEY_DOWN)) - { - currentProcess++; - if (currentProcess > 7) currentProcess = 0; - textureReload = true; - } - else if (IsKeyPressed(KEY_UP)) - { - currentProcess--; - 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 - // with a texture and by shaders - switch (currentProcess) - { - case COLOR_GRAYSCALE: ImageColorGrayscale(&image); break; - case COLOR_TINT: ImageColorTint(&image, GREEN); break; - case COLOR_INVERT: ImageColorInvert(&image); break; - case COLOR_CONTRAST: ImageColorContrast(&image, -40); break; - case COLOR_BRIGHTNESS: ImageColorBrightness(&image, -80); break; - case FLIP_VERTICAL: ImageFlipVertical(&image); break; - 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; - } - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawText("IMAGE PROCESSING:", 40, 30, 10, DARKGRAY); - - // Draw rectangles - for (int i = 0; i < NUM_PROCESSES; i++) - { - DrawRectangleRec(selectRecs[i], (i == currentProcess) ? SKYBLUE : LIGHTGRAY); - DrawRectangleLines((int)selectRecs[i].x, (int) selectRecs[i].y, (int) selectRecs[i].width, (int) selectRecs[i].height, (i == currentProcess) ? BLUE : GRAY); - DrawText( processText[i], (int)( selectRecs[i].x + selectRecs[i].width/2 - MeasureText(processText[i], 10)/2), (int) selectRecs[i].y + 11, 10, (i == currentProcess) ? DARKBLUE : DARKGRAY); - } - - 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(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Unload texture from VRAM - UnloadImage(image); // Unload image from RAM - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/textures/textures_image_text.c b/examples/src/textures/textures_image_text.c deleted file mode 100644 index c8dfe45..0000000 --- a/examples/src/textures/textures_image_text.c +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************************* -* -* raylib [texture] example - Image text drawing using TTF generated spritefont -* -* 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) -* -* Copyright (c) 2017 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - 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); - - // 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); - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - if (IsKeyDown(KEY_SPACE)) showFont = true; - else showFont = false; - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - if (!showFont) - { - // 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, - 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(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Texture unloading - - UnloadFont(font); // Unload custom spritefont - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/textures/textures_logo_raylib.c b/examples/src/textures/textures_logo_raylib.c deleted file mode 100644 index de8bb2a..0000000 --- a/examples/src/textures/textures_logo_raylib.c +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - Texture loading and drawing -* -* 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(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing"); - - // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - Texture2D texture = LoadTexture("resources/raylib_logo.png"); // Texture loading - //--------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - // TODO: Update your variables here - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); - - DrawText("this IS a texture!", 360, 370, 10, GRAY); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Texture unloading - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/textures/textures_npatch_drawing.c b/examples/src/textures/textures_npatch_drawing.c deleted file mode 100644 index 1c57e2e..0000000 --- a/examples/src/textures/textures_npatch_drawing.c +++ /dev/null @@ -1,109 +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) -* -* 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(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - 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 }; - - // 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/src/textures/textures_particles_blending.c b/examples/src/textures/textures_particles_blending.c deleted file mode 100644 index 75287ea..0000000 --- a/examples/src/textures/textures_particles_blending.c +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************************* -* -* raylib example - particles blending -* -* This example has been created using raylib 1.7 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2017 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#define MAX_PARTICLES 200 - -// Particle structure with basic data -typedef struct { - Vector2 position; - Color color; - float alpha; - float size; - float rotation; - bool active; // NOTE: Use it to activate/deactive particle -} Particle; - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending"); - - // Particles pool, reuse them! - Particle mouseTail[MAX_PARTICLES]; - - // Initialize particles - for (int i = 0; i < MAX_PARTICLES; i++) - { - mouseTail[i].position = (Vector2){ 0, 0 }; - mouseTail[i].color = (Color){ GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 }; - mouseTail[i].alpha = 1.0f; - mouseTail[i].size = (float)GetRandomValue(1, 30)/20.0f; - 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); - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // 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) - // NOTE: When a particle disappears, active = false and it can be reused. - for (int i = 0; i < MAX_PARTICLES; i++) - { - if (!mouseTail[i].active) - { - mouseTail[i].active = true; - mouseTail[i].alpha = 1.0f; - mouseTail[i].position = GetMousePosition(); - i = MAX_PARTICLES; - } - } - - for (int i = 0; i < MAX_PARTICLES; i++) - { - if (mouseTail[i].active) - { - 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; - else blending = BLEND_ALPHA; - } - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - 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 }, - (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(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(smoke); - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/textures/textures_raw_data.c b/examples/src/textures/textures_raw_data.c deleted file mode 100644 index 17604bd..0000000 --- a/examples/src/textures/textures_raw_data.c +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - Load textures from raw data -* -* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) -* -* This example has been created using raylib 1.3 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2015 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#include <stdlib.h> // Required for: malloc() and free() - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - 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 - - // 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++) - { - if (((x/32+y/32)/1)%2 == 0) pixels[y*width + x] = ORANGE; - 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 - - // Dynamic memory must be freed after using it - free(pixels); // Unload CPU (RAM) pixels data - //--------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - // TODO: Update your variables here - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, Fade(WHITE, 0.5f)); - DrawTexture(fudesumi, 430, -30, WHITE); - - 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(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(fudesumi); // Texture unloading - UnloadTexture(checked); // Texture unloading - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/textures/textures_rectangle.c b/examples/src/textures/textures_rectangle.c deleted file mode 100644 index 8be647a..0000000 --- a/examples/src/textures/textures_rectangle.c +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - Texture loading and drawing a part defined by a rectangle -* -* This example has been created using raylib 1.3 (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" - -#define MAX_FRAME_SPEED 15 -#define MIN_FRAME_SPEED 1 - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle"); - - // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading - - 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 - - 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 - //---------------------------------------------------------------------------------- - 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; - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - 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); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(scarfy); // Texture unloading - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/textures/textures_sprite_button.c b/examples/src/textures/textures_sprite_button.c deleted file mode 100644 index a5b2d8d..0000000 --- a/examples/src/textures/textures_sprite_button.c +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************************* -* -* 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(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 - { - // 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 diff --git a/examples/src/textures/textures_sprite_explosion.c b/examples/src/textures/textures_sprite_explosion.c deleted file mode 100644 index 58a8f6f..0000000 --- a/examples/src/textures/textures_sprite_explosion.c +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************************* -* -* 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(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"); - - // 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 diff --git a/examples/src/textures/textures_srcrec_dstrec.c b/examples/src/textures/textures_srcrec_dstrec.c deleted file mode 100644 index e86b729..0000000 --- a/examples/src/textures/textures_srcrec_dstrec.c +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - Texture source and destination rectangles -* -* This example has been created using raylib 1.3 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2015 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - 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; - - // Source rectangle (part of the texture to use for drawing) - Rectangle sourceRec = { 0.0f, 0.0f, frameWidth, frameHeight }; - - // Destination rectangle (screen rectangle where drawing part of texture) - Rectangle destRec = { screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2 }; - - // Origin of the texture (rotation/scale point), it's relative to destination rectangle size - Vector2 origin = { frameWidth, frameHeight }; - - int rotation = 0; - - SetTargetFPS(60); - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - rotation++; - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - // NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw - // sourceRec defines the part of the texture we use for drawing - // destRec defines the rectangle where our texture part will fit (scaling it to fit) - // origin defines the point of the texture used as reference for rotation and scaling - // 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(0, (int)destRec.y, screenWidth, (int)destRec.y, GRAY); - - DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(scarfy); // Texture unloading - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/textures/textures_to_image.c b/examples/src/textures/textures_to_image.c deleted file mode 100644 index c0989ba..0000000 --- a/examples/src/textures/textures_to_image.c +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - Retrieve image data from texture: GetTextureData() -* -* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) -* -* This example has been created using raylib 1.3 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2015 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image"); - - // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - - 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) - //--------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - // TODO: Update your variables here - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); - - DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Texture unloading - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file |
