use gl::*; use glm; type GuiVertex = struct { position: [2]f32, texcoord: [2]f32, color: [4]u8, }; fn render_rect_textured( trans: *glm::m4, x: f32, y: f32, w: f32, h: f32, color: [4]u8, u: f32, v: f32, sprw: f32, sprh: f32, tex: uint, texw: u32, texh: u32, ) void = { const x0 = x; const x1 = x + w; const y0 = y; const y1 = y + h; const u0 = u / texw: f32; const u1 = (u + sprw) / texw: f32; const v0 = v / texh: f32; const v1 = (v + sprh) / texh: f32; const quad = [ GuiVertex { position = [x0, y0], texcoord = [u0, v0], color = color, }, GuiVertex { position = [x0, y1], texcoord = [u0, v1], color = color, }, GuiVertex { position = [x1, y1], texcoord = [u1, v1], color = color, }, GuiVertex { position = [x1, y0], texcoord = [u1, v0], color = color, }, ]; const vertices = [ quad[0], quad[1], quad[2], quad[2], quad[3], quad[0], ]; glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glUseProgram(SHADER_GUI); glUniformMatrix4fv(0, 1, 0, trans: *f32); glBindTexture(GL_TEXTURE_2D, tex); let vbo = 0u; glGenBuffers(1, &vbo); defer glDeleteBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, (size(GuiVertex) * len(vertices)): uintptr, &vertices: *[*]GuiVertex, GL_STREAM_DRAW); glBindVertexArray(VAO_GUI); glBindVertexBuffer(0, vbo, 0, size(GuiVertex): i32); glDrawArrays(GL_TRIANGLES, 0, len(vertices): i32); glBindVertexArray(0); };