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.

80 lines
3.2 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [textures] example - Texture drawing
  4. *
  5. * This example illustrates how to draw on a blank texture using a shader
  6. *
  7. * This example has been created using raylib 2.0 (www.raylib.com)
  8. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  9. *
  10. * Example contributed by Michał Ciesielski and reviewed by Ramon Santamaria (@raysan5)
  11. *
  12. * Copyright (c) 2019 Michał Ciesielski and Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include "raylib.h"
  16. #if defined(PLATFORM_DESKTOP)
  17. #define GLSL_VERSION 330
  18. #else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
  19. #define GLSL_VERSION 100
  20. #endif
  21. int main(void)
  22. {
  23. // Initialization
  24. //--------------------------------------------------------------------------------------
  25. const int screenWidth = 800;
  26. const int screenHeight = 450;
  27. InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture drawing");
  28. Image imBlank = GenImageColor(1024, 1024, BLANK);
  29. Texture2D texture = LoadTextureFromImage(imBlank); // Load blank texture to fill on shader
  30. UnloadImage(imBlank);
  31. // NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
  32. Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/cubes_panning.fs", GLSL_VERSION));
  33. float time = 0.0f;
  34. int timeLoc = GetShaderLocation(shader, "uTime");
  35. SetShaderValue(shader, timeLoc, &time, UNIFORM_FLOAT);
  36. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  37. // -------------------------------------------------------------------------------------------------------------
  38. // Main game loop
  39. while (!WindowShouldClose()) // Detect window close button or ESC key
  40. {
  41. // Update
  42. //----------------------------------------------------------------------------------
  43. time = GetTime();
  44. SetShaderValue(shader, timeLoc, &time, UNIFORM_FLOAT);
  45. //----------------------------------------------------------------------------------
  46. // Draw
  47. //----------------------------------------------------------------------------------
  48. BeginDrawing();
  49. ClearBackground(RAYWHITE);
  50. BeginShaderMode(shader); // Enable our custom shader for next shapes/textures drawings
  51. DrawTexture(texture, 0, 0, WHITE); // Drawing BLANK texture, all magic happens on shader
  52. EndShaderMode(); // Disable our custom shader, return to default shader
  53. DrawText("BACKGROUND is PAINTED and ANIMATED on SHADER!", 10, 10, 20, MAROON);
  54. EndDrawing();
  55. //----------------------------------------------------------------------------------
  56. }
  57. // De-Initialization
  58. //--------------------------------------------------------------------------------------
  59. UnloadShader(shader);
  60. CloseWindow(); // Close window and OpenGL context
  61. //--------------------------------------------------------------------------------------
  62. return 0;
  63. }