Browse Source

Update shaders_ascii_rendering.c

pull/5220/head
Ray 2 months ago
parent
commit
6966ad5717
1 changed files with 14 additions and 20 deletions
  1. +14
    -20
      examples/shaders/shaders_ascii_rendering.c

+ 14
- 20
examples/shaders/shaders_ascii_rendering.c View File

@ -67,58 +67,52 @@ int main(void)
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // 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; // Revert speed
circlePos.x += circleSpeed; circlePos.x += circleSpeed;
if ((circlePos.x > 200.0f) || (circlePos.x < 40.0f)) circleSpeed *= -1; // Revert speed
if (IsKeyPressed(KEY_LEFT) && (fontSize > 9.0)) fontSize -= 1; // Reduce fontSize
if (IsKeyPressed(KEY_RIGHT) && (fontSize < 15.0)) fontSize += 1; // Increase fontSize
// Set fontsize for the shader // Set fontsize for the shader
SetShaderValue(shader, fontSizeLoc, &fontSize, SHADER_UNIFORM_FLOAT); SetShaderValue(shader, fontSizeLoc, &fontSize, SHADER_UNIFORM_FLOAT);
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginTextureMode(target); BeginTextureMode(target);
ClearBackground(WHITE); // The background of the scene itself
ClearBackground(WHITE);
// Samples Using custom shader
// Draw scene in our render texture
DrawTexture(fudesumi, 500, -30, WHITE); DrawTexture(fudesumi, 500, -30, WHITE);
DrawTextureV(raysan, circlePos, WHITE); DrawTextureV(raysan, circlePos, WHITE);
EndTextureMode(); EndTextureMode();
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginShaderMode(shader); BeginShaderMode(shader);
// Draw the scene texture (that we rendered earlier) to the screen // Draw the scene texture (that we rendered earlier) to the screen
// The shader will process every pixel of this texture // The shader will process every pixel of this texture
DrawTextureRec(target.texture, DrawTextureRec(target.texture,
(Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height },
(Vector2){ 0, 0 },
WHITE);
(Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height },
(Vector2){ 0, 0 }, WHITE);
EndShaderMode(); EndShaderMode();
DrawRectangle(0, 0, screenWidth, 40, BLACK); DrawRectangle(0, 0, screenWidth, 40, BLACK);
DrawText(TextFormat("Ascii effect - FontSize:%2.0f - [Left] -1 [Right] +1 ", fontSize), 120, 10, 20, LIGHTGRAY); DrawText(TextFormat("Ascii effect - FontSize:%2.0f - [Left] -1 [Right] +1 ", fontSize), 120, 10, 20, LIGHTGRAY);
DrawFPS(10, 10); DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadShader(shader); // Unload shader
UnloadTexture(fudesumi); // Unload texture
UnloadTexture(raysan); // Unload texture
UnloadRenderTexture(target); // Unload render texture
UnloadShader(shader); // Unload shader
UnloadTexture(fudesumi); // Unload texture
UnloadTexture(raysan); // Unload texture
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

Loading…
Cancel
Save