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

examples: empty gg/freetype project

This commit is contained in:
Alexander Medvednikov
2019-11-20 07:10:19 +03:00
parent 26fb7e0821
commit 759644ab36
4 changed files with 73 additions and 10 deletions

View File

@@ -0,0 +1,56 @@
module main
import gg
import freetype
import gx
import glfw
const (
win_width = 600
win_height = 300
bg_color = gx.white
)
struct Context {
mut:
gg &gg.GG
ft &freetype.FreeType
}
fn main() {
glfw.init_glfw()
mut ctx := &Context{
gg: gg.new_context(gg.Cfg {
width: win_width
height: win_height
use_ortho: true // This is needed for 2D drawing
create_window: true
window_title: 'Empty window'
window_user_ptr: ctx
})
}
ctx.gg.window.set_user_ptr(ctx) // TODO remove this when `window_user_ptr:` works
gg.clear(bg_color)
// Try to load font
ctx.ft = freetype.new_context(gg.Cfg{
width: win_width
height: win_height
use_ortho: true
font_size: 18
scale: 2
})
for {
gg.clear(bg_color)
ctx.draw()
ctx.gg.render()
if ctx.gg.window.should_close() {
ctx.gg.window.destroy()
return
}
}
}
fn (ctx mut Context) draw() {
}

View File

@@ -128,7 +128,7 @@ struct Game {
// gg context for drawing
gg &gg.GG
// ft context for font drawing
ft &freetype.Context
ft &freetype.FreeType
font_loaded bool
}