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
19#include "raylib.h"
20
21#if defined(PLATFORM_DESKTOP)
22 #define GLSL_VERSION 330
23#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
24 #define GLSL_VERSION 100
25#endif
26
27int main(void)
28{
29 // Initialization
30 //--------------------------------------------------------------------------------------
31 const int screenWidth = 800;
32 const int screenHeight = 450;
33
34 InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders");
35
36 Texture2D fudesumi = LoadTexture("resources/fudesumi.png");
37
38 // Load shader to be used on some parts drawing
39 // NOTE 1: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
40 // NOTE 2: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
41 Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION));
42
43 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
44 //--------------------------------------------------------------------------------------
45
46 // Main game loop
47 while (!WindowShouldClose()) // Detect window close button or ESC key
48 {
49 // Update
50 //----------------------------------------------------------------------------------
51 // TODO: Update your variables here
52 //----------------------------------------------------------------------------------
53
54 // Draw
55 //----------------------------------------------------------------------------------
56 BeginDrawing();
57
58 ClearBackground(RAYWHITE);
59
60 // Start drawing with default shader
61
62 DrawText("USING DEFAULT SHADER", 20, 40, 10, RED);
63
64 DrawCircle(80, 120, 35, DARKBLUE);
65 DrawCircleGradient(80, 220, 60, GREEN, SKYBLUE);
66 DrawCircleLines(80, 340, 80, DARKBLUE);
67
68
69 // Activate our custom shader to be applied on next shapes/textures drawings
70 BeginShaderMode(shader);
71
72 DrawText("USING CUSTOM SHADER", 190, 40, 10, RED);
73
74 DrawRectangle(250 - 60, 90, 120, 60, RED);
75 DrawRectangleGradientH(250 - 90, 170, 180, 130, MAROON, GOLD);
76 DrawRectangleLines(250 - 40, 320, 80, 60, ORANGE);
77
78 // Activate our default shader for next drawings
79 EndShaderMode();
80
81 DrawText("USING DEFAULT SHADER", 370, 40, 10, RED);
82
83 DrawTriangle((Vector2){430, 80},
84 (Vector2){430 - 60, 150},
85 (Vector2){430 + 60, 150}, VIOLET);
86
87 DrawTriangleLines((Vector2){430, 160},
88 (Vector2){430 - 20, 230},
89 (Vector2){430 + 20, 230}, DARKBLUE);
90
91 DrawPoly((Vector2){430, 320}, 6, 80, 0, BROWN);
92
93 // Activate our custom shader to be applied on next shapes/textures drawings
94 BeginShaderMode(shader);
95
96 DrawTexture(fudesumi, 500, -30, WHITE); // Using custom shader
97
98 // Activate our default shader for next drawings
99 EndShaderMode();
100
101 DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight - 20, 10, GRAY);
102
103 EndDrawing();
104 //----------------------------------------------------------------------------------
105 }
106
107 // De-Initialization
108 //--------------------------------------------------------------------------------------
109 UnloadShader(shader); // Unload shader
110 UnloadTexture(fudesumi); // Unload texture
111
112 CloseWindow(); // Close window and OpenGL context
113 //--------------------------------------------------------------------------------------
114
115 return 0;
116}