You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
4.1 KiB

преди 5 години
преди 5 години
преди 5 години
преди 5 години
преди 7 години
преди 5 години
преди 5 години
преди 7 години
преди 5 години
преди 5 години
преди 5 години
преди 7 години
преди 5 години
преди 7 години
преди 7 години
преди 5 години
преди 5 години
преди 7 години
преди 5 години
преди 5 години
  1. /*******************************************************************************************
  2. *
  3. * raylib [textures] example - Procedural images generation
  4. *
  5. * This example has been created using raylib 1.8 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2O17-2021 Wilhem Barbier (@nounoursheureux) and Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. #define NUM_TEXTURES 6 // Currently we have 7 generation algorithms
  13. int main(void)
  14. {
  15. // Initialization
  16. //--------------------------------------------------------------------------------------
  17. const int screenWidth = 800;
  18. const int screenHeight = 450;
  19. InitWindow(screenWidth, screenHeight, "raylib [textures] example - procedural images generation");
  20. Image verticalGradient = GenImageGradientV(screenWidth, screenHeight, RED, BLUE);
  21. Image horizontalGradient = GenImageGradientH(screenWidth, screenHeight, RED, BLUE);
  22. Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.0f, WHITE, BLACK);
  23. Image checked = GenImageChecked(screenWidth, screenHeight, 32, 32, RED, BLUE);
  24. Image whiteNoise = GenImageWhiteNoise(screenWidth, screenHeight, 0.5f);
  25. Image cellular = GenImageCellular(screenWidth, screenHeight, 32);
  26. Texture2D textures[NUM_TEXTURES] = { 0 };
  27. textures[0] = LoadTextureFromImage(verticalGradient);
  28. textures[1] = LoadTextureFromImage(horizontalGradient);
  29. textures[2] = LoadTextureFromImage(radialGradient);
  30. textures[3] = LoadTextureFromImage(checked);
  31. textures[4] = LoadTextureFromImage(whiteNoise);
  32. textures[5] = LoadTextureFromImage(cellular);
  33. // Unload image data (CPU RAM)
  34. UnloadImage(verticalGradient);
  35. UnloadImage(horizontalGradient);
  36. UnloadImage(radialGradient);
  37. UnloadImage(checked);
  38. UnloadImage(whiteNoise);
  39. UnloadImage(cellular);
  40. int currentTexture = 0;
  41. SetTargetFPS(60);
  42. //---------------------------------------------------------------------------------------
  43. // Main game loop
  44. while (!WindowShouldClose())
  45. {
  46. // Update
  47. //----------------------------------------------------------------------------------
  48. if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsKeyPressed(KEY_RIGHT))
  49. {
  50. currentTexture = (currentTexture + 1)%NUM_TEXTURES; // Cycle between the textures
  51. }
  52. //----------------------------------------------------------------------------------
  53. // Draw
  54. //----------------------------------------------------------------------------------
  55. BeginDrawing();
  56. ClearBackground(RAYWHITE);
  57. DrawTexture(textures[currentTexture], 0, 0, WHITE);
  58. DrawRectangle(30, 400, 325, 30, Fade(SKYBLUE, 0.5f));
  59. DrawRectangleLines(30, 400, 325, 30, Fade(WHITE, 0.5f));
  60. DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, WHITE);
  61. switch(currentTexture)
  62. {
  63. case 0: DrawText("VERTICAL GRADIENT", 560, 10, 20, RAYWHITE); break;
  64. case 1: DrawText("HORIZONTAL GRADIENT", 540, 10, 20, RAYWHITE); break;
  65. case 2: DrawText("RADIAL GRADIENT", 580, 10, 20, LIGHTGRAY); break;
  66. case 3: DrawText("CHECKED", 680, 10, 20, RAYWHITE); break;
  67. case 4: DrawText("WHITE NOISE", 640, 10, 20, RED); break;
  68. case 5: DrawText("CELLULAR", 670, 10, 20, RAYWHITE); break;
  69. default: break;
  70. }
  71. EndDrawing();
  72. //----------------------------------------------------------------------------------
  73. }
  74. // De-Initialization
  75. //--------------------------------------------------------------------------------------
  76. // Unload textures data (GPU VRAM)
  77. for (int i = 0; i < NUM_TEXTURES; i++) UnloadTexture(textures[i]);
  78. CloseWindow(); // Close window and OpenGL context
  79. //--------------------------------------------------------------------------------------
  80. return 0;
  81. }