Add basic raylib functionality: open window
This commit is contained in:
parent
821162015a
commit
914e1127db
|
@ -18,6 +18,9 @@ pub fn build(b: *std.Build) void {
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
exe.linkSystemLibrary("raylib");
|
||||||
|
exe.linkSystemLibrary("c");
|
||||||
|
|
||||||
b.installArtifact(exe);
|
b.installArtifact(exe);
|
||||||
|
|
||||||
const run_cmd = b.addRunArtifact(exe);
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
|
|
|
@ -3,10 +3,10 @@ const std = @import("std");
|
||||||
//const zlm = @import("zlm");
|
//const zlm = @import("zlm");
|
||||||
//const gl = @import("zgl");
|
//const gl = @import("zgl");
|
||||||
//const m = zlm.SpecializeOn(f32);
|
//const m = zlm.SpecializeOn(f32);
|
||||||
|
const rl = @import("raylib.zig");
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
//window: sdl.Window,
|
|
||||||
color: [4]f32 = .{ 0, 0, 0, 0 },
|
color: [4]f32 = .{ 0, 0, 0, 0 },
|
||||||
|
|
||||||
// There's a vbo for each shader program
|
// There's a vbo for each shader program
|
||||||
|
@ -20,9 +20,9 @@ const max_objects: usize = 16384;
|
||||||
const quadSize: usize = 9 * 6;
|
const quadSize: usize = 9 * 6;
|
||||||
|
|
||||||
pub fn init() !Self {
|
pub fn init() !Self {
|
||||||
var renderer = Self{
|
rl.initWindow(640, 480, "USG", 60);
|
||||||
//.window = window,
|
|
||||||
};
|
var renderer = Self{};
|
||||||
|
|
||||||
return renderer;
|
return renderer;
|
||||||
}
|
}
|
||||||
|
@ -30,23 +30,10 @@ pub fn init() !Self {
|
||||||
pub fn render(self: *Self) void {
|
pub fn render(self: *Self) void {
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
||||||
//// TODO: Submit with SubData instead to not pass the whole buffer
|
rl.endDrawing();
|
||||||
//self.buffer.data(f32, &self.vbo, .static_draw);
|
rl.beginDrawing();
|
||||||
|
|
||||||
//var i: usize = 0;
|
rl.clearBackground(232, 216, 166, 255);
|
||||||
//const amount = self.vbo_index / quadSize;
|
|
||||||
//while (i < amount) : (i += 1) {
|
|
||||||
// gl.bindTexture(self.textures[i].texture, .@"2d");
|
|
||||||
// gl.drawArrays(.triangles, i * 6, 6);
|
|
||||||
//}
|
|
||||||
//self.vbo_index = 0;
|
|
||||||
|
|
||||||
//// Clear the vbo, this really shouldn't be necessary as the index is set to zero,
|
|
||||||
//// but otherwise it leads to bugs
|
|
||||||
//self.vbo = .{0.0} ** max_objects;
|
|
||||||
|
|
||||||
//sdl.gl.swapWindow(self.window);
|
|
||||||
//gl.clear(.{ .color = true });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(self: *Self) void {
|
||||||
|
|
26
src/main.zig
26
src/main.zig
|
@ -1,5 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
//const SDL = @import("sdl2");
|
// TODO: Get this from a input class, not from rl directly
|
||||||
|
const shouldClose = @import("raylib.zig").windowShouldClose;
|
||||||
|
|
||||||
const Renderer = @import("Renderer.zig");
|
const Renderer = @import("Renderer.zig");
|
||||||
const Game = @import("Game.zig");
|
const Game = @import("Game.zig");
|
||||||
|
@ -16,20 +17,7 @@ pub fn main() !void {
|
||||||
|
|
||||||
var current_state: State = main_menu.state;
|
var current_state: State = main_menu.state;
|
||||||
|
|
||||||
//try SDL.image.init(.{ .jpg = true });
|
while (!shouldClose()) {
|
||||||
|
|
||||||
//mainLoop: while (true) {
|
|
||||||
while (true) {
|
|
||||||
//const start = SDL.getTicks64();
|
|
||||||
|
|
||||||
// Manage window close request
|
|
||||||
//while (SDL.pollEvent()) |ev| {
|
|
||||||
// switch (ev) {
|
|
||||||
// .quit => break :mainLoop,
|
|
||||||
// else => {},
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (game.needs_reinit) {
|
if (game.needs_reinit) {
|
||||||
game = Game.init(&renderer);
|
game = Game.init(&renderer);
|
||||||
}
|
}
|
||||||
|
@ -44,13 +32,5 @@ pub fn main() !void {
|
||||||
};
|
};
|
||||||
|
|
||||||
renderer.render();
|
renderer.render();
|
||||||
|
|
||||||
// Limit to 60 fps
|
|
||||||
//const delay = SDL.getTicks64() - start;
|
|
||||||
|
|
||||||
//std.debug.print("{} ms\n", .{delay});
|
|
||||||
//if (delay < 17) {
|
|
||||||
// SDL.delay(17 - @intCast(u32, delay));
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
pub const c = @cImport({
|
||||||
|
@cInclude("raylib.h");
|
||||||
|
});
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
//const Self = @This();
|
||||||
|
|
||||||
|
pub fn initWindow(width: i32, height: i32, title: [*c]const u8, fps: i32) void {
|
||||||
|
c.InitWindow(width, height, title);
|
||||||
|
c.SetTargetFPS(fps);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn windowShouldClose() bool {
|
||||||
|
return c.WindowShouldClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn closeWindow() void {
|
||||||
|
c.CloseWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn beginDrawing() void {
|
||||||
|
c.BeginDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn endDrawing() void {
|
||||||
|
c.EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn drawText(text: [*c]const u8, x: i32, y: i32, fontSize: i32, r: u8, g: u8, b: u8, a: u8) void {
|
||||||
|
c.DrawText(text, x, y, fontSize, c.Color{ .r = r, .g = g, .b = b, .a = a});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clearBackground(r: u8, g: u8, b: u8, a: u8) void {
|
||||||
|
c.ClearBackground(c.Color{ .r = r, .g = g, .b = b, .a = a});
|
||||||
|
}
|
Loading…
Reference in New Issue