1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples: add examples/gg/rotating_textured_quad.v

This commit is contained in:
Delyan Angelov 2022-08-14 09:39:23 +03:00
parent 7280d4c95a
commit cae7bc9a9a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -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()
}