const std = @import("std"); //const sdl = @import("sdl2"); //const zlm = @import("zlm"); //const gl = @import("zgl"); //const m = zlm.SpecializeOn(f32); const rl = @import("raylib.zig"); const Self = @This(); const Color = [4]u8; color: Color = .{ 0, 0, 0, 0 }, // There's a vbo for each shader program vbo: [max_objects]f32 = .{0.0} ** max_objects, vbo_index: usize = 0, // The index of the program is the enum converted to int //textures: [max_objects]Texture = .{undefined} ** max_objects, const max_objects: usize = 16384; const quadSize: usize = 9 * 6; pub fn init() !Self { rl.initWindow(640, 480, "USG", 60); var renderer = Self{}; return renderer; } pub fn render(self: *Self) void { //_ = self; rl.endDrawing(); rl.beginDrawing(); rl.clearBackground(.{232, 216, 166, 255}); //self.setColor(.{0,0,0,255}); self.fillRectangle(10, 10, 100, 100); } pub fn deinit(self: *Self) void { _ = self; rl.closeWindow(); } pub fn fillRectangle(self: *Self, x: i32, y: i32, w: i32, h: i32) void { self.fillRectangleEx(x, y, w, h, 0); } pub fn fillRectangleEx(self: *Self, x: i32, y: i32, w: i32, h: i32, skew_x: i32) void { var xf: f32 = @floatFromInt(x); var yf: f32 = @floatFromInt(y); var wf: f32 = @floatFromInt(w); var hf: f32 = @floatFromInt(h); const skew_x_offset = @as(f32, @floatFromInt(skew_x)) * hf / 100; const upLeft = [_]f32{ xf + skew_x_offset, yf }; const upRight = [_]f32{ xf + wf + skew_x_offset, yf }; const downLeft = [_]f32{ xf - skew_x_offset, yf + hf }; const downRight = [_]f32{ xf + wf - skew_x_offset, yf + hf }; rl.drawTriangle(upLeft, downLeft, upRight, self.color); rl.drawTriangle(downLeft, downRight, upRight, self.color); } pub fn drawText(self: Self, text: [:0]const u8, x: i32, y: i32, size: i32) void { rl.drawText(text, x, y, size, self.color); } pub fn setColor(self: *Self, color: Color) void { self.color = color; } pub const OutputSize = struct { width: i32, height: i32 }; pub fn getOutputSize(self: Self) OutputSize { _ = self; return OutputSize{ .width = rl.getScreenWidth(), .height = rl.getScreenHeight(), }; } //pub const Texture = struct { // texture: gl.Texture, // width: usize, // height: usize, // // pub fn init(data: [*]const u8, width: usize, height: usize) Texture { // var tex = gl.genTexture(); // //defer gl.Texture.delete(tex); // gl.bindTexture(tex, .@"2d"); // // gl.textureImage2D(.@"2d", 0, .rgba, width, height, .rgba, .unsigned_byte, data); // // gl.texParameter(.@"2d", .wrap_s, .clamp_to_edge); // gl.texParameter(.@"2d", .wrap_r, .clamp_to_edge); // gl.texParameter(.@"2d", .min_filter, .linear); // gl.texParameter(.@"2d", .mag_filter, .linear); // // return Texture{ // .texture = tex, // .width = width, // .height = height, // }; // } // // pub fn fromText(text: [:0]const u8, size: c_int) Texture { // var font = sdl.ttf.openFont("res/fonts/MarginaliaRegular-8XlZ.ttf", size) catch unreachable; // defer font.close(); // // var surface = font.renderTextBlended(text, sdl.Color.white) catch unreachable; // defer surface.destroy(); // // const width = @intCast(usize, surface.ptr.w); // const height = @intCast(usize, surface.ptr.h); // var newsurf = sdl.c.SDL_ConvertSurfaceFormat(surface.ptr, @enumToInt(sdl.PixelFormatEnum.argb8888), 0) orelse unreachable; // const data = @ptrCast([*]const u8, newsurf.pixels); // // return Texture.init(data, width, height); // } // // pub fn deinit(self: *Texture) void { // gl.Texture.delete(self.texture); // } //};