diff --git a/examples/shaders/resources/shaders/glsl100/ascii.fs b/examples/shaders/resources/shaders/glsl100/ascii.fs index 3090c7cc6..d5e154c65 100644 --- a/examples/shaders/resources/shaders/glsl100/ascii.fs +++ b/examples/shaders/resources/shaders/glsl100/ascii.fs @@ -1,6 +1,6 @@ #version 100 -precision highp float; +precision mediump float; // Input from the vertex shader varying vec2 fragTexCoord; diff --git a/examples/shaders/shaders_ascii_effect.c b/examples/shaders/shaders_ascii_effect.c deleted file mode 100644 index b5e5f45e1..000000000 --- a/examples/shaders/shaders_ascii_effect.c +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************************* -* -* raylib [shaders] example - ascii effect -* -* Example complexity rating: [★☆☆☆] 1/4 -* -* Example originally created with raylib 5.5, last time updated with raylib 5.6 -* -* Example contributed by Maicon Santana (@maiconpintoabreu) and reviewed by Ramon Santamaria (@raysan5) -* -* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, -* BSD-like license that allows static linking with closed source software -* -* Copyright (c) 2025-2025 Maicon Santana (@maiconpintoabreu) -* -********************************************************************************************/ - -#include "raylib.h" - -#if defined(PLATFORM_DESKTOP) - #define GLSL_VERSION 330 -#else // PLATFORM_ANDROID, PLATFORM_WEB - #define GLSL_VERSION 100 -#endif - -//------------------------------------------------------------------------------------ -// Program main entry point -//------------------------------------------------------------------------------------ -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - ascii effect"); - - // Texture to test static drawing - Texture2D fudesumi = LoadTexture("resources/fudesumi.png"); - // Texture to test moving drawing - Texture2D raysan = LoadTexture("resources/raysan.png"); - - // Load shader to be used on postprocessing - Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/ascii.fs", GLSL_VERSION)); - - // These locations are used to send data to the GPU. - int resolutionLoc = GetShaderLocation(shader, "resolution"); - int fontSizeLoc = GetShaderLocation(shader, "fontSize"); - - // Set the character size for the ASCII effect - // fontsize should be 9 or more - float fontSize = 9.0f; - - // Send the updated values to the shader - float resolution[2] = { (float)screenWidth, (float)screenHeight }; - SetShaderValue(shader, resolutionLoc, resolution, SHADER_UNIFORM_VEC2); - - Vector2 circlePos = (Vector2){40.0f, (float)screenHeight * 0.5f}; - float circleSpeed = 1.0f; - - // RenderTexture to apply the postprocessing later - RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - - // Update - //---------------------------------------------------------------------------------- - if (IsKeyPressed(KEY_LEFT) && fontSize > 9.0) - { - fontSize -= 1; // Reduce fontSize - } - - if (IsKeyPressed(KEY_RIGHT) && fontSize < 15.0) - { - fontSize += 1; // Increase fontSize - } - - if (circlePos.x > 200.0f || circlePos.x < 40.0f) { - circleSpeed *= -1; - } - - circlePos.x += circleSpeed; - - // Set fontsize for the shader - SetShaderValue(shader, fontSizeLoc, &fontSize, SHADER_UNIFORM_FLOAT); - - // Draw - //---------------------------------------------------------------------------------- - - BeginTextureMode(target); - ClearBackground(WHITE); // The background of the scene itself - - // Samples Using custom shader - DrawTexture(fudesumi, 500, -30, WHITE); - DrawTextureV(raysan, circlePos, WHITE); - - EndTextureMode(); - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginShaderMode(shader); - - // Draw the scene texture (that we rendered earlier) to the screen. - // The shader will process every pixel of this texture. - DrawTextureRec(target.texture, - (Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height }, - (Vector2){ 0, 0 }, - WHITE); - EndShaderMode(); - - DrawRectangle(0, 0, screenWidth, 40, BLACK); - DrawText(TextFormat("Ascii effect - FontSize:%2.0f - [Left] -1 [Right] +1 ", fontSize), 120, 10, 20, LIGHTGRAY); - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadShader(shader); // Unload shader - UnloadTexture(fudesumi); // Unload texture - UnloadTexture(raysan); // Unload texture - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/shaders/shaders_ascii_effect.png b/examples/shaders/shaders_ascii_effect.png deleted file mode 100644 index 59ecc8395..000000000 Binary files a/examples/shaders/shaders_ascii_effect.png and /dev/null differ diff --git a/examples/shaders/shaders_ascii_rendering.c b/examples/shaders/shaders_ascii_rendering.c index 5444caeee..ca7593fa9 100644 --- a/examples/shaders/shaders_ascii_rendering.c +++ b/examples/shaders/shaders_ascii_rendering.c @@ -48,12 +48,12 @@ int main(void) int fontSizeLoc = GetShaderLocation(shader, "fontSize"); // Set the character size for the ASCII effect - float fontSize = 4.0f; + // fontsize should be 9 or more + float fontSize = 9.0f; // Send the updated values to the shader float resolution[2] = { (float)screenWidth, (float)screenHeight }; SetShaderValue(shader, resolutionLoc, resolution, SHADER_UNIFORM_VEC2); - SetShaderValue(shader, fontSizeLoc, &fontSize, SHADER_UNIFORM_FLOAT); Vector2 circlePos = (Vector2){40.0f, (float)screenHeight * 0.5f}; float circleSpeed = 1.0f; @@ -67,37 +67,55 @@ int main(void) // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { + // Update //---------------------------------------------------------------------------------- + if (IsKeyPressed(KEY_LEFT) && fontSize > 9.0) + { + fontSize -= 1; // Reduce fontSize + } + + if (IsKeyPressed(KEY_RIGHT) && fontSize < 15.0) + { + fontSize += 1; // Increase fontSize + } + + if (circlePos.x > 200.0f || circlePos.x < 40.0f) { + circleSpeed *= -1; + } + circlePos.x += circleSpeed; - - if ((circlePos.x > 200.0f) || (circlePos.x < 40.0f)) circleSpeed *= -1; - //---------------------------------------------------------------------------------- + + // Set fontsize for the shader + SetShaderValue(shader, fontSizeLoc, &fontSize, SHADER_UNIFORM_FLOAT); // Draw //---------------------------------------------------------------------------------- - // Draw our scene to a render texture first + BeginTextureMode(target); - ClearBackground(WHITE); - + ClearBackground(WHITE); // The background of the scene itself + + // Samples Using custom shader DrawTexture(fudesumi, 500, -30, WHITE); DrawTextureV(raysan, circlePos, WHITE); - + EndTextureMode(); - BeginDrawing(); + ClearBackground(RAYWHITE); BeginShaderMode(shader); - // Draw the render texture containing scene - // The shader will process every pixel on the screen - DrawTextureRec(target.texture, - (Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height }, - (Vector2){ 0, 0 }, WHITE); + + // Draw the scene texture (that we rendered earlier) to the screen. + // The shader will process every pixel of this texture. + DrawTextureRec(target.texture, + (Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height }, + (Vector2){ 0, 0 }, + WHITE); EndShaderMode(); DrawRectangle(0, 0, screenWidth, 40, BLACK); - DrawText("Ascii effect", 120, 10, 20, LIGHTGRAY); + DrawText(TextFormat("Ascii effect - FontSize:%2.0f - [Left] -1 [Right] +1 ", fontSize), 120, 10, 20, LIGHTGRAY); DrawFPS(10, 10); EndDrawing(); diff --git a/examples/shaders/shaders_ascii_rendering.png b/examples/shaders/shaders_ascii_rendering.png index eee5cc90b..59ecc8395 100644 Binary files a/examples/shaders/shaders_ascii_rendering.png and b/examples/shaders/shaders_ascii_rendering.png differ