From cae7bc9a9a0896ab699d025081a881b34056d845 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 14 Aug 2022 09:39:23 +0300 Subject: [PATCH] examples: add examples/gg/rotating_textured_quad.v --- examples/gg/rotating_textured_quad.v | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 examples/gg/rotating_textured_quad.v diff --git a/examples/gg/rotating_textured_quad.v b/examples/gg/rotating_textured_quad.v new file mode 100644 index 000000000..1ffec3f80 --- /dev/null +++ b/examples/gg/rotating_textured_quad.v @@ -0,0 +1,49 @@ +import gg +import gx +import os +import sokol.sgl + +pub struct Window { +pub mut: + ctx &gg.Context = unsafe { nil } + img gg.Image +} + +pub fn (mut window Window) init() { + window.img = window.ctx.create_image(os.resource_abs_path('../assets/logo.png')) +} + +pub fn (mut window Window) draw() { + angle := f32(window.ctx.frame) / 64 // since window.ctx.frame is increased by 1 on every frame -> the angle will be increasing too + window.ctx.begin() + sgl.load_pipeline(window.ctx.timage_pip) + + sgl.translate(400, 400, 0) // center of the screen + sgl.rotate(angle, 0.0, 0.0, 1.0) // rotate around the Z axis pointing towards the camera + + sgl.enable_texture() + sgl.texture(window.img.simg) + sgl.begin_quads() + sgl.c4b(255, 255, 255, 255) + sgl.v3f_t2f(200, 200, 0, 1.0, 1.0) + sgl.v3f_t2f(200, -200, 0, 1.0, 0.0) + sgl.v3f_t2f(-200, -200, 0, 0.0, 0.0) + sgl.v3f_t2f(-200, 200, 0, 0.0, 1.0) + sgl.end() + sgl.disable_texture() + window.ctx.end() +} + +fn main() { + mut window := &Window{} + window.ctx = gg.new_context( + window_title: 'Rotating V logo' + bg_color: gx.light_green + width: 800 + height: 800 + user_data: window + init_fn: window.init + frame_fn: window.draw + ) + window.ctx.run() +} -- 2.30.2