1
0
Fork 0
auts/isotest/app.v

89 lines
1.4 KiB
V

module main
import nsauzede.vsdl2
import nsauzede.vsdl2.image as img
import time
type Atexit_func_t fn ()
fn C.atexit(Atexit_func_t)
struct App {
mut:
w int
h int
dt f32
ctx &Context
// Sdl (fixme?)
window voidptr
screen &vsdl2.Surface
renderer voidptr
}
fn new_app(mut ctx Context) &App {
println("new_app()")
a := &App{
dt: 0.0,
ctx: ctx,
}
// Update ctx
ctx.app = a
return a
}
fn (mut a App) init(w, h int, title string) {
println("app init() w: $w, h: $h")
// Init sdl
println("init sdl...")
C.SDL_Init(C.SDL_INIT_VIDEO)
C.atexit(C.SDL_Quit)
C.TTF_Init()
C.atexit(C.TTF_Quit)
bpp := 32
vsdl2.create_window_and_renderer(w, h, 0, &a.window, &a.renderer)
C.SDL_SetWindowTitle(a.window, title.str)
a.w = w
a.h = h
a.screen = vsdl2.create_rgb_surface(0, w, h, bpp, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000)
//a.texture = C.SDL_CreateTexture(sdl.renderer, C.SDL_PIXELFORMAT_ARGB8888, C.SDL_TEXTUREACCESS_STREAMING, w, h)
flags := C.IMG_INIT_PNG
imgres := img.img_init(flags)
if (imgres & flags) != flags {
println('error initializing image library.')
}
// Init drawer
println("init drawer...")
mut d := new_drawer(mut a.ctx)
d.init(w, h, a.renderer)
println("app init done")
}
fn (mut a App) step() {
println("app step()")
a.dt = f32(20.0)
//a.render()
a.update(a.dt)
}
fn (mut a App) flip() {
println("app flip()")
C.SDL_RenderPresent(a.renderer)
}
fn (mut a App) update(dt f32) {
}