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.

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