v / examples / gg
Raw file | 51 loc (45 sloc) | 1.15 KB | Latest commit hash 5bb058e35
1import gg
2import gx
3import os
4import sokol.sgl
5
6pub struct Window {
7pub mut:
8 ctx &gg.Context = unsafe { nil }
9 img gg.Image
10}
11
12pub fn (mut window Window) init() {
13 window.img = window.ctx.create_image(os.resource_abs_path('../assets/logo.png')) or {
14 panic(err)
15 }
16}
17
18pub fn (mut window Window) draw() {
19 angle := f32(window.ctx.frame) / 64 // since window.ctx.frame is increased by 1 on every frame -> the angle will be increasing too
20 window.ctx.begin()
21 sgl.load_pipeline(window.ctx.pipeline.alpha)
22
23 sgl.translate(400, 400, 0) // center of the screen
24 sgl.rotate(angle, 0.0, 0.0, 1.0) // rotate around the Z axis pointing towards the camera
25
26 sgl.enable_texture()
27 sgl.texture(window.img.simg)
28 sgl.begin_quads()
29 sgl.c4b(255, 255, 255, 255)
30 sgl.v3f_t2f(200, 200, 0, 1.0, 1.0)
31 sgl.v3f_t2f(200, -200, 0, 1.0, 0.0)
32 sgl.v3f_t2f(-200, -200, 0, 0.0, 0.0)
33 sgl.v3f_t2f(-200, 200, 0, 0.0, 1.0)
34 sgl.end()
35 sgl.disable_texture()
36 window.ctx.end()
37}
38
39fn main() {
40 mut window := &Window{}
41 window.ctx = gg.new_context(
42 window_title: 'Rotating V logo'
43 bg_color: gx.light_green
44 width: 800
45 height: 800
46 user_data: window
47 init_fn: window.init
48 frame_fn: window.draw
49 )
50 window.ctx.run()
51}