2019-05-16 18:23:31 +03:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
|
|
|
* raylib [shaders] example - Sieve of Eratosthenes
|
|
|
|
*
|
2022-07-20 02:28:37 +03:00
|
|
|
* NOTE: Sieve of Eratosthenes, the earliest known (ancient Greek) prime number sieve.
|
2019-05-16 18:23:31 +03:00
|
|
|
*
|
2022-07-20 02:28:37 +03:00
|
|
|
* "Sift the twos and sift the threes,
|
|
|
|
* The Sieve of Eratosthenes.
|
|
|
|
* When the multiples sublime,
|
|
|
|
* the numbers that are left are prime."
|
2019-05-16 18:23:31 +03:00
|
|
|
*
|
|
|
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
|
|
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
|
|
|
*
|
|
|
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3).
|
|
|
|
*
|
2022-07-20 02:28:37 +03:00
|
|
|
* Example originally created with raylib 2.5, last time updated with raylib 4.0
|
2019-05-16 18:23:31 +03:00
|
|
|
*
|
|
|
|
* Example contributed by ProfJski and reviewed by Ramon Santamaria (@raysan5)
|
|
|
|
*
|
2022-07-20 02:28:37 +03:00
|
|
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
|
|
* BSD-like license that allows static linking with closed source software
|
|
|
|
*
|
2023-01-01 18:00:56 +03:00
|
|
|
* Copyright (c) 2019-2023 ProfJski and Ramon Santamaria (@raysan5)
|
2019-05-16 18:23:31 +03:00
|
|
|
*
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
|
|
|
|
#if defined(PLATFORM_DESKTOP)
|
|
|
|
#define GLSL_VERSION 330
|
2023-09-07 18:42:28 +03:00
|
|
|
#else // PLATFORM_ANDROID, PLATFORM_WEB
|
2019-05-16 18:23:31 +03:00
|
|
|
#define GLSL_VERSION 100
|
|
|
|
#endif
|
|
|
|
|
2022-06-21 20:53:18 +03:00
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Program main entry point
|
|
|
|
//------------------------------------------------------------------------------------
|
2019-05-20 17:36:42 +03:00
|
|
|
int main(void)
|
2019-05-16 18:23:31 +03:00
|
|
|
{
|
|
|
|
// Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
const int screenWidth = 800;
|
|
|
|
const int screenHeight = 450;
|
|
|
|
|
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Sieve of Eratosthenes");
|
|
|
|
|
|
|
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
2021-04-22 19:55:24 +03:00
|
|
|
|
2019-05-16 18:23:31 +03:00
|
|
|
// Load Eratosthenes shader
|
|
|
|
// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
|
2020-08-16 12:28:15 +03:00
|
|
|
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/eratosthenes.fs", GLSL_VERSION));
|
2019-05-16 18:23:31 +03:00
|
|
|
|
2021-06-23 02:25:09 +03:00
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
2019-05-16 18:23:31 +03:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Main game loop
|
2021-06-23 02:25:09 +03:00
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
2019-05-16 18:23:31 +03:00
|
|
|
{
|
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Nothing to do here, everything is happening in the shader
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
2021-06-23 02:25:09 +03:00
|
|
|
BeginTextureMode(target); // Enable drawing to texture
|
|
|
|
ClearBackground(BLACK); // Clear the render texture
|
2019-05-16 18:23:31 +03:00
|
|
|
|
2021-06-23 02:25:09 +03:00
|
|
|
// Draw a rectangle in shader mode to be used as shader canvas
|
|
|
|
// NOTE: Rectangle uses font white character texture coordinates,
|
|
|
|
// so shader can not be applied here directly because input vertexTexCoord
|
|
|
|
// do not represent full screen coordinates (space where want to apply shader)
|
|
|
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
|
|
|
|
EndTextureMode(); // End drawing to texture (now we have a blank texture available for the shader)
|
2019-05-16 18:23:31 +03:00
|
|
|
|
2021-06-23 02:25:09 +03:00
|
|
|
BeginDrawing();
|
|
|
|
ClearBackground(RAYWHITE); // Clear screen background
|
2019-05-16 18:23:31 +03:00
|
|
|
|
|
|
|
BeginShaderMode(shader);
|
|
|
|
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
2021-04-25 19:50:26 +03:00
|
|
|
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height }, (Vector2){ 0.0f, 0.0f }, WHITE);
|
2019-05-16 18:23:31 +03:00
|
|
|
EndShaderMode();
|
|
|
|
EndDrawing();
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
|
|
|
|
// De-Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
2021-06-23 02:25:09 +03:00
|
|
|
UnloadShader(shader); // Unload shader
|
|
|
|
UnloadRenderTexture(target); // Unload render texture
|
2019-05-16 18:23:31 +03:00
|
|
|
|
2021-06-23 02:25:09 +03:00
|
|
|
CloseWindow(); // Close window and OpenGL context
|
2019-05-16 18:23:31 +03:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|