Defer begin/end in examples

This commit is contained in:
Not-Nik 2023-07-20 16:39:06 +02:00
parent e13c5bf521
commit 286324cf03
No known key found for this signature in database
GPG Key ID: 08BB71E672DB3BFD
10 changed files with 40 additions and 45 deletions

View File

@ -37,12 +37,11 @@ pub fn main() anyerror!void {
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rl.beginDrawing(); rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.white); rl.clearBackground(rl.Color.white);
rl.drawText("Congrats! You created your first window!", 190, 200, 20, rl.Color.light_gray); rl.drawText("Congrats! You created your first window!", 190, 200, 20, rl.Color.light_gray);
rl.endDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
} }

View File

@ -81,10 +81,13 @@ pub fn main() anyerror!void {
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rl.beginDrawing(); rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.ray_white); rl.clearBackground(rl.Color.ray_white);
{
camera.begin(); camera.begin();
defer camera.end();
rl.drawRectangle(-6000, 320, 13000, 8000, rl.Color.dark_gray); rl.drawRectangle(-6000, 320, 13000, 8000, rl.Color.dark_gray);
@ -96,8 +99,7 @@ pub fn main() anyerror!void {
rl.drawLine(@floatToInt(i32, camera.target.x), -screenHeight * 10, @floatToInt(i32, camera.target.x), screenHeight * 10, rl.Color.green); rl.drawLine(@floatToInt(i32, camera.target.x), -screenHeight * 10, @floatToInt(i32, camera.target.x), screenHeight * 10, rl.Color.green);
rl.drawLine(-screenWidth * 10, @floatToInt(i32, camera.target.y), screenWidth * 10, @floatToInt(i32, camera.target.y), rl.Color.green); rl.drawLine(-screenWidth * 10, @floatToInt(i32, camera.target.y), screenWidth * 10, @floatToInt(i32, camera.target.y), rl.Color.green);
}
camera.end();
rl.drawText("SCREEN AREA", 640, 10, 20, rl.Color.red); rl.drawText("SCREEN AREA", 640, 10, 20, rl.Color.red);
@ -114,8 +116,6 @@ pub fn main() anyerror!void {
rl.drawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, rl.Color.dark_gray); rl.drawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, rl.Color.dark_gray);
rl.drawText("- A / S to Rotate", 40, 80, 10, rl.Color.dark_gray); rl.drawText("- A / S to Rotate", 40, 80, 10, rl.Color.dark_gray);
rl.drawText("- R to reset Zoom and Rotation", 40, 100, 10, rl.Color.dark_gray); rl.drawText("- R to reset Zoom and Rotation", 40, 100, 10, rl.Color.dark_gray);
rl.endDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
} }

View File

@ -46,10 +46,13 @@ pub fn main() anyerror!void {
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rl.beginDrawing(); rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.ray_white); rl.clearBackground(rl.Color.ray_white);
{
camera.begin(); camera.begin();
defer camera.end();
// Draw ground // Draw ground
rl.drawPlane(rl.Vector3.init(0, 0, 0), rl.Vector2.init(32, 32), rl.Color.light_gray); rl.drawPlane(rl.Vector3.init(0, 0, 0), rl.Vector2.init(32, 32), rl.Color.light_gray);
@ -62,8 +65,7 @@ pub fn main() anyerror!void {
rl.drawCube(positions[i], 2.0, height, 2.0, colors[i]); rl.drawCube(positions[i], 2.0, height, 2.0, colors[i]);
rl.drawCubeWires(positions[i], 2.0, height, 2.0, rl.Color.maroon); rl.drawCubeWires(positions[i], 2.0, height, 2.0, rl.Color.maroon);
} }
}
camera.end();
rl.drawRectangle(10, 10, 220, 70, rl.Color.sky_blue.fade(0.5)); rl.drawRectangle(10, 10, 220, 70, rl.Color.sky_blue.fade(0.5));
rl.drawRectangleLines(10, 10, 220, 70, rl.Color.blue); rl.drawRectangleLines(10, 10, 220, 70, rl.Color.blue);

View File

@ -24,12 +24,11 @@ pub fn main() anyerror!void {
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rl.beginDrawing(); rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.white); rl.clearBackground(rl.Color.white);
rl.drawText("Congrats! You created your first window!", 190, 200, 20, rl.Color.light_gray); rl.drawText("Congrats! You created your first window!", 190, 200, 20, rl.Color.light_gray);
rl.endDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
} }

View File

@ -38,14 +38,13 @@ pub fn main() anyerror!void {
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rl.beginDrawing(); rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.ray_white); rl.clearBackground(rl.Color.ray_white);
rl.drawText("move the ball with arrow keys", 10, 10, 20, rl.Color.dark_gray); rl.drawText("move the ball with arrow keys", 10, 10, 20, rl.Color.dark_gray);
rl.drawCircleV(ballPosition, 50, rl.Color.maroon); rl.drawCircleV(ballPosition, 50, rl.Color.maroon);
rl.endDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
} }

View File

@ -37,14 +37,13 @@ pub fn main() anyerror!void {
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rl.beginDrawing(); rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.ray_white); rl.clearBackground(rl.Color.ray_white);
rl.drawCircleV(ballPosition, 40, ballColor); rl.drawCircleV(ballPosition, 40, ballColor);
rl.drawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.Color.dark_gray); rl.drawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.Color.dark_gray);
rl.endDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
} }

View File

@ -28,6 +28,7 @@ pub fn main() anyerror!void {
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rl.beginDrawing(); rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.white); rl.clearBackground(rl.Color.white);
@ -36,8 +37,6 @@ pub fn main() anyerror!void {
rl.drawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, rl.Color.gray); rl.drawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, rl.Color.gray);
rl.drawText(rl.textFormat("Box position Y: %03i", .{@floatToInt(c_int, boxPositionY)}), 10, 40, 20, rl.Color.light_gray); rl.drawText(rl.textFormat("Box position Y: %03i", .{@floatToInt(c_int, boxPositionY)}), 10, 40, 20, rl.Color.light_gray);
rl.endDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
} }

View File

@ -56,6 +56,7 @@ pub fn main() anyerror!void {
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rl.beginDrawing(); rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.ray_white); rl.clearBackground(rl.Color.ray_white);
@ -77,8 +78,6 @@ pub fn main() anyerror!void {
rl.drawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.Color.dark_gray); rl.drawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.Color.dark_gray);
rl.drawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, rl.Color.dark_gray); rl.drawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, rl.Color.dark_gray);
rl.endDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
} }

View File

@ -51,22 +51,22 @@ pub fn main() anyerror!void {
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rl.beginDrawing(); rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.ray_white); rl.clearBackground(rl.Color.ray_white);
{
rl.beginShaderMode(shdrOutline); rl.beginShaderMode(shdrOutline);
defer rl.endShaderMode();
texture.draw(@divFloor(rl.getScreenWidth(), 2) - @divFloor(texture.width, 2), -30, rl.Color.white); texture.draw(@divFloor(rl.getScreenWidth(), 2) - @divFloor(texture.width, 2), -30, rl.Color.white);
}
rl.endShaderMode();
rl.drawText("Shader-based\ntexture\noutline", 10, 10, 20, rl.Color.gray); rl.drawText("Shader-based\ntexture\noutline", 10, 10, 20, rl.Color.gray);
rl.drawText(rl.textFormat("Outline size: %i px", .{@floatToInt(i32, outlineSize)}), 10, 120, 20, rl.Color.maroon); rl.drawText(rl.textFormat("Outline size: %i px", .{@floatToInt(i32, outlineSize)}), 10, 120, 20, rl.Color.maroon);
rl.drawFPS(710, 10); rl.drawFPS(710, 10);
rl.endDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
} }

View File

@ -63,6 +63,7 @@ pub fn main() anyerror!void {
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
rl.beginDrawing(); rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.ray_white); rl.clearBackground(rl.Color.ray_white);
@ -84,8 +85,6 @@ pub fn main() anyerror!void {
scarfy.drawRec(frameRec, position, rl.Color.white); // Draw part of the texture scarfy.drawRec(frameRec, position, rl.Color.white); // Draw part of the texture
rl.drawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, rl.Color.gray); rl.drawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, rl.Color.gray);
rl.endDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
} }
} }