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

sokol: fix building of examples and ci tests

This commit is contained in:
Delyan Angelov
2020-01-17 21:05:45 +02:00
committed by Alexander Medvednikov
parent 3d57d3bb7b
commit 24d34a4f2c
12 changed files with 181 additions and 183 deletions

View File

@@ -2,28 +2,32 @@ import sokol
import sokol.sapp
import sokol.gfx
import sokol.sgl
import fontstash
struct AppState {
pass_action sg_pass_action
}
const (
used_import = sokol.used_import
)
fn main() {
state := &AppState{
pass_action: gfx.create_clear_pass(0.1, 0.1, 0.1, 1.0)
}
title := 'Sokol Drawing Template'
desc := sapp_desc{
user_data: state
init_userdata_cb: init
frame_userdata_cb: frame
window_title: 'Sokal Drawing Template'.str
window_title: title.str
html5_canvas_name: title.str
}
sapp.run(&desc)
}
fn init(user_data voidptr) {
desc := sg_desc {
desc := sg_desc{
mtl_device: C.sapp_metal_get_device()
mtl_renderpass_descriptor_cb: sapp_metal_get_renderpass_descriptor
mtl_drawable_cb: sapp_metal_get_drawable
@@ -33,17 +37,14 @@ fn init(user_data voidptr) {
d3d11_depth_stencil_view_cb: sapp_d3d11_get_depth_stencil_view
}
gfx.setup(&desc)
sgl_desc := sgl_desc_t{}
sgl.setup(&sgl_desc)
}
fn frame(user_data voidptr) {
//println('frame')
// println('frame')
state := &AppState(user_data)
draw()
gfx.begin_default_pass(&state.pass_action, sapp.width(), sapp.height())
sgl.draw()
gfx.end_pass()
@@ -55,30 +56,28 @@ fn draw() {
sgl.defaults()
sgl.matrix_mode_projection()
sgl.ortho(0.0, f32(sapp.width()), f32(sapp.height()), 0.0, -1.0, 1.0)
sgl.c4b(255, 0, 0, 128)
draw_hollow_rect(10, 10, 100, 30)
sgl.c4b(25, 150, 0, 128)
draw_filled_rect(10, 150, 80, 40)
//line(0, 0, 500, 500)
// line(0, 0, 500, 500)
}
fn draw_hollow_rect(x, y, w, h f32) {
sgl.begin_line_strip()
sgl.v2f(x, y)
sgl.begin_line_strip()
sgl.v2f(x, y)
sgl.v2f(x + w, y)
sgl.v2f(x + w, y + h)
sgl.v2f(x, y + h)
sgl.v2f(x, y)
sgl.end()
sgl.end()
}
fn draw_filled_rect(x, y, w, h f32) {
sgl.begin_quads()
sgl.begin_quads()
sgl_v2f(x, y)
sgl_v2f(x + w, y)
sgl_v2f(x + w, y + h)
sgl_v2f(x, y + h)
sgl.end()
sgl_v2f(x + w, y)
sgl_v2f(x + w, y + h)
sgl_v2f(x, y + h)
sgl.end()
}