| 1 | import gg |
| 2 | import os.asset |
| 3 | import sokol.sgl |
| 4 | |
| 5 | // If you have emscripten (see https://emscripten.org/docs/getting_started/index.html), you can compile this program to WASM, using: |
| 6 | // `v -os wasm32_emscripten -o examples/gg/rotating_textured_quad.html examples/gg/rotating_textured_quad.v`, and later check with: |
| 7 | // `emrun examples/gg/rotating_textured_quad.html` . |
| 8 | #flag wasm32_emscripten --embed-file @VEXEROOT/examples/assets/logo.png@/assets/logo.png |
| 9 | #flag wasm32_emscripten --embed-file @VEXEROOT/examples/assets/fonts/RobotoMono-Regular.ttf@/assets/RobotoMono-Regular.ttf |
| 10 | |
| 11 | pub struct Window { |
| 12 | pub mut: |
| 13 | ctx &gg.Context = unsafe { nil } |
| 14 | img gg.Image |
| 15 | } |
| 16 | |
| 17 | pub fn (mut window Window) init() { |
| 18 | image_path := asset.get_path('../assets', 'logo.png') |
| 19 | window.img = window.ctx.create_image(image_path) or { panic(err) } |
| 20 | } |
| 21 | |
| 22 | pub fn (mut window Window) draw() { |
| 23 | angle := f32(window.ctx.frame) / 64 // since window.ctx.frame is increased by 1 on every frame -> the angle will be increasing too |
| 24 | window.ctx.begin() |
| 25 | sgl.load_pipeline(window.ctx.pipeline.alpha) |
| 26 | |
| 27 | sgl.translate(250, 250, 0) // center of the screen |
| 28 | sgl.rotate(angle, 0.0, 0.0, 1.0) // rotate around the Z axis pointing towards the camera |
| 29 | |
| 30 | sgl.enable_texture() |
| 31 | sgl.texture(window.img.simg, window.img.ssmp) |
| 32 | sgl.begin_quads() |
| 33 | sgl.c4b(255, 255, 255, 255) |
| 34 | sgl.v3f_t2f(200, 200, 0, 1.0, 1.0) |
| 35 | sgl.v3f_t2f(200, -200, 0, 1.0, 0.0) |
| 36 | sgl.v3f_t2f(-200, -200, 0, 0.0, 0.0) |
| 37 | sgl.v3f_t2f(-200, 200, 0, 0.0, 1.0) |
| 38 | sgl.end() |
| 39 | sgl.disable_texture() |
| 40 | window.ctx.end() |
| 41 | } |
| 42 | |
| 43 | fn main() { |
| 44 | mut window := &Window{} |
| 45 | window.ctx = gg.new_context( |
| 46 | window_title: 'Rotating V logo' |
| 47 | bg_color: gg.light_green |
| 48 | width: 500 |
| 49 | height: 500 |
| 50 | user_data: window |
| 51 | init_fn: window.init |
| 52 | frame_fn: window.draw |
| 53 | font_path: asset.get_path('../assets', 'RobotoMono-Regular.ttf') |
| 54 | ) |
| 55 | window.ctx.run() |
| 56 | } |
| 57 | |