mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 12:07:27 +00:00
Defer begin/end in examples
This commit is contained in:
parent
e13c5bf521
commit
286324cf03
@ -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();
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,24 +81,26 @@ 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);
|
||||||
|
|
||||||
for (buildings) |building, i| {
|
for (buildings) |building, i| {
|
||||||
rl.drawRectangleRec(building, buildColors[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.drawText("SCREEN AREA", 640, 10, 20, rl.Color.red);
|
||||||
|
|
||||||
rl.drawRectangle(0, 0, screenWidth, 5, 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("- 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();
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,25 +46,27 @@ 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);
|
||||||
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.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(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
|
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
|
// Draw some cubes around
|
||||||
for (heights) |height, i| {
|
for (heights) |height, i| {
|
||||||
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);
|
||||||
|
|
||||||
|
@ -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();
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user