examples: make `v -prod build-examples` pass without warnings/errors
parent
67ecc04580
commit
8b2e704741
|
@ -57,14 +57,15 @@ Let my heart be still a moment and this mystery explore;—
|
|||
lines = text.split('\n')
|
||||
)
|
||||
|
||||
|
||||
struct App {
|
||||
mut:
|
||||
gg &gg.Context
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut app := &App{}
|
||||
mut app := &App{
|
||||
gg: 0
|
||||
}
|
||||
app.gg = gg.new_context({
|
||||
width: win_width
|
||||
height: win_height
|
||||
|
@ -74,8 +75,7 @@ fn main() {
|
|||
user_data: app
|
||||
bg_color: bg_color
|
||||
frame_fn: frame
|
||||
font_path: os.resource_abs_path('../assets/fonts/RobotoMono-Regular.ttf')
|
||||
//window_user_ptr: ctx
|
||||
font_path: os.resource_abs_path('../assets/fonts/RobotoMono-Regular.ttf') // window_user_ptr: ctx
|
||||
})
|
||||
app.gg.run()
|
||||
}
|
||||
|
@ -89,4 +89,3 @@ fn frame(mut app App) {
|
|||
}
|
||||
app.gg.end()
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,10 @@ mut:
|
|||
}
|
||||
|
||||
fn main() {
|
||||
mut app := &App{}
|
||||
app.gg = gg.new_context(
|
||||
mut app := &App{
|
||||
gg: 0
|
||||
}
|
||||
app.gg = gg.new_context({
|
||||
bg_color: gx.white
|
||||
width: win_width
|
||||
height: win_height
|
||||
|
@ -27,7 +29,7 @@ fn main() {
|
|||
frame_fn: frame
|
||||
user_data: app
|
||||
init_fn: init_images
|
||||
)
|
||||
})
|
||||
app.image = app.gg.create_image(os.resource_abs_path('logo.png'))
|
||||
app.gg.run()
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
module main
|
||||
|
||||
import os
|
||||
|
@ -64,7 +63,6 @@ const (
|
|||
gx.rgb(74, 198, 255), // lightblue longest
|
||||
gx.rgb(0, 170, 170), // unused ?
|
||||
]
|
||||
|
||||
background_color = gx.white
|
||||
ui_color = gx.rgba(255, 0, 0, 210)
|
||||
)
|
||||
|
@ -77,8 +75,11 @@ struct Block {
|
|||
}
|
||||
|
||||
enum GameState {
|
||||
paused running gameover
|
||||
paused
|
||||
running
|
||||
gameover
|
||||
}
|
||||
|
||||
struct Game {
|
||||
mut:
|
||||
// Score of the current game
|
||||
|
@ -118,7 +119,9 @@ struct Game {
|
|||
second_sw time.StopWatch = time.new_stopwatch({})
|
||||
}
|
||||
|
||||
const ( fpath = os.resource_abs_path('../assets/fonts/RobotoMono-Regular.ttf') )
|
||||
const (
|
||||
fpath = os.resource_abs_path('../assets/fonts/RobotoMono-Regular.ttf')
|
||||
)
|
||||
|
||||
[if showfps]
|
||||
fn (mut game Game) showfps() {
|
||||
|
@ -143,25 +146,22 @@ fn frame(mut game Game) {
|
|||
game.gg.end()
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
mut game := &Game{
|
||||
gg: 0
|
||||
}
|
||||
game.gg = gg.new_context(
|
||||
game.gg = gg.new_context({
|
||||
bg_color: gx.white
|
||||
width: win_width
|
||||
height: win_height
|
||||
use_ortho: true // This is needed for 2D drawing
|
||||
create_window: true
|
||||
window_title: 'V Tetris'
|
||||
//
|
||||
window_title: 'V Tetris' //
|
||||
user_data: game
|
||||
frame_fn: frame
|
||||
event_fn: on_event
|
||||
font_path: fpath
|
||||
//wait_events: true
|
||||
)
|
||||
font_path: fpath // wait_events: true
|
||||
})
|
||||
game.init_game()
|
||||
go game.run() // Run the game loop in a new thread
|
||||
game.gg.run() // Run the render loop in the main thread
|
||||
|
@ -348,15 +348,16 @@ fn (g &Game) draw_next_tetro() {
|
|||
}
|
||||
}
|
||||
|
||||
fn (g &Game) draw_block_color(i, j int, color gx.Color) {
|
||||
g.gg.draw_rect(f32((j - 1) * block_size), f32((i - 1) * block_size),
|
||||
f32(block_size - 1), f32(block_size - 1), color)
|
||||
fn (g &Game) draw_block_color(i int, j int, color gx.Color) {
|
||||
g.gg.draw_rect(f32((j - 1) * block_size), f32((i - 1) * block_size), f32(block_size - 1),
|
||||
f32(block_size - 1), color)
|
||||
}
|
||||
|
||||
fn (g &Game) draw_block(i, j, color_idx int) {
|
||||
fn (g &Game) draw_block(i int, j int, color_idx int) {
|
||||
color := if g.state == .gameover { gx.gray } else { colors[color_idx] }
|
||||
g.draw_block_color(i, j, color)
|
||||
}
|
||||
|
||||
fn (g &Game) draw_field() {
|
||||
for i := 1; i < field_height + 1; i++ {
|
||||
for j := 1; j < field_width + 1; j++ {
|
||||
|
@ -373,13 +374,11 @@ fn (mut g Game) draw_ui() {
|
|||
lines := g.lines.str()
|
||||
g.gg.draw_text(win_width - lines.len * text_size, 3, lines, text_cfg)
|
||||
if g.state == .gameover {
|
||||
g.gg.draw_rect(0, win_height / 2 - text_size, win_width,
|
||||
5 * text_size, ui_color)
|
||||
g.gg.draw_rect(0, win_height / 2 - text_size, win_width, 5 * text_size, ui_color)
|
||||
g.gg.draw_text(1, win_height / 2 + 0 * text_size, 'Game Over', over_cfg)
|
||||
g.gg.draw_text(1, win_height / 2 + 2 * text_size, 'Space to restart', over_cfg)
|
||||
} else if g.state == .paused {
|
||||
g.gg.draw_rect(0, win_height / 2 - text_size, win_width,
|
||||
5 * text_size, ui_color)
|
||||
g.gg.draw_rect(0, win_height / 2 - text_size, win_width, 5 * text_size, ui_color)
|
||||
g.gg.draw_text(1, win_height / 2 + 0 * text_size, 'Game Paused', text_cfg)
|
||||
g.gg.draw_text(1, win_height / 2 + 2 * text_size, 'SPACE to resume', text_cfg)
|
||||
}
|
||||
|
@ -444,7 +443,6 @@ fn (mut game Game) key_down(key sapp.KeyCode) {
|
|||
}
|
||||
else {}
|
||||
}
|
||||
|
||||
if game.state != .running {
|
||||
return
|
||||
}
|
||||
|
@ -476,7 +474,8 @@ fn (mut game Game) key_down(key sapp.KeyCode) {
|
|||
game.move_tetro() // drop faster when the player presses <down>
|
||||
}
|
||||
.d {
|
||||
for game.move_tetro() {}
|
||||
for game.move_tetro() {
|
||||
}
|
||||
}
|
||||
.g {
|
||||
game.show_ghost = !game.show_ghost
|
||||
|
|
43
vlib/gg/gg.v
43
vlib/gg/gg.v
|
@ -13,13 +13,13 @@ import math
|
|||
// import time
|
||||
pub type FNCb = fn (x voidptr)
|
||||
|
||||
pub type FNEvent = fn (e, x voidptr)
|
||||
pub type FNEvent = fn (e voidptr, x voidptr)
|
||||
|
||||
pub type FNFail = fn (msg string, x voidptr)
|
||||
|
||||
pub type FNKeyDown = fn (c sapp.KeyCode, m sapp.Modifier, x voidptr)
|
||||
|
||||
pub type FNMove = fn (x, y f32, z voidptr)
|
||||
pub type FNMove = fn (x f32, y f32, z voidptr)
|
||||
|
||||
pub type FNChar = fn (c u32, x voidptr)
|
||||
|
||||
|
@ -43,13 +43,18 @@ pub:
|
|||
cleanup_fn FNCb = voidptr(0)
|
||||
fail_fn FNFail = voidptr(0)
|
||||
event_fn FNEvent = voidptr(0)
|
||||
keydown_fn FNKeyDown = voidptr(0) // special case of event_fn
|
||||
char_fn FNChar = voidptr(0) // special case of event_fn
|
||||
move_fn FNMove = voidptr(0) // special case of event_fn
|
||||
click_fn FNMove = voidptr(0) // special case of event_fn
|
||||
keydown_fn FNKeyDown = voidptr(0)
|
||||
// special case of event_fn
|
||||
char_fn FNChar = voidptr(0)
|
||||
// special case of event_fn
|
||||
move_fn FNMove = voidptr(0)
|
||||
// special case of event_fn
|
||||
click_fn FNMove = voidptr(0)
|
||||
// special case of event_fn
|
||||
wait_events bool // set this to true for UIs, to save power
|
||||
fullscreen bool
|
||||
scale f32 = 1.0 // vid needs this
|
||||
scale f32 = 1.0
|
||||
// vid needs this
|
||||
// init_text bool
|
||||
font_path string
|
||||
}
|
||||
|
@ -61,7 +66,8 @@ mut:
|
|||
// (so that the user can store image ids, not entire Image objects)
|
||||
image_cache []Image
|
||||
pub mut:
|
||||
scale f32 = 1.0 // will get set to 2.0 for retina, will remain 1.0 for normal
|
||||
scale f32 = 1.0
|
||||
// will get set to 2.0 for retina, will remain 1.0 for normal
|
||||
width int
|
||||
height int
|
||||
clear_pass C.sg_pass_action
|
||||
|
@ -237,7 +243,7 @@ pub fn (mut ctx Context) set_bg_color(c gx.Color) {
|
|||
}
|
||||
|
||||
// TODO: Fix alpha
|
||||
pub fn (ctx &Context) draw_rect(x, y, w, h f32, c gx.Color) {
|
||||
pub fn (ctx &Context) draw_rect(x f32, y f32, w f32, h f32, c gx.Color) {
|
||||
if c.a != 255 {
|
||||
sgl.load_pipeline(ctx.timage_pip)
|
||||
}
|
||||
|
@ -250,7 +256,7 @@ pub fn (ctx &Context) draw_rect(x, y, w, h f32, c gx.Color) {
|
|||
sgl.end()
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_triangle(x, y, x2, y2, x3, y3 f32, c gx.Color) {
|
||||
pub fn (ctx &Context) draw_triangle(x f32, y f32, x2 f32, y2 f32, x3 f32, y3 f32, c gx.Color) {
|
||||
if c.a != 255 {
|
||||
sgl.load_pipeline(ctx.timage_pip)
|
||||
}
|
||||
|
@ -262,7 +268,7 @@ pub fn (ctx &Context) draw_triangle(x, y, x2, y2, x3, y3 f32, c gx.Color) {
|
|||
sgl.end()
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_empty_rect(x, y, w, h f32, c gx.Color) {
|
||||
pub fn (ctx &Context) draw_empty_rect(x f32, y f32, w f32, h f32, c gx.Color) {
|
||||
if c.a != 255 {
|
||||
sgl.load_pipeline(ctx.timage_pip)
|
||||
}
|
||||
|
@ -284,7 +290,7 @@ pub fn (ctx &Context) draw_empty_rect(x, y, w, h f32, c gx.Color) {
|
|||
sgl.end()
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_circle_line(x, y f32, r, segments int, c gx.Color) {
|
||||
pub fn (ctx &Context) draw_circle_line(x f32, y f32, r int, segments int, c gx.Color) {
|
||||
if c.a != 255 {
|
||||
sgl.load_pipeline(ctx.timage_pip)
|
||||
}
|
||||
|
@ -302,8 +308,7 @@ pub fn (ctx &Context) draw_circle_line(x, y f32, r, segments int, c gx.Color) {
|
|||
sgl.end()
|
||||
}
|
||||
|
||||
|
||||
pub fn (ctx &Context) draw_circle(x, y f32, r, segments int, c gx.Color) {
|
||||
pub fn (ctx &Context) draw_circle(x f32, y f32, r int, segments int, c gx.Color) {
|
||||
if c.a != 255 {
|
||||
sgl.load_pipeline(ctx.timage_pip)
|
||||
}
|
||||
|
@ -322,7 +327,7 @@ pub fn (ctx &Context) draw_circle(x, y f32, r, segments int, c gx.Color) {
|
|||
sgl.end()
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_arc_line(x, y f32, r int, start_angle, arc_angle f32, segments int, c gx.Color) {
|
||||
pub fn (ctx &Context) draw_arc_line(x f32, y f32, r int, start_angle f32, arc_angle f32, segments int, c gx.Color) {
|
||||
if c.a != 255 {
|
||||
sgl.load_pipeline(ctx.timage_pip)
|
||||
}
|
||||
|
@ -345,7 +350,7 @@ pub fn (ctx &Context) draw_arc_line(x, y f32, r int, start_angle, arc_angle f32,
|
|||
sgl.end()
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_arc(x, y f32, r int, start_angle, arc_angle f32, segments int, c gx.Color) {
|
||||
pub fn (ctx &Context) draw_arc(x f32, y f32, r int, start_angle f32, arc_angle f32, segments int, c gx.Color) {
|
||||
if c.a != 255 {
|
||||
sgl.load_pipeline(ctx.timage_pip)
|
||||
}
|
||||
|
@ -396,7 +401,7 @@ fn abs(a f32) f32 {
|
|||
return -a
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_line(x, y, x2, y2 f32, c gx.Color) {
|
||||
pub fn (ctx &Context) draw_line(x f32, y f32, x2 f32, y2 f32, c gx.Color) {
|
||||
if c.a != 255 {
|
||||
sgl.load_pipeline(ctx.timage_pip)
|
||||
}
|
||||
|
@ -419,10 +424,10 @@ pub fn (ctx &Context) draw_line(x, y, x2, y2 f32, c gx.Color) {
|
|||
sgl.end()
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_rounded_rect(x, y, width, height, radius f32, color gx.Color) {
|
||||
pub fn (ctx &Context) draw_rounded_rect(x f32, y f32, width f32, height f32, radius f32, color gx.Color) {
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_empty_rounded_rect(x, y, width, height, radius f32, border_color gx.Color) {
|
||||
pub fn (ctx &Context) draw_empty_rounded_rect(x f32, y f32, width f32, height f32, radius f32, border_color gx.Color) {
|
||||
}
|
||||
|
||||
fn C.WaitMessage()
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
module gg
|
||||
|
||||
// import gx
|
||||
// import sokol.sapp
|
||||
// import sokol.gfx
|
||||
import os
|
||||
import sokol
|
||||
//import sokol.sapp
|
||||
import sokol.sgl
|
||||
//import sokol.gfx
|
||||
import stbi
|
||||
|
||||
pub struct Image {
|
||||
|
@ -31,7 +31,9 @@ pub fn (mut ctx Context) create_image(file string) Image {
|
|||
if !C.sg_isvalid() {
|
||||
// Sokol is not initialized yet, add stbi object to a queue/cache
|
||||
// ctx.image_queue << file
|
||||
stb_img := stbi.load(file) or { return Image{} }
|
||||
stb_img := stbi.load(file) or {
|
||||
return Image{}
|
||||
}
|
||||
img := Image{
|
||||
width: stb_img.width
|
||||
height: stb_img.height
|
||||
|
@ -57,7 +59,9 @@ fn create_image(file string) Image {
|
|||
println('gg.create_image(): file not found: $file')
|
||||
return Image{} // none
|
||||
}
|
||||
stb_img := stbi.load(file) or { return Image{} }
|
||||
stb_img := stbi.load(file) or {
|
||||
return Image{}
|
||||
}
|
||||
mut img := Image{
|
||||
width: stb_img.width
|
||||
height: stb_img.height
|
||||
|
@ -72,7 +76,9 @@ fn create_image(file string) Image {
|
|||
}
|
||||
|
||||
pub fn create_image_from_memory(buf byteptr, bufsize int) Image {
|
||||
stb_img := stbi.load_from_memory(buf, bufsize) or { return Image{} }
|
||||
stb_img := stbi.load_from_memory(buf, bufsize) or {
|
||||
return Image{}
|
||||
}
|
||||
mut img := Image{
|
||||
width: stb_img.width
|
||||
height: stb_img.height
|
||||
|
@ -109,7 +115,7 @@ pub fn (mut img Image) init_sokol_image() &Image {
|
|||
return img
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_image(x, y, width, height f32, img_ &Image) {
|
||||
pub fn (ctx &Context) draw_image(x f32, y f32, width f32, height f32, img_ &Image) {
|
||||
if img_.id >= ctx.image_cache.len {
|
||||
eprintln('gg: draw_image() bad img id $img_.id (img cache len = $ctx.image_cache.len)')
|
||||
return
|
||||
|
@ -141,7 +147,7 @@ pub fn (ctx &Context) draw_image(x, y, width, height f32, img_ &Image) {
|
|||
}
|
||||
|
||||
// TODO remove copy pasta, merge the functions
|
||||
pub fn (ctx &Context) draw_image_flipped(x, y, width, height f32, img_ &Image) {
|
||||
pub fn (ctx &Context) draw_image_flipped(x f32, y f32, width f32, height f32, img_ &Image) {
|
||||
if img_.id >= ctx.image_cache.len {
|
||||
eprintln('gg: draw_image() bad img id $img_.id (img cache len = $ctx.image_cache.len)')
|
||||
return
|
||||
|
@ -172,9 +178,7 @@ pub fn (ctx &Context) draw_image_flipped(x, y, width, height f32, img_ &Image) {
|
|||
sgl.disable_texture()
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_image_by_id(x, y, width, height f32, id int) {
|
||||
pub fn (ctx &Context) draw_image_by_id(x f32, y f32, width f32, height f32, id int) {
|
||||
img := ctx.image_cache[id]
|
||||
ctx.draw_image(x, y, width, height, img)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ enum FontVariant {
|
|||
struct FT {
|
||||
pub:
|
||||
fons &C.FONScontext
|
||||
|
||||
font_normal int
|
||||
font_bold int
|
||||
font_mono int
|
||||
|
@ -41,7 +40,6 @@ fn new_ft(c FTConfig) ?&FT{
|
|||
return none
|
||||
}
|
||||
}
|
||||
|
||||
mut bytes := []byte{}
|
||||
$if android {
|
||||
bytes = os.read_apk_asset(c.font_path) or {
|
||||
|
@ -75,25 +73,23 @@ fn new_ft(c FTConfig) ?&FT{
|
|||
font_normal: C.fonsAddFontMem(fons, 'sans', bytes.data, bytes.len, false)
|
||||
font_bold: C.fonsAddFontMem(fons, 'sans', bytes_bold.data, bytes_bold.len, false)
|
||||
font_mono: C.fonsAddFontMem(fons, 'sans', bytes_mono.data, bytes_mono.len, false)
|
||||
font_italic: C.fonsAddFontMem(fons, 'sans', bytes_italic.data, bytes_italic.len, false)
|
||||
font_italic: C.fonsAddFontMem(fons, 'sans', bytes_italic.data, bytes_italic.len,
|
||||
false)
|
||||
scale: c.scale
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn (ctx &Context) set_cfg(cfg gx.TextCfg) {
|
||||
if !ctx.font_inited {
|
||||
return
|
||||
}
|
||||
if cfg.bold {
|
||||
ctx.ft.fons.set_font(ctx.ft.font_bold)
|
||||
}
|
||||
else if cfg.mono {
|
||||
} else if cfg.mono {
|
||||
ctx.ft.fons.set_font(ctx.ft.font_mono)
|
||||
}
|
||||
else if cfg.italic {
|
||||
} else if cfg.italic {
|
||||
ctx.ft.fons.set_font(ctx.ft.font_italic)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ctx.ft.fons.set_font(ctx.ft.font_normal)
|
||||
}
|
||||
scale := if ctx.ft.scale == 0 { f32(1) } else { ctx.ft.scale }
|
||||
|
@ -111,7 +107,7 @@ fn (ctx &Context) set_cfg(cfg gx.TextCfg) {
|
|||
ctx.ft.fons.vert_metrics(&ascender, &descender, &lh)
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_text(x, y int, text_ string, cfg gx.TextCfg) {
|
||||
pub fn (ctx &Context) draw_text(x int, y int, text_ string, cfg gx.TextCfg) {
|
||||
if !ctx.font_inited {
|
||||
eprintln('gg: draw_text(): font not initialized')
|
||||
return
|
||||
|
@ -126,7 +122,7 @@ pub fn (ctx &Context) draw_text(x, y int, text_ string, cfg gx.TextCfg) {
|
|||
C.fonsDrawText(ctx.ft.fons, x * scale, y * scale, text.str, 0) // TODO: check offsets/alignment
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_text_def(x, y int, text string) {
|
||||
pub fn (ctx &Context) draw_text_def(x int, y int, text string) {
|
||||
ctx.draw_text(x, y, text, {})
|
||||
}
|
||||
|
||||
|
@ -134,7 +130,6 @@ pub fn (ctx &Context) draw_text_def(x, y int, text string) {
|
|||
pub fn (mut gg FT) init_font() {
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn (ft &FT) flush() {
|
||||
sfons.flush(ft.fons)
|
||||
}
|
||||
|
@ -172,7 +167,6 @@ pub fn (ctx &Context) text_size(s string) (int, int) {
|
|||
return int((buf[2] - buf[0]) / ctx.scale), int((buf[3] - buf[1]) / ctx.scale)
|
||||
}
|
||||
|
||||
|
||||
pub fn system_font_path() string {
|
||||
env_font := os.getenv('VUI_FONT')
|
||||
if env_font != '' && os.exists(env_font) {
|
||||
|
@ -191,7 +185,9 @@ pub fn system_font_path() string {
|
|||
}
|
||||
}
|
||||
}
|
||||
s := os.exec('fc-list') or { panic('failed to fetch system fonts') }
|
||||
s := os.exec('fc-list') or {
|
||||
panic('failed to fetch system fonts')
|
||||
}
|
||||
system_fonts := s.output.split('\n')
|
||||
for line in system_fonts {
|
||||
for font in fonts {
|
||||
|
|
167
vlib/gx/color.v
167
vlib/gx/color.v
|
@ -1,29 +1,106 @@
|
|||
module gx
|
||||
|
||||
pub const (
|
||||
blue = Color { r: 0, g: 0, b: 255 }
|
||||
red = Color { r: 255, g: 0, b: 0 }
|
||||
green = Color { r: 0, g: 255, b: 0 }
|
||||
yellow = Color { r: 255, g: 255, b: 0 }
|
||||
|
||||
orange = Color { r: 255, g: 165, b: 0 }
|
||||
purple = Color { r: 128, g: 0, b: 128 }
|
||||
|
||||
black = Color { r: 0, g: 0, b: 0 }
|
||||
gray = Color { r: 128, g: 128, b: 128 }
|
||||
indigo = Color { r: 75, g: 0, b: 130 }
|
||||
pink = Color { r: 255, g: 192, b: 203 }
|
||||
violet = Color { r: 238, g: 130, b: 238 }
|
||||
white = Color { r: 255, g: 255, b: 255 }
|
||||
|
||||
dark_blue = Color { r: 0, g: 0, b: 139 }
|
||||
dark_gray = Color { r: 169, g: 169, b: 169 }
|
||||
dark_green = Color { r: 0, g: 100, b: 0 }
|
||||
dark_red = Color { r: 139, g: 0, b: 0 }
|
||||
light_blue = Color { r: 173, g: 216, b: 230 }
|
||||
light_gray = Color { r: 211, g: 211, b: 211 }
|
||||
light_green = Color { r: 144, g: 238, b: 144 }
|
||||
light_red = Color { r: 255, g: 204, b: 203 }
|
||||
blue = Color{
|
||||
r: 0
|
||||
g: 0
|
||||
b: 255
|
||||
}
|
||||
red = Color{
|
||||
r: 255
|
||||
g: 0
|
||||
b: 0
|
||||
}
|
||||
green = Color{
|
||||
r: 0
|
||||
g: 255
|
||||
b: 0
|
||||
}
|
||||
yellow = Color{
|
||||
r: 255
|
||||
g: 255
|
||||
b: 0
|
||||
}
|
||||
orange = Color{
|
||||
r: 255
|
||||
g: 165
|
||||
b: 0
|
||||
}
|
||||
purple = Color{
|
||||
r: 128
|
||||
g: 0
|
||||
b: 128
|
||||
}
|
||||
black = Color{
|
||||
r: 0
|
||||
g: 0
|
||||
b: 0
|
||||
}
|
||||
gray = Color{
|
||||
r: 128
|
||||
g: 128
|
||||
b: 128
|
||||
}
|
||||
indigo = Color{
|
||||
r: 75
|
||||
g: 0
|
||||
b: 130
|
||||
}
|
||||
pink = Color{
|
||||
r: 255
|
||||
g: 192
|
||||
b: 203
|
||||
}
|
||||
violet = Color{
|
||||
r: 238
|
||||
g: 130
|
||||
b: 238
|
||||
}
|
||||
white = Color{
|
||||
r: 255
|
||||
g: 255
|
||||
b: 255
|
||||
}
|
||||
dark_blue = Color{
|
||||
r: 0
|
||||
g: 0
|
||||
b: 139
|
||||
}
|
||||
dark_gray = Color{
|
||||
r: 169
|
||||
g: 169
|
||||
b: 169
|
||||
}
|
||||
dark_green = Color{
|
||||
r: 0
|
||||
g: 100
|
||||
b: 0
|
||||
}
|
||||
dark_red = Color{
|
||||
r: 139
|
||||
g: 0
|
||||
b: 0
|
||||
}
|
||||
light_blue = Color{
|
||||
r: 173
|
||||
g: 216
|
||||
b: 230
|
||||
}
|
||||
light_gray = Color{
|
||||
r: 211
|
||||
g: 211
|
||||
b: 211
|
||||
}
|
||||
light_green = Color{
|
||||
r: 144
|
||||
g: 238
|
||||
b: 144
|
||||
}
|
||||
light_red = Color{
|
||||
r: 255
|
||||
g: 204
|
||||
b: 203
|
||||
}
|
||||
)
|
||||
|
||||
// Color represents a 32 bit color value in sRGB format
|
||||
|
@ -38,62 +115,62 @@ pub mut:
|
|||
// hex takes in a 32 bit integer and splits it into 4 byte values
|
||||
pub fn hex(color int) Color {
|
||||
return Color{
|
||||
r: byte((color >> 24) & 0xFF),
|
||||
g: byte((color >> 16) & 0xFF),
|
||||
b: byte((color >> 8) & 0xFF),
|
||||
r: byte((color >> 24) & 0xFF)
|
||||
g: byte((color >> 16) & 0xFF)
|
||||
b: byte((color >> 8) & 0xFF)
|
||||
a: byte((color) & 0xFF)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rgb(r, g, b byte) Color {
|
||||
pub fn rgb(r byte, g byte, b byte) Color {
|
||||
return Color{
|
||||
r: r,
|
||||
g: g,
|
||||
r: r
|
||||
g: g
|
||||
b: b
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rgba(r, g, b, a byte) Color {
|
||||
pub fn rgba(r byte, g byte, b byte, a byte) Color {
|
||||
return Color{
|
||||
r: r,
|
||||
g: g,
|
||||
b: b,
|
||||
r: r
|
||||
g: g
|
||||
b: b
|
||||
a: a
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (c Color) +(c2 Color) Color {
|
||||
return Color{
|
||||
r: c.r + c2.r,
|
||||
g: c.g + c2.g,
|
||||
b: c.b + c2.b,
|
||||
r: c.r + c2.r
|
||||
g: c.g + c2.g
|
||||
b: c.b + c2.b
|
||||
a: c.b + c2.a
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (c Color) -(c2 Color) Color {
|
||||
return Color{
|
||||
r: c.r - c2.r,
|
||||
g: c.g - c2.g,
|
||||
b: c.b - c2.b,
|
||||
r: c.r - c2.r
|
||||
g: c.g - c2.g
|
||||
b: c.b - c2.b
|
||||
a: c.b - c2.a
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (c Color) *(c2 Color) Color {
|
||||
return Color{
|
||||
r: c.r * c2.r,
|
||||
g: c.g * c2.g,
|
||||
b: c.b * c2.b,
|
||||
r: c.r * c2.r
|
||||
g: c.g * c2.g
|
||||
b: c.b * c2.b
|
||||
a: c.b * c2.a
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (c Color) /(c2 Color) Color {
|
||||
return Color{
|
||||
r: c.r / c2.r,
|
||||
g: c.g / c2.g,
|
||||
b: c.b / c2.b,
|
||||
r: c.r / c2.r
|
||||
g: c.g / c2.g
|
||||
b: c.b / c2.b
|
||||
a: c.b / c2.a
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ pub struct C.sg_desc {
|
|||
_end_canary u32
|
||||
}
|
||||
|
||||
|
||||
pub struct C.sg_context_desc {
|
||||
/*
|
||||
sg_pixel_format color_format;
|
||||
|
@ -39,7 +38,6 @@ pub struct C.sg_context_desc {
|
|||
gl C.sg_gl_context_desc
|
||||
metal C.sg_mtl_context_desc
|
||||
d3d11 C.sg_d3d11_context_desc
|
||||
|
||||
color_format PixelFormat
|
||||
depth_format PixelFormat
|
||||
}
|
||||
|
@ -61,7 +59,6 @@ pub struct C.sg_d3d11_context_desc {
|
|||
depth_stencil_view_cb fn () voidptr
|
||||
}
|
||||
|
||||
|
||||
pub struct C.sg_pipeline_desc {
|
||||
pub mut:
|
||||
_start_canary u32
|
||||
|
@ -77,15 +74,16 @@ pub mut:
|
|||
}
|
||||
|
||||
pub struct C.sg_pipeline_info {
|
||||
|
||||
}
|
||||
|
||||
pub struct C.sg_pipeline {
|
||||
pub:
|
||||
id u32
|
||||
}
|
||||
pub fn (p C.sg_pipeline) free() { C.sg_destroy_pipeline(p) }
|
||||
|
||||
pub fn (p C.sg_pipeline) free() {
|
||||
C.sg_destroy_pipeline(p)
|
||||
}
|
||||
|
||||
pub struct C.sg_bindings {
|
||||
pub mut:
|
||||
|
@ -123,7 +121,6 @@ pub fn (b &C.sg_bindings) append_index_buffer(data voidptr, element_size int, el
|
|||
return C.sg_append_buffer(b.index_buffer, data, element_size * element_count)
|
||||
}
|
||||
|
||||
|
||||
pub struct C.sg_shader_desc {
|
||||
pub mut:
|
||||
_start_canary u32
|
||||
|
@ -156,12 +153,12 @@ pub fn (mut desc C.sg_shader_desc) set_frag_image(index int, name string) &C.sg_
|
|||
return desc
|
||||
}
|
||||
|
||||
pub fn (mut desc C.sg_shader_desc) set_vert_uniform_block_size(block_index, size int) &C.sg_shader_desc {
|
||||
pub fn (mut desc C.sg_shader_desc) set_vert_uniform_block_size(block_index int, size int) &C.sg_shader_desc {
|
||||
desc.vs.uniform_blocks[block_index].size = size
|
||||
return desc
|
||||
}
|
||||
|
||||
pub fn (mut desc C.sg_shader_desc) set_frag_uniform_block_size(block_index, size int) &C.sg_shader_desc {
|
||||
pub fn (mut desc C.sg_shader_desc) set_frag_uniform_block_size(block_index int, size int) &C.sg_shader_desc {
|
||||
desc.fs.uniform_blocks[block_index].size = size
|
||||
return desc
|
||||
}
|
||||
|
@ -182,12 +179,11 @@ pub fn (desc &C.sg_shader_desc) make_shader() C.sg_shader {
|
|||
return C.sg_make_shader(desc)
|
||||
}
|
||||
|
||||
|
||||
pub struct C.sg_shader_attr_desc {
|
||||
pub mut:
|
||||
name byteptr /* GLSL vertex attribute name (only required for GLES2) */
|
||||
sem_name byteptr /* HLSL semantic name */
|
||||
sem_index int /* HLSL semantic index */
|
||||
name byteptr // GLSL vertex attribute name (only required for GLES2)
|
||||
sem_name byteptr // HLSL semantic name
|
||||
sem_index int // HLSL semantic index
|
||||
}
|
||||
|
||||
pub struct C.sg_shader_stage_desc {
|
||||
|
@ -206,7 +202,6 @@ pub fn (mut desc C.sg_shader_stage_desc) set_image(index int, name string) C.sg_
|
|||
return *desc
|
||||
}
|
||||
|
||||
|
||||
pub struct C.sg_shader_uniform_block_desc {
|
||||
pub mut:
|
||||
size int
|
||||
|
@ -226,7 +221,8 @@ pub mut:
|
|||
@type ImageType
|
||||
}
|
||||
|
||||
pub struct C.sg_shader_info {}
|
||||
pub struct C.sg_shader_info {
|
||||
}
|
||||
|
||||
pub struct C.sg_context {
|
||||
id u32
|
||||
|
@ -236,8 +232,10 @@ pub struct C.sg_shader {
|
|||
pub:
|
||||
id u32
|
||||
}
|
||||
pub fn (s C.sg_shader) free() { C.sg_destroy_shader(s) }
|
||||
|
||||
pub fn (s C.sg_shader) free() {
|
||||
C.sg_destroy_shader(s)
|
||||
}
|
||||
|
||||
pub struct C.sg_pass_desc {
|
||||
pub mut:
|
||||
|
@ -264,8 +262,10 @@ pub mut:
|
|||
pub struct C.sg_pass {
|
||||
id u32
|
||||
}
|
||||
pub fn (p C.sg_pass) free() { C.sg_destroy_pass(p) }
|
||||
|
||||
pub fn (p C.sg_pass) free() {
|
||||
C.sg_destroy_pass(p)
|
||||
}
|
||||
|
||||
pub struct C.sg_buffer_desc {
|
||||
pub mut:
|
||||
|
@ -275,24 +275,27 @@ pub mut:
|
|||
usage Usage
|
||||
content byteptr
|
||||
label byteptr
|
||||
/* GL specific */
|
||||
// GL specific
|
||||
gl_buffers [2]u32
|
||||
/* Metal specific */
|
||||
// Metal specific
|
||||
mtl_buffers [2]voidptr
|
||||
/* D3D11 specific */
|
||||
// D3D11 specific
|
||||
d3d11_buffer voidptr
|
||||
_end_canary u32
|
||||
}
|
||||
|
||||
pub struct C.sg_buffer_info {}
|
||||
pub struct C.sg_buffer_info {
|
||||
}
|
||||
|
||||
pub struct C.sg_buffer {
|
||||
id u32
|
||||
}
|
||||
pub fn (b C.sg_buffer) free() { C.sg_destroy_buffer(b) }
|
||||
|
||||
pub fn (b C.sg_buffer) free() {
|
||||
C.sg_destroy_buffer(b)
|
||||
}
|
||||
|
||||
pub union DepthLayers {
|
||||
pub struct DepthLayers {
|
||||
depth int
|
||||
layers int
|
||||
}
|
||||
|
@ -304,7 +307,6 @@ pub mut:
|
|||
render_target bool
|
||||
width int
|
||||
height int
|
||||
|
||||
depth DepthLayers
|
||||
// depth int
|
||||
// union {
|
||||
|
@ -326,29 +328,31 @@ pub mut:
|
|||
max_lod f32
|
||||
content C.sg_image_content
|
||||
label byteptr
|
||||
/* GL specific */
|
||||
// GL specific
|
||||
gl_textures [2]u32
|
||||
/* Metal specific */
|
||||
// Metal specific
|
||||
mtl_textures [2]voidptr
|
||||
/* D3D11 specific */
|
||||
// D3D11 specific
|
||||
d3d11_texture voidptr
|
||||
_end_canary u32
|
||||
}
|
||||
|
||||
pub struct C.sg_image_info {
|
||||
pub mut:
|
||||
slot C.sg_slot_info /* resource pool slot info */
|
||||
upd_frame_index u32 /* frame index of last sg_update_image() */
|
||||
num_slots int /* number of renaming-slots for dynamically updated images */
|
||||
active_slot int /* currently active write-slot for dynamically updated images */
|
||||
slot C.sg_slot_info // resource pool slot info
|
||||
upd_frame_index u32 // frame index of last sg_update_image()
|
||||
num_slots int // number of renaming-slots for dynamically updated images
|
||||
active_slot int // currently active write-slot for dynamically updated images
|
||||
}
|
||||
|
||||
pub struct C.sg_image {
|
||||
pub:
|
||||
id u32
|
||||
}
|
||||
pub fn (i C.sg_image) free() { C.sg_destroy_image(i) }
|
||||
|
||||
pub fn (i C.sg_image) free() {
|
||||
C.sg_destroy_image(i)
|
||||
}
|
||||
|
||||
pub struct C.sg_image_content {
|
||||
pub mut:
|
||||
|
@ -357,29 +361,29 @@ pub mut:
|
|||
|
||||
pub struct C.sg_subimage_content {
|
||||
pub mut:
|
||||
ptr voidptr /* pointer to subimage data */
|
||||
size int /* size in bytes of pointed-to subimage data */
|
||||
ptr voidptr // pointer to subimage data
|
||||
size int // size in bytes of pointed-to subimage data
|
||||
}
|
||||
|
||||
pub struct C.sg_features {
|
||||
pub:
|
||||
instancing bool /* hardware instancing supported */
|
||||
origin_top_left bool /* framebuffer and texture origin is in top left corner */
|
||||
multiple_render_targets bool /* offscreen render passes can have multiple render targets attached */
|
||||
msaa_render_targets bool /* offscreen render passes support MSAA antialiasing */
|
||||
imagetype_3d bool /* creation of SG_IMAGETYPE_3D images is supported */
|
||||
imagetype_array bool /* creation of SG_IMAGETYPE_ARRAY images is supported */
|
||||
image_clamp_to_border bool /* border color and clamp-to-border UV-wrap mode is supported */
|
||||
instancing bool // hardware instancing supported
|
||||
origin_top_left bool // framebuffer and texture origin is in top left corner
|
||||
multiple_render_targets bool // offscreen render passes can have multiple render targets attached
|
||||
msaa_render_targets bool // offscreen render passes support MSAA antialiasing
|
||||
imagetype_3d bool // creation of SG_IMAGETYPE_3D images is supported
|
||||
imagetype_array bool // creation of SG_IMAGETYPE_ARRAY images is supported
|
||||
image_clamp_to_border bool // border color and clamp-to-border UV-wrap mode is supported
|
||||
}
|
||||
|
||||
pub struct C.sg_limits {
|
||||
pub:
|
||||
max_image_size_2d u32 /* max width/height of SG_IMAGETYPE_2D images */
|
||||
max_image_size_cube u32 /* max width/height of SG_IMAGETYPE_CUBE images */
|
||||
max_image_size_3d u32 /* max width/height/depth of SG_IMAGETYPE_3D images */
|
||||
max_image_size_array u32 /* max width/height pf SG_IMAGETYPE_ARRAY images */
|
||||
max_image_array_layers u32 /* max number of layers in SG_IMAGETYPE_ARRAY images */
|
||||
max_vertex_attrs u32 /* <= SG_MAX_VERTEX_ATTRIBUTES (only on some GLES2 impls) */
|
||||
max_image_size_2d u32 // max width/height of SG_IMAGETYPE_2D images
|
||||
max_image_size_cube u32 // max width/height of SG_IMAGETYPE_CUBE images
|
||||
max_image_size_3d u32 // max width/height/depth of SG_IMAGETYPE_3D images
|
||||
max_image_size_array u32 // max width/height pf SG_IMAGETYPE_ARRAY images
|
||||
max_image_array_layers u32 // max number of layers in SG_IMAGETYPE_ARRAY images
|
||||
max_vertex_attrs u32 // <= SG_MAX_VERTEX_ATTRIBUTES (only on some GLES2 impls)
|
||||
}
|
||||
|
||||
pub struct C.sg_layout_desc {
|
||||
|
@ -447,7 +451,6 @@ pub mut:
|
|||
depth_bias_clamp f32
|
||||
}
|
||||
|
||||
|
||||
pub struct C.sg_color_attachment_action {
|
||||
pub mut:
|
||||
action Action
|
||||
|
@ -462,7 +465,6 @@ pub fn (mut action C.sg_color_attachment_action) set_color_values(r, g, b, a f32
|
|||
action.val[3] = a
|
||||
}
|
||||
*/
|
||||
|
||||
pub struct C.sg_depth_attachment_action {
|
||||
pub mut:
|
||||
action Action
|
||||
|
@ -477,12 +479,12 @@ pub mut:
|
|||
|
||||
pub struct C.sg_pixelformat_info {
|
||||
pub:
|
||||
sample bool /* pixel format can be sampled in shaders */
|
||||
filter bool /* pixel format can be sampled with filtering */
|
||||
render bool /* pixel format can be used as render target */
|
||||
blend bool /* alpha-blending is supported */
|
||||
msaa bool /* pixel format can be used as MSAA render target */
|
||||
depth bool /* pixel format is a depth format */
|
||||
sample bool // pixel format can be sampled in shaders
|
||||
filter bool // pixel format can be sampled with filtering
|
||||
render bool // pixel format can be used as render target
|
||||
blend bool // alpha-blending is supported
|
||||
msaa bool // pixel format can be used as MSAA render target
|
||||
depth bool // pixel format is a depth format
|
||||
}
|
||||
|
||||
pub struct C.sg_attachment_desc {
|
||||
|
@ -490,7 +492,6 @@ pub mut:
|
|||
image C.sg_image
|
||||
mip_level int
|
||||
face int
|
||||
|
||||
// image sg_image
|
||||
// mip_level int
|
||||
// union {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module gfx
|
||||
|
||||
pub fn create_clear_pass(r, g, b, a f32) C.sg_pass_action {
|
||||
pub fn create_clear_pass(r f32, g f32, b f32, a f32) C.sg_pass_action {
|
||||
mut color_action := C.sg_color_attachment_action{
|
||||
action: C.SG_ACTION_CLEAR
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ color_action.val[0] = r
|
|||
color_action.val[1] = g
|
||||
color_action.val[2] = b
|
||||
color_action.val[3] = a
|
||||
|
||||
mut pass_action := C.sg_pass_action{}
|
||||
pass_action.colors[0] = color_action
|
||||
return pass_action
|
||||
|
|
Loading…
Reference in New Issue