shaders_shapes_textures.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. int main()
  20. {
  21. // Initialization
  22. //--------------------------------------------------------------------------------------
  23. int screenWidth = 800;
  24. int screenHeight = 450;
  25. InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders");
  26. Texture2D fudesumi = LoadTexture("resources/fudesumi.png");
  27. // NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
  28. Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
  29. "resources/shaders/glsl330/grayscale.fs");
  30. SetTargetFPS(60);
  31. //--------------------------------------------------------------------------------------
  32. // Main game loop
  33. while (!WindowShouldClose()) // Detect window close button or ESC key
  34. {
  35. // Update
  36. //----------------------------------------------------------------------------------
  37. // TODO: Update your variables here
  38. //----------------------------------------------------------------------------------
  39. // Draw
  40. //----------------------------------------------------------------------------------
  41. BeginDrawing();
  42. ClearBackground(RAYWHITE);
  43. // Start drawing with default shader
  44. DrawText("USING DEFAULT SHADER", 20, 40, 10, RED);
  45. DrawCircle(80, 120, 35, DARKBLUE);
  46. DrawCircleGradient(80, 220, 60, GREEN, SKYBLUE);
  47. DrawCircleLines(80, 340, 80, DARKBLUE);
  48. // Activate our custom shader to be applied on next shapes/textures drawings
  49. BeginShaderMode(shader);
  50. DrawText("USING CUSTOM SHADER", 190, 40, 10, RED);
  51. DrawRectangle(250 - 60, 90, 120, 60, RED);
  52. DrawRectangleGradientH(250 - 90, 170, 180, 130, MAROON, GOLD);
  53. DrawRectangleLines(250 - 40, 320, 80, 60, ORANGE);
  54. // Activate our default shader for next drawings
  55. EndShaderMode();
  56. DrawText("USING DEFAULT SHADER", 370, 40, 10, RED);
  57. DrawTriangle((Vector2){430, 80},
  58. (Vector2){430 - 60, 150},
  59. (Vector2){430 + 60, 150}, VIOLET);
  60. DrawTriangleLines((Vector2){430, 160},
  61. (Vector2){430 - 20, 230},
  62. (Vector2){430 + 20, 230}, DARKBLUE);
  63. DrawPoly((Vector2){430, 320}, 6, 80, 0, BROWN);
  64. // Activate our custom shader to be applied on next shapes/textures drawings
  65. BeginShaderMode(shader);
  66. DrawTexture(fudesumi, 500, -30, WHITE); // Using custom shader
  67. // Activate our default shader for next drawings
  68. EndShaderMode();
  69. DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight - 20, 10, GRAY);
  70. EndDrawing();
  71. //----------------------------------------------------------------------------------
  72. }
  73. // De-Initialization
  74. //--------------------------------------------------------------------------------------
  75. UnloadShader(shader); // Unload shader
  76. UnloadTexture(fudesumi); // Unload texture
  77. CloseWindow(); // Close window and OpenGL context
  78. //--------------------------------------------------------------------------------------
  79. return 0;
  80. }