More defer

This commit is contained in:
Not-Nik 2023-07-20 16:23:41 +02:00
parent 183cc437ac
commit f50189fdd0
Failed to generate hash of commit
12 changed files with 21 additions and 64 deletions

View file

@ -12,6 +12,7 @@ pub fn main() anyerror!void {
const screenHeight = 450;
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - 2d camera");
defer rl.closeWindow(); // Close window and OpenGL context
var player = rl.Rectangle{ .x = 400, .y = 280, .width = 40, .height = 40 };
var buildings: [MAX_BUILDINGS]rl.Rectangle = undefined;
@ -117,9 +118,4 @@ pub fn main() anyerror!void {
rl.endDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
rl.closeWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View file

@ -11,6 +11,7 @@ pub fn main() anyerror!void {
const screenHeight = 450;
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - 3d camera first person");
defer rl.closeWindow(); // Close window and OpenGL context
var camera = rl.Camera3D{
.position = rl.Vector3.init(4, 2, 4),
@ -74,9 +75,4 @@ pub fn main() anyerror!void {
rl.endDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
rl.closeWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View file

@ -9,6 +9,7 @@ pub fn main() anyerror!void {
const screenHeight = 450;
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
defer rl.closeWindow(); // Close window and OpenGL context
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -31,9 +32,4 @@ pub fn main() anyerror!void {
rl.endDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
rl.closeWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View file

@ -9,6 +9,7 @@ pub fn main() anyerror!void {
const screenHeight = 450;
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - keyboard input");
defer rl.closeWindow(); // Close window and OpenGL context
var ballPosition = rl.Vector2.init(screenWidth / 2, screenHeight / 2);
@ -47,9 +48,4 @@ pub fn main() anyerror!void {
rl.endDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
rl.closeWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View file

@ -9,6 +9,7 @@ pub fn main() anyerror!void {
const screenHeight = 450;
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - mouse input");
defer rl.closeWindow(); // Close window and OpenGL context
var ballPosition = rl.Vector2.init(-100, -100);
var ballColor = rl.Color.dark_blue;
@ -46,9 +47,4 @@ pub fn main() anyerror!void {
rl.endDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
rl.closeWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View file

@ -10,6 +10,7 @@ pub fn main() anyerror!void {
const screenHeight = 450;
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
defer rl.closeWindow(); // Close window and OpenGL context
var boxPositionY: f32 = screenHeight / 2 - 40;
var scrollSpeed: f32 = 4; // Scrolling speed in pixels
@ -39,9 +40,4 @@ pub fn main() anyerror!void {
rl.endDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
rl.closeWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View file

@ -9,6 +9,7 @@ pub fn main() anyerror!void {
const screenHeight = 450;
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
defer rl.closeWindow(); // Close window and OpenGL context
var ballPosition = rl.Vector2.init(-100, -100);
var ballColor = rl.Color.beige;
@ -80,9 +81,4 @@ pub fn main() anyerror!void {
rl.endDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
rl.closeWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View file

@ -13,10 +13,13 @@ pub fn main() anyerror!void {
const screenHeight = 450;
rl.initWindow(screenWidth, screenHeight, "raylib [shaders] example - Apply an outline to a texture");
defer rl.closeWindow(); // Close window and OpenGL context
const texture: rl.Texture = rl.Texture.init("resources/textures/fudesumi.png");
defer rl.unloadTexture(texture);
const shdrOutline: rl.Shader = rl.loadShader(null, "resources/shaders/glsl330/outline.fs");
defer rl.unloadShader(shdrOutline);
var outlineSize: f32 = 2.0;
const outlineColor = [4]f32{ 1.0, 0.0, 0.0, 1.0 }; // Normalized RED color
@ -66,13 +69,4 @@ pub fn main() anyerror!void {
rl.endDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
rl.unloadTexture(texture);
rl.unloadShader(shdrOutline);
rl.closeWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

View file

@ -14,9 +14,11 @@ pub fn main() anyerror!void {
rl.initAudioDevice(); // Initialize audio device
rl.initWindow(screenWidth, screenHeight, "raylib [texture] example - sprite anim");
defer rl.closeWindow(); // Close window and OpenGL context
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
const scarfy: rl.Texture = rl.Texture.init("resources/textures/scarfy.png"); // Texture loading
defer rl.unloadTexture(scarfy); // Texture unloading
const position = rl.Vector2.init(350.0, 280.0);
var frameRec = rl.Rectangle.init(0, 0, @intToFloat(f32, @divFloor(scarfy.width, 6)), @intToFloat(f32, scarfy.height));
@ -86,11 +88,4 @@ pub fn main() anyerror!void {
rl.endDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
rl.unloadTexture(scarfy); // Texture unloading
rl.closeWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}