From 286324cf0316cbc6046ae7f3a78cb68c3fd5b8d6 Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Thu, 20 Jul 2023 16:39:06 +0200 Subject: [PATCH] Defer begin/end in examples --- README.md | 3 +-- examples/core/2d_camera.zig | 26 ++++++++++++------------ examples/core/3d_camera_first_person.zig | 26 +++++++++++++----------- examples/core/basic_window.zig | 3 +-- examples/core/input_keys.zig | 3 +-- examples/core/input_mouse.zig | 3 +-- examples/core/input_mouse_wheel.zig | 3 +-- examples/core/input_multitouch.zig | 3 +-- examples/shaders/texture_outline.zig | 12 +++++------ examples/textures/sprite_anim.zig | 3 +-- 10 files changed, 40 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index d30d182..ab713ce 100755 --- a/README.md +++ b/README.md @@ -37,12 +37,11 @@ pub fn main() anyerror!void { // Draw //---------------------------------------------------------------------------------- rl.beginDrawing(); + defer rl.endDrawing(); rl.clearBackground(rl.Color.white); rl.drawText("Congrats! You created your first window!", 190, 200, 20, rl.Color.light_gray); - - rl.endDrawing(); //---------------------------------------------------------------------------------- } } diff --git a/examples/core/2d_camera.zig b/examples/core/2d_camera.zig index 6da95d5..daaeb72 100755 --- a/examples/core/2d_camera.zig +++ b/examples/core/2d_camera.zig @@ -81,24 +81,26 @@ pub fn main() anyerror!void { // Draw //---------------------------------------------------------------------------------- rl.beginDrawing(); + defer rl.endDrawing(); 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); - for (buildings) |building, i| { - rl.drawRectangleRec(building, buildColors[i]); + for (buildings) |building, i| { + rl.drawRectangleRec(building, buildColors[i]); + } + + rl.drawRectangleRec(player, rl.Color.red); + + 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.drawRectangleRec(player, rl.Color.red); - - 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); - - camera.end(); - rl.drawText("SCREEN AREA", 640, 10, 20, rl.Color.red); rl.drawRectangle(0, 0, screenWidth, 5, 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("- 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.endDrawing(); //---------------------------------------------------------------------------------- } } diff --git a/examples/core/3d_camera_first_person.zig b/examples/core/3d_camera_first_person.zig index 5d732fc..3f41878 100644 --- a/examples/core/3d_camera_first_person.zig +++ b/examples/core/3d_camera_first_person.zig @@ -46,25 +46,27 @@ pub fn main() anyerror!void { // Draw //---------------------------------------------------------------------------------- rl.beginDrawing(); + defer rl.endDrawing(); rl.clearBackground(rl.Color.ray_white); - camera.begin(); + { + camera.begin(); + defer camera.end(); - // Draw ground - rl.drawPlane(rl.Vector3.init(0, 0, 0), rl.Vector2.init(32, 32), rl.Color.light_gray); - rl.drawCube(rl.Vector3.init(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Color.blue); // Draw a blue wall - rl.drawCube(rl.Vector3.init(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Color.lime); // Draw a green wall - rl.drawCube(rl.Vector3.init(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, rl.Color.gold); // Draw a yellow wall + // Draw ground + rl.drawPlane(rl.Vector3.init(0, 0, 0), rl.Vector2.init(32, 32), rl.Color.light_gray); + rl.drawCube(rl.Vector3.init(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Color.blue); // Draw a blue wall + rl.drawCube(rl.Vector3.init(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Color.lime); // Draw a green wall + rl.drawCube(rl.Vector3.init(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, rl.Color.gold); // Draw a yellow wall - // Draw some cubes around - for (heights) |height, i| { - rl.drawCube(positions[i], 2.0, height, 2.0, colors[i]); - rl.drawCubeWires(positions[i], 2.0, height, 2.0, rl.Color.maroon); + // Draw some cubes around + for (heights) |height, i| { + rl.drawCube(positions[i], 2.0, height, 2.0, colors[i]); + 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.drawRectangleLines(10, 10, 220, 70, rl.Color.blue); diff --git a/examples/core/basic_window.zig b/examples/core/basic_window.zig index b5f64b4..b2529e9 100755 --- a/examples/core/basic_window.zig +++ b/examples/core/basic_window.zig @@ -24,12 +24,11 @@ pub fn main() anyerror!void { // Draw //---------------------------------------------------------------------------------- rl.beginDrawing(); + defer rl.endDrawing(); rl.clearBackground(rl.Color.white); rl.drawText("Congrats! You created your first window!", 190, 200, 20, rl.Color.light_gray); - - rl.endDrawing(); //---------------------------------------------------------------------------------- } } diff --git a/examples/core/input_keys.zig b/examples/core/input_keys.zig index 82dd17f..17657bf 100755 --- a/examples/core/input_keys.zig +++ b/examples/core/input_keys.zig @@ -38,14 +38,13 @@ pub fn main() anyerror!void { // Draw //---------------------------------------------------------------------------------- rl.beginDrawing(); + defer rl.endDrawing(); rl.clearBackground(rl.Color.ray_white); rl.drawText("move the ball with arrow keys", 10, 10, 20, rl.Color.dark_gray); rl.drawCircleV(ballPosition, 50, rl.Color.maroon); - - rl.endDrawing(); //---------------------------------------------------------------------------------- } } diff --git a/examples/core/input_mouse.zig b/examples/core/input_mouse.zig index aead21b..fadd00e 100755 --- a/examples/core/input_mouse.zig +++ b/examples/core/input_mouse.zig @@ -37,14 +37,13 @@ pub fn main() anyerror!void { // Draw //---------------------------------------------------------------------------------- rl.beginDrawing(); + defer rl.endDrawing(); rl.clearBackground(rl.Color.ray_white); 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.endDrawing(); //---------------------------------------------------------------------------------- } } diff --git a/examples/core/input_mouse_wheel.zig b/examples/core/input_mouse_wheel.zig index 6613221..3aa9f69 100755 --- a/examples/core/input_mouse_wheel.zig +++ b/examples/core/input_mouse_wheel.zig @@ -28,6 +28,7 @@ pub fn main() anyerror!void { // Draw //---------------------------------------------------------------------------------- rl.beginDrawing(); + defer rl.endDrawing(); 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(rl.textFormat("Box position Y: %03i", .{@floatToInt(c_int, boxPositionY)}), 10, 40, 20, rl.Color.light_gray); - - rl.endDrawing(); //---------------------------------------------------------------------------------- } } diff --git a/examples/core/input_multitouch.zig b/examples/core/input_multitouch.zig index 0feb30f..1ba0f7a 100755 --- a/examples/core/input_multitouch.zig +++ b/examples/core/input_multitouch.zig @@ -56,6 +56,7 @@ pub fn main() anyerror!void { // Draw //---------------------------------------------------------------------------------- rl.beginDrawing(); + defer rl.endDrawing(); 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("touch the screen at multiple locations to get multiple balls", 10, 30, 20, rl.Color.dark_gray); - - rl.endDrawing(); //---------------------------------------------------------------------------------- } } diff --git a/examples/shaders/texture_outline.zig b/examples/shaders/texture_outline.zig index 413eeb6..18ad9a8 100644 --- a/examples/shaders/texture_outline.zig +++ b/examples/shaders/texture_outline.zig @@ -51,22 +51,22 @@ pub fn main() anyerror!void { // Draw //---------------------------------------------------------------------------------- rl.beginDrawing(); + defer rl.endDrawing(); 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); - - rl.endShaderMode(); + texture.draw(@divFloor(rl.getScreenWidth(), 2) - @divFloor(texture.width, 2), -30, rl.Color.white); + } 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.drawFPS(710, 10); - - rl.endDrawing(); //---------------------------------------------------------------------------------- } } diff --git a/examples/textures/sprite_anim.zig b/examples/textures/sprite_anim.zig index 29a4744..ea7bcf3 100644 --- a/examples/textures/sprite_anim.zig +++ b/examples/textures/sprite_anim.zig @@ -63,6 +63,7 @@ pub fn main() anyerror!void { // Draw //---------------------------------------------------------------------------------- rl.beginDrawing(); + defer rl.endDrawing(); 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 rl.drawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, rl.Color.gray); - - rl.endDrawing(); //---------------------------------------------------------------------------------- } }