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:
56
examples/empty_gg_freetype.v
Normal file
56
examples/empty_gg_freetype.v
Normal 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() {
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user