Skip to content

Commit 6966ad5

Browse files
committed
Update shaders_ascii_rendering.c
1 parent 3f30533 commit 6966ad5

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

examples/shaders/shaders_ascii_rendering.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,58 +67,52 @@ int main(void)
6767
// Main game loop
6868
while (!WindowShouldClose()) // Detect window close button or ESC key
6969
{
70-
7170
// Update
7271
//----------------------------------------------------------------------------------
73-
if (IsKeyPressed(KEY_LEFT) && fontSize > 9.0) fontSize -= 1; // Reduce fontSize
74-
75-
if (IsKeyPressed(KEY_RIGHT) && fontSize < 15.0) fontSize += 1; // Increase fontSize
76-
77-
if (circlePos.x > 200.0f || circlePos.x < 40.0f) circleSpeed *= -1; // Revert speed
78-
7972
circlePos.x += circleSpeed;
73+
if ((circlePos.x > 200.0f) || (circlePos.x < 40.0f)) circleSpeed *= -1; // Revert speed
74+
75+
if (IsKeyPressed(KEY_LEFT) && (fontSize > 9.0)) fontSize -= 1; // Reduce fontSize
76+
if (IsKeyPressed(KEY_RIGHT) && (fontSize < 15.0)) fontSize += 1; // Increase fontSize
8077

8178
// Set fontsize for the shader
8279
SetShaderValue(shader, fontSizeLoc, &fontSize, SHADER_UNIFORM_FLOAT);
8380

8481
// Draw
8582
//----------------------------------------------------------------------------------
86-
8783
BeginTextureMode(target);
88-
ClearBackground(WHITE); // The background of the scene itself
84+
ClearBackground(WHITE);
8985

90-
// Samples Using custom shader
86+
// Draw scene in our render texture
9187
DrawTexture(fudesumi, 500, -30, WHITE);
9288
DrawTextureV(raysan, circlePos, WHITE);
93-
9489
EndTextureMode();
90+
9591
BeginDrawing();
96-
9792
ClearBackground(RAYWHITE);
9893

9994
BeginShaderMode(shader);
100-
10195
// Draw the scene texture (that we rendered earlier) to the screen
10296
// The shader will process every pixel of this texture
10397
DrawTextureRec(target.texture,
104-
(Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height },
105-
(Vector2){ 0, 0 },
106-
WHITE);
98+
(Rectangle){ 0, 0, (float)target.texture.width, (float)-target.texture.height },
99+
(Vector2){ 0, 0 }, WHITE);
107100
EndShaderMode();
108101

109102
DrawRectangle(0, 0, screenWidth, 40, BLACK);
110103
DrawText(TextFormat("Ascii effect - FontSize:%2.0f - [Left] -1 [Right] +1 ", fontSize), 120, 10, 20, LIGHTGRAY);
111104
DrawFPS(10, 10);
112-
113105
EndDrawing();
114106
//----------------------------------------------------------------------------------
115107
}
116108

117109
// De-Initialization
118110
//--------------------------------------------------------------------------------------
119-
UnloadShader(shader); // Unload shader
120-
UnloadTexture(fudesumi); // Unload texture
121-
UnloadTexture(raysan); // Unload texture
111+
UnloadRenderTexture(target); // Unload render texture
112+
113+
UnloadShader(shader); // Unload shader
114+
UnloadTexture(fudesumi); // Unload texture
115+
UnloadTexture(raysan); // Unload texture
122116

123117
CloseWindow(); // Close window and OpenGL context
124118
//--------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)