1 | /******************************************************************************************* |
2 | * |
3 | * raylib [shaders] example - Sieve of Eratosthenes |
4 | * |
5 | * Sieve of Eratosthenes, the earliest known (ancient Greek) prime number sieve. |
6 | * |
7 | * "Sift the twos and sift the threes, |
8 | * The Sieve of Eratosthenes. |
9 | * When the multiples sublime, |
10 | * the numbers that are left are prime." |
11 | * |
12 | * NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, |
13 | * OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. |
14 | * |
15 | * NOTE: Shaders used in this example are #version 330 (OpenGL 3.3). |
16 | * |
17 | * This example has been created using raylib 2.5 (www.raylib.com) |
18 | * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) |
19 | * |
20 | * Example contributed by ProfJski and reviewed by Ramon Santamaria (@raysan5) |
21 | * |
22 | * Copyright (c) 2019 ProfJski and Ramon Santamaria (@raysan5) |
23 | * |
24 | ********************************************************************************************/ |
25 | |
26 | #include "raylib.h" |
27 | |
28 | #if defined(PLATFORM_DESKTOP) |
29 | #define GLSL_VERSION 330 |
30 | #else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB |
31 | #define GLSL_VERSION 100 |
32 | #endif |
33 | |
34 | int main(void) |
35 | { |
36 | // Initialization |
37 | //-------------------------------------------------------------------------------------- |
38 | const int screenWidth = 800; |
39 | const int screenHeight = 450; |
40 | |
41 | InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Sieve of Eratosthenes" ); |
42 | |
43 | RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); |
44 | |
45 | // Load Eratosthenes shader |
46 | // NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader |
47 | Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/eratosthenes.fs" , GLSL_VERSION)); |
48 | |
49 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
50 | //-------------------------------------------------------------------------------------- |
51 | |
52 | // Main game loop |
53 | while (!WindowShouldClose()) // Detect window close button or ESC key |
54 | { |
55 | // Update |
56 | //---------------------------------------------------------------------------------- |
57 | // Nothing to do here, everything is happening in the shader |
58 | //---------------------------------------------------------------------------------- |
59 | |
60 | // Draw |
61 | //---------------------------------------------------------------------------------- |
62 | BeginDrawing(); |
63 | |
64 | ClearBackground(RAYWHITE); |
65 | |
66 | BeginTextureMode(target); // Enable drawing to texture |
67 | ClearBackground(BLACK); // Clear the render texture |
68 | |
69 | // Draw a rectangle in shader mode to be used as shader canvas |
70 | // NOTE: Rectangle uses font white character texture coordinates, |
71 | // so shader can not be applied here directly because input vertexTexCoord |
72 | // do not represent full screen coordinates (space where want to apply shader) |
73 | DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK); |
74 | EndTextureMode(); // End drawing to texture (now we have a blank texture available for the shader) |
75 | |
76 | BeginShaderMode(shader); |
77 | // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) |
78 | DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0.0f, 0.0f }, WHITE); |
79 | EndShaderMode(); |
80 | |
81 | EndDrawing(); |
82 | //---------------------------------------------------------------------------------- |
83 | } |
84 | |
85 | // De-Initialization |
86 | //-------------------------------------------------------------------------------------- |
87 | UnloadShader(shader); // Unload shader |
88 | UnloadRenderTexture(target); // Unload texture |
89 | |
90 | CloseWindow(); // Close window and OpenGL context |
91 | //-------------------------------------------------------------------------------------- |
92 | |
93 | return 0; |
94 | } |
95 | |