shaders_shapes_textures.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.6 (www.raylib.com)
  13. -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  14. --
  15. -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
  16. --
  17. -------------------------------------------------------------------------------------------
  18. -- Initialization
  19. -------------------------------------------------------------------------------------------
  20. local screenWidth = 800
  21. local screenHeight = 450
  22. InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders")
  23. local sonic = LoadTexture("resources/texture_formats/sonic.png")
  24. -- NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
  25. local shader = LoadShader("resources/shaders/glsl330/base.vs",
  26. "resources/shaders/glsl330/grayscale.fs")
  27. -- Shader usage is also different than models/postprocessing, shader is just activated when required
  28. SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
  29. -------------------------------------------------------------------------------------------
  30. -- Main game loop
  31. while not WindowShouldClose() do -- Detect window close button or ESC key
  32. -- Update
  33. ---------------------------------------------------------------------------------------
  34. -- TODO: Update your variables here
  35. ---------------------------------------------------------------------------------------
  36. -- Draw
  37. ---------------------------------------------------------------------------------------
  38. BeginDrawing()
  39. ClearBackground(RAYWHITE)
  40. -- Start drawing with default shader
  41. DrawText("USING DEFAULT SHADER", 20, 40, 10, RED)
  42. DrawCircle(80, 120, 35, DARKBLUE)
  43. DrawCircleGradient(80, 220, 60, GREEN, SKYBLUE)
  44. DrawCircleLines(80, 340, 80, DARKBLUE)
  45. -- Activate our custom shader to be applied on next shapes/textures drawings
  46. BeginShaderMode(shader)
  47. DrawText("USING CUSTOM SHADER", 190, 40, 10, RED)
  48. DrawRectangle(250 - 60, 90, 120, 60, RED)
  49. DrawRectangleGradient(250 - 90, 170, 180, 130, MAROON, GOLD)
  50. DrawRectangleLines(250 - 40, 320, 80, 60, ORANGE)
  51. -- Activate our default shader for next drawings
  52. EndShaderMode()
  53. DrawText("USING DEFAULT SHADER", 370, 40, 10, RED)
  54. DrawTriangle(Vector2(430, 80),
  55. Vector2(430 - 60, 150),
  56. Vector2(430 + 60, 150), VIOLET)
  57. DrawTriangleLines(Vector2(430, 160),
  58. Vector2(430 - 20, 230),
  59. Vector2(430 + 20, 230), DARKBLUE)
  60. DrawPoly(Vector2(430, 320), 6, 80, 0, BROWN)
  61. -- Activate our custom shader to be applied on next shapes/textures drawings
  62. BeginShaderMode(shader)
  63. DrawTexture(sonic, 380, -10, WHITE) -- Using custom shader
  64. -- Activate our default shader for next drawings
  65. EndShaderMode()
  66. EndDrawing()
  67. ---------------------------------------------------------------------------------------
  68. end
  69. -- De-Initialization
  70. -------------------------------------------------------------------------------------------
  71. UnloadShader(shader) -- Unload shader
  72. UnloadTexture(sonic) -- Unload texture
  73. CloseWindow() -- Close window and OpenGL context
  74. -------------------------------------------------------------------------------------------