sdl - Nim and SDL2 trouble with Rect -
i have following nim+official libsdl2 wrapper code
import sdl2 discard sdl2.init(init_everything) let window = createwindow("tic-tac-toe", sdl_windowpos_centered, sdl_windowpos_centered, 600, 390, sdl_window_shown) renderer = createrenderer(window, -1, renderer_accelerated or renderer_presentvsync or renderer_targettexture) proc loadimage(file: string): textureptr = let loadedimage = loadbmp(file) let texture = createtexturefromsurface(renderer, loadedimage) freesurface(loadedimage) return texture proc applysurface(x: cint, y: cint, tex: textureptr, rend: rendererptr) = var pos: rect pos.x = x pos.y = y querytexture(tex, nil, nil, pos.w, pos.h) copy(rend, tex, nil, pos) let background = loadimage("resources/bg.bmp") clear(renderer) applysurface(0, 0, background, renderer) present(renderer) var evt = sdl2.defaultevent rungame = true while rungame: while pollevent(evt): if evt.kind == quitevent: rungame = false break destroy window
and there error during compilation:
source.nim(19, 15) error: type mismatch: got (textureptr, nil, nil, cint, cint) expected 1 of: sdl2.querytexture(texture: textureptr, format: ptr uint32, access: ptr cint, w: ptr cint, h: ptr cint)
same 20th line:
source.nim(20, 7) error: type mismatch: got (rendererptr, textureptr, nil, rect) expected 1 of: system.copy(s: string, first: int) system.copy(s: string, first: int, last: int) sdl2.copy(renderer: rendererptr, texture: textureptr, srcrect: ptr rect, dstrect: ptr rect)
if replace pos nil in copy() , comment querytexture(), okay. please, me solve problem.
your problem procs require ptr
respective data types, not data itself. instance ptr cint
required, passing plain cint
. have take addr
of cint
ptr cint
. example:
var w = pos.w var h = pos.h querytexture(tex, nil, nil, w.addr, h.addr)
note in order "take address" need variable of var
type (for details on see this question). since pos
var
, pos.w.addr
, pos.h.addr
should work. have take pos.addr
last parameter of copy
.
Comments
Post a Comment