mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00

Some checks failed
Graphics CI / gg-regressions (push) Waiting to run
vlib modules CI / build-module-docs (push) Waiting to run
native backend CI / native-backend-ubuntu (push) Waiting to run
vab CI / v-compiles-os-android (push) Waiting to run
native backend CI / native-backend-windows (push) Waiting to run
Shy and PV CI / v-compiles-puzzle-vibes (push) Waiting to run
Sanitized CI / sanitize-undefined-clang (push) Waiting to run
Sanitized CI / sanitize-undefined-gcc (push) Waiting to run
Sanitized CI / tests-sanitize-address-clang (push) Waiting to run
Sanitized CI / sanitize-address-msvc (push) Waiting to run
Sanitized CI / sanitize-address-gcc (push) Waiting to run
Sanitized CI / sanitize-memory-clang (push) Waiting to run
sdl CI / v-compiles-sdl-examples (push) Waiting to run
Time CI / time-linux (push) Waiting to run
Time CI / time-macos (push) Waiting to run
Time CI / time-windows (push) Waiting to run
toml CI / toml-module-pass-external-test-suites (push) Waiting to run
Tools CI / tools-linux (clang) (push) Waiting to run
Tools CI / tools-linux (gcc) (push) Waiting to run
Tools CI / tools-linux (tcc) (push) Waiting to run
Tools CI / tools-macos (clang) (push) Waiting to run
Tools CI / tools-windows (gcc) (push) Waiting to run
Tools CI / tools-windows (msvc) (push) Waiting to run
Tools CI / tools-windows (tcc) (push) Waiting to run
Tools CI / tools-docker-ubuntu-musl (push) Waiting to run
vab CI / vab-compiles-v-examples (push) Waiting to run
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Waiting to run
wasm backend CI / wasm-backend (windows-2022) (push) Waiting to run
Workflow Lint / lint-yml-workflows (push) Has been cancelled
56 lines
1.8 KiB
V
56 lines
1.8 KiB
V
import gg
|
|
import os.asset
|
|
import sokol.sgl
|
|
|
|
// If you have emscripten (see https://emscripten.org/docs/getting_started/index.html), you can compile this program to WASM, using:
|
|
// `v -os wasm32_emscripten -o examples/gg/rotating_textured_quad.html examples/gg/rotating_textured_quad.v`, and later check with:
|
|
// `emrun examples/gg/rotating_textured_quad.html` .
|
|
#flag wasm32_emscripten --embed-file @VEXEROOT/examples/assets/logo.png@/assets/logo.png
|
|
#flag wasm32_emscripten --embed-file @VEXEROOT/examples/assets/fonts/RobotoMono-Regular.ttf@/assets/RobotoMono-Regular.ttf
|
|
|
|
pub struct Window {
|
|
pub mut:
|
|
ctx &gg.Context = unsafe { nil }
|
|
img gg.Image
|
|
}
|
|
|
|
pub fn (mut window Window) init() {
|
|
image_path := asset.get_path('../assets', 'logo.png')
|
|
window.img = window.ctx.create_image(image_path) or { panic(err) }
|
|
}
|
|
|
|
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.pipeline.alpha)
|
|
|
|
sgl.translate(250, 250, 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, window.img.ssmp)
|
|
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: gg.light_green
|
|
width: 500
|
|
height: 500
|
|
user_data: window
|
|
init_fn: window.init
|
|
frame_fn: window.draw
|
|
font_path: asset.get_path('../assets', 'RobotoMono-Regular.ttf')
|
|
)
|
|
window.ctx.run()
|
|
}
|