mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
examples, tests: small formatting cleanup in cube_glsl.v , remove already fixed skips in v test-cleancode
, before // vfmt off
and // vfmt on
This commit is contained in:
@@ -39,14 +39,11 @@ const verify_known_failing_exceptions = [
|
|||||||
'examples/sokol/03_march_tracing_glsl/rt_glsl.v',
|
'examples/sokol/03_march_tracing_glsl/rt_glsl.v',
|
||||||
'examples/sokol/04_multi_shader_glsl/rt_glsl.v',
|
'examples/sokol/04_multi_shader_glsl/rt_glsl.v',
|
||||||
'examples/sokol/05_instancing_glsl/rt_glsl.v',
|
'examples/sokol/05_instancing_glsl/rt_glsl.v',
|
||||||
'examples/sokol/06_obj_viewer/show_obj.v',
|
|
||||||
'vlib/v/checker/tests/modules/deprecated_module/main.v' /* adds deprecated_module. module prefix to imports, even though the folder has v.mod */,
|
'vlib/v/checker/tests/modules/deprecated_module/main.v' /* adds deprecated_module. module prefix to imports, even though the folder has v.mod */,
|
||||||
'vlib/gg/m4/graphic.v',
|
'vlib/gg/m4/graphic.v',
|
||||||
'vlib/gg/m4/m4_test.v',
|
'vlib/gg/m4/m4_test.v',
|
||||||
'vlib/gg/m4/matrix.v',
|
'vlib/gg/m4/matrix.v',
|
||||||
'vlib/builtin/int_test.v' /* special number formatting that should be tested */,
|
|
||||||
// TODOs and unfixed vfmt bugs
|
// TODOs and unfixed vfmt bugs
|
||||||
'vlib/v/gen/js/tests/js.v', /* local `hello` fn, gets replaced with module `hello` aliased as `hl` */
|
|
||||||
'vlib/v/tests/inout/string_interpolation_inner_expr_cbr.vv', /* for new string interpolation, prevent resolving to nested interpolation */
|
'vlib/v/tests/inout/string_interpolation_inner_expr_cbr.vv', /* for new string interpolation, prevent resolving to nested interpolation */
|
||||||
'vlib/v/tests/string_new_interpolation_test.v', /* new string interpolation */
|
'vlib/v/tests/string_new_interpolation_test.v', /* new string interpolation */
|
||||||
]
|
]
|
||||||
|
@@ -102,48 +102,52 @@ fn update_text_texture(sg_img gfx.Image, w int, h int, buf &byte) {
|
|||||||
fn draw_triangle() {
|
fn draw_triangle() {
|
||||||
sgl.defaults()
|
sgl.defaults()
|
||||||
sgl.begin_triangles()
|
sgl.begin_triangles()
|
||||||
sgl.v2f_c3b( 0.0, 0.5, 255, 0 , 0 )
|
{
|
||||||
sgl.v2f_c3b(-0.5, -0.5, 0, 0 , 255)
|
sgl.v2f_c3b( 0.0, 0.5, 255, 0 , 0 )
|
||||||
sgl.v2f_c3b( 0.5, -0.5, 0, 255, 0 )
|
sgl.v2f_c3b(-0.5, -0.5, 0, 0 , 255)
|
||||||
|
sgl.v2f_c3b( 0.5, -0.5, 0, 255, 0 )
|
||||||
|
}
|
||||||
sgl.end()
|
sgl.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
// vertex specification for a cube with colored sides and texture coords
|
// vertex specification for a cube with colored sides and texture coords
|
||||||
fn cube() {
|
fn cube() {
|
||||||
sgl.begin_quads()
|
sgl.begin_quads()
|
||||||
// edge color
|
{
|
||||||
sgl.c3f(1.0, 0.0, 0.0)
|
// edge color
|
||||||
// edge coord
|
sgl.c3f(1.0, 0.0, 0.0)
|
||||||
// x,y,z, texture cord: u,v
|
// edge coord
|
||||||
sgl.v3f_t2f(-1.0, 1.0, -1.0, -1.0, 1.0)
|
// x,y,z, texture cord: u,v
|
||||||
sgl.v3f_t2f( 1.0, 1.0, -1.0, 1.0, 1.0)
|
sgl.v3f_t2f(-1.0, 1.0, -1.0, -1.0, 1.0)
|
||||||
sgl.v3f_t2f( 1.0, -1.0, -1.0, 1.0, -1.0)
|
sgl.v3f_t2f( 1.0, 1.0, -1.0, 1.0, 1.0)
|
||||||
sgl.v3f_t2f(-1.0, -1.0, -1.0, -1.0, -1.0)
|
sgl.v3f_t2f( 1.0, -1.0, -1.0, 1.0, -1.0)
|
||||||
sgl.c3f(0.0, 1.0, 0.0)
|
sgl.v3f_t2f(-1.0, -1.0, -1.0, -1.0, -1.0)
|
||||||
sgl.v3f_t2f(-1.0, -1.0, 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)
|
sgl.v3f_t2f(1.0, 1.0, -1.0, 1.0, -1.0)
|
||||||
sgl.c3f(0.0, 0.5, 1.0)
|
sgl.v3f_t2f(1.0, 1.0, 1.0, -1.0, -1.0)
|
||||||
sgl.v3f_t2f( 1.0, -1.0, -1.0, -1.0, 1.0)
|
sgl.c3f(0.0, 0.5, 1.0)
|
||||||
sgl.v3f_t2f( 1.0, -1.0, 1.0, 1.0, 1.0)
|
sgl.v3f_t2f( 1.0, -1.0, -1.0, -1.0, 1.0)
|
||||||
sgl.v3f_t2f(-1.0, -1.0, 1.0, 1.0, -1.0)
|
sgl.v3f_t2f( 1.0, -1.0, 1.0, 1.0, 1.0)
|
||||||
sgl.v3f_t2f(-1.0, -1.0, -1.0, -1.0, -1.0)
|
sgl.v3f_t2f(-1.0, -1.0, 1.0, 1.0, -1.0)
|
||||||
sgl.c3f(1.0, 0.0, 0.5)
|
sgl.v3f_t2f(-1.0, -1.0, -1.0, -1.0, -1.0)
|
||||||
sgl.v3f_t2f(-1.0, 1.0, -1.0, -1.0, 1.0)
|
sgl.c3f(1.0, 0.0, 0.5)
|
||||||
sgl.v3f_t2f(-1.0, 1.0, 1.0, 1.0, 1.0)
|
sgl.v3f_t2f(-1.0, 1.0, -1.0, -1.0, 1.0)
|
||||||
sgl.v3f_t2f( 1.0, 1.0, 1.0, 1.0, -1.0)
|
sgl.v3f_t2f(-1.0, 1.0, 1.0, 1.0, 1.0)
|
||||||
sgl.v3f_t2f( 1.0, 1.0, -1.0, -1.0, -1.0)
|
sgl.v3f_t2f( 1.0, 1.0, 1.0, 1.0, -1.0)
|
||||||
|
sgl.v3f_t2f( 1.0, 1.0, -1.0, -1.0, -1.0)
|
||||||
|
}
|
||||||
sgl.end()
|
sgl.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,56 +167,62 @@ fn draw_cubes(app App) {
|
|||||||
sgl.rotate(sgl.rad(rot[1]), 0.0, 1.0, 0.0)
|
sgl.rotate(sgl.rad(rot[1]), 0.0, 1.0, 0.0)
|
||||||
cube()
|
cube()
|
||||||
sgl.push_matrix()
|
sgl.push_matrix()
|
||||||
sgl.translate(0.0, 0.0, 3.0)
|
{
|
||||||
sgl.scale(0.5, 0.5, 0.5)
|
sgl.translate(0.0, 0.0, 3.0)
|
||||||
sgl.rotate(-2.0 * sgl.rad(rot[0]), 1.0, 0.0, 0.0)
|
sgl.scale(0.5, 0.5, 0.5)
|
||||||
sgl.rotate(-2.0 * sgl.rad(rot[1]), 0.0, 1.0, 0.0)
|
sgl.rotate(-2.0 * sgl.rad(rot[0]), 1.0, 0.0, 0.0)
|
||||||
cube()
|
sgl.rotate(-2.0 * sgl.rad(rot[1]), 0.0, 1.0, 0.0)
|
||||||
sgl.push_matrix()
|
cube()
|
||||||
sgl.translate(0.0, 0.0, 3.0)
|
sgl.push_matrix()
|
||||||
sgl.scale(0.5, 0.5, 0.5)
|
{
|
||||||
sgl.rotate(-3.0 * sgl.rad(2 * rot[0]), 1.0, 0.0, 0.0)
|
sgl.translate(0.0, 0.0, 3.0)
|
||||||
sgl.rotate( 3.0 * sgl.rad(2 * rot[1]), 0.0, 0.0, 1.0)
|
sgl.scale(0.5, 0.5, 0.5)
|
||||||
cube()
|
sgl.rotate(-3.0 * sgl.rad(2 * rot[0]), 1.0, 0.0, 0.0)
|
||||||
sgl.pop_matrix()
|
sgl.rotate(3.0 * sgl.rad(2 * rot[1]), 0.0, 0.0, 1.0)
|
||||||
|
cube()
|
||||||
|
}
|
||||||
|
sgl.pop_matrix()
|
||||||
|
}
|
||||||
sgl.pop_matrix()
|
sgl.pop_matrix()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cube_texture(r f32, g f32, b f32) {
|
fn cube_texture(r f32, g f32, b f32) {
|
||||||
sgl.begin_quads()
|
sgl.begin_quads()
|
||||||
// edge color
|
{
|
||||||
sgl.c3f(r, g, b)
|
// edge color
|
||||||
// edge coord
|
sgl.c3f(r, g, b)
|
||||||
// x,y,z, texture cord: u,v
|
// edge coord
|
||||||
sgl.v3f_t2f(-1.0, 1.0, -1.0, 0.0 , 0.25)
|
// x,y,z, texture cord: u,v
|
||||||
sgl.v3f_t2f( 1.0, 1.0, -1.0, 0.25, 0.25)
|
sgl.v3f_t2f(-1.0, 1.0, -1.0, 0.0 , 0.25)
|
||||||
sgl.v3f_t2f( 1.0, -1.0, -1.0, 0.25, 0.0 )
|
sgl.v3f_t2f( 1.0, 1.0, -1.0, 0.25, 0.25)
|
||||||
sgl.v3f_t2f(-1.0, -1.0, -1.0, 0.0 , 0.0 )
|
sgl.v3f_t2f( 1.0, -1.0, -1.0, 0.25, 0.0 )
|
||||||
sgl.c3f(r, g, b)
|
sgl.v3f_t2f(-1.0, -1.0, -1.0, 0.0 , 0.0 )
|
||||||
sgl.v3f_t2f(-1.0, -1.0, 1.0, 0.0 , 0.25)
|
sgl.c3f(r, g, b)
|
||||||
sgl.v3f_t2f( 1.0, -1.0, 1.0, 0.25, 0.25)
|
sgl.v3f_t2f(-1.0, -1.0, 1.0, 0.0 , 0.25)
|
||||||
sgl.v3f_t2f( 1.0, 1.0, 1.0, 0.25, 0.0 )
|
sgl.v3f_t2f( 1.0, -1.0, 1.0, 0.25, 0.25)
|
||||||
sgl.v3f_t2f(-1.0, 1.0, 1.0, 0.0 , 0.0 )
|
sgl.v3f_t2f( 1.0, 1.0, 1.0, 0.25, 0.0 )
|
||||||
sgl.c3f(r, g, b)
|
sgl.v3f_t2f(-1.0, 1.0, 1.0, 0.0 , 0.0 )
|
||||||
sgl.v3f_t2f(-1.0, -1.0, 1.0, 0.0 , 0.25)
|
sgl.c3f(r, g, b)
|
||||||
sgl.v3f_t2f(-1.0, 1.0, 1.0, 0.25, 0.25)
|
sgl.v3f_t2f(-1.0, -1.0, 1.0, 0.0 , 0.25)
|
||||||
sgl.v3f_t2f(-1.0, 1.0, -1.0, 0.25, 0.0 )
|
sgl.v3f_t2f(-1.0, 1.0, 1.0, 0.25, 0.25)
|
||||||
sgl.v3f_t2f(-1.0, -1.0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)
|
||||||
sgl.v3f_t2f( 1.0, 1.0, 1.0, 0.25, 0.0 )
|
sgl.v3f_t2f(-1.0, 1.0, 1.0, 0.25, 0.25)
|
||||||
sgl.v3f_t2f( 1.0, 1.0, -1.0, 0.0 , 0.0 )
|
sgl.v3f_t2f( 1.0, 1.0, 1.0, 0.25, 0.0 )
|
||||||
|
sgl.v3f_t2f( 1.0, 1.0, -1.0, 0.0 , 0.0 )
|
||||||
|
}
|
||||||
sgl.end()
|
sgl.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,8 +244,8 @@ struct Vertex_t {
|
|||||||
color u32
|
color u32
|
||||||
// u u16
|
// u u16
|
||||||
// v u16
|
// v u16
|
||||||
u f32
|
u f32
|
||||||
v f32
|
v f32
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_cube_glsl(mut app App) {
|
fn init_cube_glsl(mut app App) {
|
||||||
@@ -289,7 +299,7 @@ fn init_cube_glsl(mut app App) {
|
|||||||
// vert_buffer_desc.usage = .immutable
|
// vert_buffer_desc.usage = .immutable
|
||||||
vbuf := gfx.make_buffer(&vert_buffer_desc)
|
vbuf := gfx.make_buffer(&vert_buffer_desc)
|
||||||
|
|
||||||
/* create an index buffer for the cube */
|
// create an index buffer for the cube
|
||||||
indices := [
|
indices := [
|
||||||
u16(0), 1, 2, 0, 2, 3,
|
u16(0), 1, 2, 0, 2, 3,
|
||||||
6, 5, 4, 7, 6, 4,
|
6, 5, 4, 7, 6, 4,
|
||||||
@@ -299,7 +309,9 @@ fn init_cube_glsl(mut app App) {
|
|||||||
22, 21, 20, 23, 22, 20
|
22, 21, 20, 23, 22, 20
|
||||||
]
|
]
|
||||||
|
|
||||||
mut index_buffer_desc := gfx.BufferDesc{label: c'cube-indices'}
|
mut index_buffer_desc := gfx.BufferDesc{
|
||||||
|
label: c'cube-indices'
|
||||||
|
}
|
||||||
unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) }
|
unsafe { vmemset(&index_buffer_desc, 0, int(sizeof(index_buffer_desc))) }
|
||||||
|
|
||||||
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
|
index_buffer_desc.size = usize(indices.len * int(sizeof(u16)))
|
||||||
@@ -347,46 +359,58 @@ fn draw_cube_glsl(app App) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rot := [f32(app.mouse_y), f32(app.mouse_x)]
|
// clear
|
||||||
|
|
||||||
ws := gg.window_size_real_pixels()
|
ws := gg.window_size_real_pixels()
|
||||||
// ratio := f32(ws.width)/ws.height
|
mut color_action := gfx.ColorAttachmentAction{
|
||||||
dw := f32(ws.width / 2)
|
action: unsafe { gfx.Action(C.SG_ACTION_DONTCARE) } // C.SG_ACTION_CLEAR)
|
||||||
dh := f32(ws.height / 2)
|
value: gfx.Color{
|
||||||
|
r: 1.0
|
||||||
tr_matrix := m4.calc_tr_matrices(dw, dh, rot[0], rot[1], 2.0)
|
g: 1.0
|
||||||
gfx.apply_viewport(ws.width / 2, 0, ws.width / 2, ws.height / 2, true)
|
b: 1.0
|
||||||
|
a: 1.0
|
||||||
// apply the pipline and bindings
|
}
|
||||||
gfx.apply_pipeline(app.cube_pip_glsl)
|
|
||||||
gfx.apply_bindings(app.cube_bind)
|
|
||||||
|
|
||||||
//***************
|
|
||||||
// Uniforms
|
|
||||||
//***************
|
|
||||||
// passing the view matrix as uniform
|
|
||||||
// res is a 4x4 matrix of f32 thus: 4*16 byte of size
|
|
||||||
vs_uniforms_range := gfx.Range{
|
|
||||||
ptr: &tr_matrix
|
|
||||||
size: usize(4 * 16)
|
|
||||||
}
|
}
|
||||||
gfx.apply_uniforms(.vs, C.SLOT_vs_params, &vs_uniforms_range)
|
mut pass_action := gfx.PassAction{}
|
||||||
|
pass_action.colors[0] = color_action
|
||||||
|
gfx.begin_default_pass(&pass_action, ws.width, ws.height)
|
||||||
|
{
|
||||||
|
rot := [f32(app.mouse_y), f32(app.mouse_x)]
|
||||||
|
// ratio := f32(ws.width)/ws.height
|
||||||
|
dw := f32(ws.width / 2)
|
||||||
|
dh := f32(ws.height / 2)
|
||||||
|
|
||||||
// fs uniforms
|
tr_matrix := m4.calc_tr_matrices(dw, dh, rot[0], rot[1], 2.0)
|
||||||
time_ticks := f32(time.ticks() - app.ticks) / 1000
|
gfx.apply_viewport(ws.width / 2, 0, ws.width / 2, ws.height / 2, true)
|
||||||
mut text_res := [
|
|
||||||
f32(512),
|
// apply the pipline and bindings
|
||||||
512, /* x,y resolution to pass to FS */
|
gfx.apply_pipeline(app.cube_pip_glsl)
|
||||||
time_ticks, /* time as f32 */
|
gfx.apply_bindings(app.cube_bind)
|
||||||
0 /* padding 4 Bytes == 1 f32 */,
|
|
||||||
]!
|
// Uniforms:
|
||||||
fs_uniforms_range := gfx.Range{
|
// passing the view matrix as uniform
|
||||||
ptr: unsafe { &text_res }
|
// res is a 4x4 matrix of f32 thus: 4*16 byte of size
|
||||||
size: usize(4 * 4)
|
vs_uniforms_range := gfx.Range{
|
||||||
|
ptr: &tr_matrix
|
||||||
|
size: usize(4 * 16)
|
||||||
|
}
|
||||||
|
gfx.apply_uniforms(.vs, C.SLOT_vs_params, &vs_uniforms_range)
|
||||||
|
|
||||||
|
// fs uniforms
|
||||||
|
time_ticks := f32(time.ticks() - app.ticks) / 1000
|
||||||
|
mut text_res := [
|
||||||
|
f32(512),
|
||||||
|
512, /* x,y resolution to pass to FS */
|
||||||
|
time_ticks, /* time as f32 */
|
||||||
|
0 /* padding 4 Bytes == 1 f32 */,
|
||||||
|
]!
|
||||||
|
fs_uniforms_range := gfx.Range{
|
||||||
|
ptr: unsafe { &text_res }
|
||||||
|
size: usize(4 * 4)
|
||||||
|
}
|
||||||
|
gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range)
|
||||||
|
|
||||||
|
gfx.draw(0, (3 * 2) * 6, 1)
|
||||||
}
|
}
|
||||||
gfx.apply_uniforms(.fs, C.SLOT_fs_params, &fs_uniforms_range)
|
|
||||||
|
|
||||||
gfx.draw(0, (3 * 2) * 6, 1)
|
|
||||||
gfx.end_pass()
|
gfx.end_pass()
|
||||||
gfx.commit()
|
gfx.commit()
|
||||||
}
|
}
|
||||||
@@ -407,19 +431,24 @@ fn draw_texture_cubes(app App) {
|
|||||||
sgl.rotate(sgl.rad(rot[0]), 1.0, 0.0, 0.0)
|
sgl.rotate(sgl.rad(rot[0]), 1.0, 0.0, 0.0)
|
||||||
sgl.rotate(sgl.rad(rot[1]), 0.0, 1.0, 0.0)
|
sgl.rotate(sgl.rad(rot[1]), 0.0, 1.0, 0.0)
|
||||||
cube_texture(1, 1, 1)
|
cube_texture(1, 1, 1)
|
||||||
|
|
||||||
sgl.push_matrix()
|
sgl.push_matrix()
|
||||||
|
{
|
||||||
sgl.translate(0.0, 0.0, 3.0)
|
sgl.translate(0.0, 0.0, 3.0)
|
||||||
sgl.scale(0.5, 0.5, 0.5)
|
sgl.scale(0.5, 0.5, 0.5)
|
||||||
sgl.rotate(-2.0 * sgl.rad(rot[0]), 1.0, 0.0, 0.0)
|
sgl.rotate(-2.0 * sgl.rad(rot[0]), 1.0, 0.0, 0.0)
|
||||||
sgl.rotate(-2.0 * sgl.rad(rot[1]), 0.0, 1.0, 0.0)
|
sgl.rotate(-2.0 * sgl.rad(rot[1]), 0.0, 1.0, 0.0)
|
||||||
cube_texture(1,1,1)
|
cube_texture(1, 1, 1)
|
||||||
sgl.push_matrix()
|
sgl.push_matrix()
|
||||||
|
{
|
||||||
sgl.translate(0.0, 0.0, 3.0)
|
sgl.translate(0.0, 0.0, 3.0)
|
||||||
sgl.scale(0.5, 0.5, 0.5)
|
sgl.scale(0.5, 0.5, 0.5)
|
||||||
sgl.rotate(-3.0 * sgl.rad(2*rot[0]), 1.0, 0.0, 0.0)
|
sgl.rotate(-3.0 * sgl.rad(2 * rot[0]), 1.0, 0.0, 0.0)
|
||||||
sgl.rotate(3.0 * sgl.rad(2*rot[1]), 0.0, 0.0, 1.0)
|
sgl.rotate(3.0 * sgl.rad(2 * rot[1]), 0.0, 0.0, 1.0)
|
||||||
cube_texture(1,1,1)
|
cube_texture(1, 1, 1)
|
||||||
|
}
|
||||||
sgl.pop_matrix()
|
sgl.pop_matrix()
|
||||||
|
}
|
||||||
sgl.pop_matrix()
|
sgl.pop_matrix()
|
||||||
|
|
||||||
sgl.disable_texture()
|
sgl.disable_texture()
|
||||||
@@ -440,35 +469,22 @@ fn frame(mut app App) {
|
|||||||
// app.gg.begin()
|
// app.gg.begin()
|
||||||
|
|
||||||
app.gg.begin()
|
app.gg.begin()
|
||||||
sgl.defaults()
|
{
|
||||||
|
sgl.defaults()
|
||||||
|
|
||||||
// 2d triangle
|
// 2d triangle
|
||||||
sgl.viewport(x0, y0, ww, hh, true)
|
sgl.viewport(x0, y0, ww, hh, true)
|
||||||
draw_triangle()
|
draw_triangle()
|
||||||
|
|
||||||
// colored cubes with viewport
|
// colored cubes with viewport
|
||||||
sgl.viewport(x0, y1, ww, hh, true)
|
sgl.viewport(x0, y1, ww, hh, true)
|
||||||
draw_cubes(app)
|
draw_cubes(app)
|
||||||
|
|
||||||
// textured cubed with viewport
|
// textured cubed with viewport
|
||||||
sgl.viewport(0, int(dh / 5), dw, int(dh * ratio), true)
|
sgl.viewport(0, int(dh / 5), dw, int(dh * ratio), true)
|
||||||
draw_texture_cubes(app)
|
draw_texture_cubes(app)
|
||||||
|
|
||||||
app.gg.end()
|
|
||||||
|
|
||||||
// clear
|
|
||||||
mut color_action := gfx.ColorAttachmentAction{
|
|
||||||
action: unsafe { gfx.Action(C.SG_ACTION_DONTCARE) } // C.SG_ACTION_CLEAR)
|
|
||||||
value: gfx.Color{
|
|
||||||
r: 1.0
|
|
||||||
g: 1.0
|
|
||||||
b: 1.0
|
|
||||||
a: 1.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mut pass_action := gfx.PassAction{}
|
app.gg.end()
|
||||||
pass_action.colors[0] = color_action
|
|
||||||
gfx.begin_default_pass(&pass_action, ws.width, ws.height)
|
|
||||||
|
|
||||||
// glsl cube
|
// glsl cube
|
||||||
draw_cube_glsl(app)
|
draw_cube_glsl(app)
|
||||||
@@ -477,9 +493,7 @@ fn frame(mut app App) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
*
|
|
||||||
* Init / Cleanup
|
* Init / Cleanup
|
||||||
*
|
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
fn my_init(mut app App) {
|
fn my_init(mut app App) {
|
||||||
// set max vertices,
|
// set max vertices,
|
||||||
@@ -537,9 +551,9 @@ fn my_init(mut app App) {
|
|||||||
tmp_txt[i + 3] = u8(0xFF)
|
tmp_txt[i + 3] = u8(0xFF)
|
||||||
} else {
|
} else {
|
||||||
col := if ((x + y) & 1) == 1 { 0xFF } else { 128 }
|
col := if ((x + y) & 1) == 1 { 0xFF } else { 128 }
|
||||||
tmp_txt[i + 0] = u8(col) // red
|
tmp_txt[i + 0] = u8(col) // red
|
||||||
tmp_txt[i + 1] = u8(col) // green
|
tmp_txt[i + 1] = u8(col) // green
|
||||||
tmp_txt[i + 2] = u8(col) // blue
|
tmp_txt[i + 2] = u8(col) // blue
|
||||||
tmp_txt[i + 3] = u8(0xFF) // alpha
|
tmp_txt[i + 3] = u8(0xFF) // alpha
|
||||||
}
|
}
|
||||||
i += 4
|
i += 4
|
||||||
@@ -554,9 +568,7 @@ fn my_init(mut app App) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
*
|
|
||||||
* event
|
* event
|
||||||
*
|
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
fn my_event_manager(mut ev gg.Event, mut app App) {
|
fn my_event_manager(mut ev gg.Event, mut app App) {
|
||||||
if ev.typ == .mouse_move {
|
if ev.typ == .mouse_move {
|
||||||
@@ -572,11 +584,6 @@ fn my_event_manager(mut ev gg.Event, mut app App) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Main
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// App init
|
// App init
|
||||||
mut app := &App{
|
mut app := &App{
|
||||||
|
Reference in New Issue
Block a user