diff options
| author | Ray San <[email protected]> | 2017-10-17 11:51:50 +0200 |
|---|---|---|
| committer | Ray San <[email protected]> | 2017-10-17 11:51:50 +0200 |
| commit | 5dc216f4196603a9b5951b596ac2b9b0e84d56e3 (patch) | |
| tree | 25da3d9671843713029e5c2de4d50e390ff964fa /examples/textures | |
| parent | b065edc8785a5a7aca3dfe79163b15aa7a0d6883 (diff) | |
| download | raylib-5dc216f4196603a9b5951b596ac2b9b0e84d56e3.tar.gz raylib-5dc216f4196603a9b5951b596ac2b9b0e84d56e3.zip | |
Improved some examples
Diffstat (limited to 'examples/textures')
| -rw-r--r-- | examples/textures/resources/custom_jupiter_crash.png | bin | 0 -> 23596 bytes | |||
| -rw-r--r-- | examples/textures/textures_image_drawing.c | 8 | ||||
| -rw-r--r-- | examples/textures/textures_image_generation.c | 44 | ||||
| -rw-r--r-- | examples/textures/textures_image_generation.png | bin | 222595 -> 225357 bytes |
4 files changed, 38 insertions, 14 deletions
diff --git a/examples/textures/resources/custom_jupiter_crash.png b/examples/textures/resources/custom_jupiter_crash.png Binary files differnew file mode 100644 index 00000000..451b591f --- /dev/null +++ b/examples/textures/resources/custom_jupiter_crash.png diff --git a/examples/textures/textures_image_drawing.c b/examples/textures/textures_image_drawing.c index 1c6a1fb9..ac128af9 100644 --- a/examples/textures/textures_image_drawing.c +++ b/examples/textures/textures_image_drawing.c @@ -36,6 +36,14 @@ int main() 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 + SpriteFont font = LoadSpriteFont("resources/custom_jupiter_crash.png"); + + // Draw over image using custom font + ImageDrawTextEx(&parrots, (Vector2){ 300, 230 }, font, "PARROTS & CAT", font.baseSize, -2, WHITE); + + UnloadSpriteFont(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 diff --git a/examples/textures/textures_image_generation.c b/examples/textures/textures_image_generation.c index 8f87e689..7d8e017e 100644 --- a/examples/textures/textures_image_generation.c +++ b/examples/textures/textures_image_generation.c @@ -11,7 +11,7 @@ #include "raylib.h" -#define TEXTURES_NUM 7 // for now we have 7 generation algorithms +#define NUM_TEXTURES 7 // Currently we have 7 generation algorithms int main() { @@ -30,7 +30,7 @@ int main() Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 8.f); Image cellular = GenImageCellular(screenWidth, screenHeight, 32); - Texture2D textures[TEXTURES_NUM]; + Texture2D textures[NUM_TEXTURES]; textures[0] = LoadTextureFromImage(verticalGradient); textures[1] = LoadTextureFromImage(horizontalGradient); textures[2] = LoadTextureFromImage(radialGradient); @@ -38,6 +38,15 @@ int main() 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; @@ -51,7 +60,7 @@ int main() //---------------------------------------------------------------------------------- if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { - currentTexture = (currentTexture + 1) % TEXTURES_NUM; // cycle between the 5 textures + currentTexture = (currentTexture + 1)%NUM_TEXTURES; // Cycle between the textures } //---------------------------------------------------------------------------------- @@ -63,24 +72,31 @@ int main() 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 image data (CPU RAM) - UnloadImage(verticalGradient); - UnloadImage(horizontalGradient); - UnloadImage(radialGradient); - UnloadImage(checked); - UnloadImage(whiteNoise); - UnloadImage(perlinNoise); - UnloadImage(cellular); - + // Unload textures data (GPU VRAM) - for (int i = 0; i < TEXTURES_NUM; i++) UnloadTexture(textures[i]); + for (int i = 0; i < NUM_TEXTURES; i++) UnloadTexture(textures[i]); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/textures/textures_image_generation.png b/examples/textures/textures_image_generation.png Binary files differindex a272b405..398b0462 100644 --- a/examples/textures/textures_image_generation.png +++ b/examples/textures/textures_image_generation.png |
