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.

115 lines
4.6 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [shaders] example - Apply a shader to some shape or texture
  4. *
  5. * NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
  6. * OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
  7. *
  8. * NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
  9. * on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
  10. * raylib comes with shaders ready for both versions, check raylib/shaders install folder
  11. *
  12. * This example has been created using raylib 1.7 (www.raylib.com)
  13. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  14. *
  15. * Copyright (c) 2015 Ramon Santamaria (@raysan5)
  16. *
  17. ********************************************************************************************/
  18. #include "raylib.h"
  19. #if defined(PLATFORM_DESKTOP)
  20. #define GLSL_VERSION 330
  21. #else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
  22. #define GLSL_VERSION 100
  23. #endif
  24. int main(void)
  25. {
  26. // Initialization
  27. //--------------------------------------------------------------------------------------
  28. const int screenWidth = 800;
  29. const int screenHeight = 450;
  30. InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders");
  31. Texture2D fudesumi = LoadTexture("resources/fudesumi.png");
  32. // Load shader to be used on some parts drawing
  33. // NOTE 1: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
  34. // NOTE 2: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
  35. Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION));
  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. // TODO: Update your variables here
  44. //----------------------------------------------------------------------------------
  45. // Draw
  46. //----------------------------------------------------------------------------------
  47. BeginDrawing();
  48. ClearBackground(RAYWHITE);
  49. // Start drawing with default shader
  50. DrawText("USING DEFAULT SHADER", 20, 40, 10, RED);
  51. DrawCircle(80, 120, 35, DARKBLUE);
  52. DrawCircleGradient(80, 220, 60, GREEN, SKYBLUE);
  53. DrawCircleLines(80, 340, 80, DARKBLUE);
  54. // Activate our custom shader to be applied on next shapes/textures drawings
  55. BeginShaderMode(shader);
  56. DrawText("USING CUSTOM SHADER", 190, 40, 10, RED);
  57. DrawRectangle(250 - 60, 90, 120, 60, RED);
  58. DrawRectangleGradientH(250 - 90, 170, 180, 130, MAROON, GOLD);
  59. DrawRectangleLines(250 - 40, 320, 80, 60, ORANGE);
  60. // Activate our default shader for next drawings
  61. EndShaderMode();
  62. DrawText("USING DEFAULT SHADER", 370, 40, 10, RED);
  63. DrawTriangle((Vector2){430, 80},
  64. (Vector2){430 - 60, 150},
  65. (Vector2){430 + 60, 150}, VIOLET);
  66. DrawTriangleLines((Vector2){430, 160},
  67. (Vector2){430 - 20, 230},
  68. (Vector2){430 + 20, 230}, DARKBLUE);
  69. DrawPoly((Vector2){430, 320}, 6, 80, 0, BROWN);
  70. // Activate our custom shader to be applied on next shapes/textures drawings
  71. BeginShaderMode(shader);
  72. DrawTexture(fudesumi, 500, -30, WHITE); // Using custom shader
  73. // Activate our default shader for next drawings
  74. EndShaderMode();
  75. DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight - 20, 10, GRAY);
  76. EndDrawing();
  77. //----------------------------------------------------------------------------------
  78. }
  79. // De-Initialization
  80. //--------------------------------------------------------------------------------------
  81. UnloadShader(shader); // Unload shader
  82. UnloadTexture(fudesumi); // Unload texture
  83. CloseWindow(); // Close window and OpenGL context
  84. //--------------------------------------------------------------------------------------
  85. return 0;
  86. }