stdinc

    Dark Mode
Search:
Group by:

stdinc.nim

Procs

proc malloc*(size: csize_t): pointer {...}{.cdecl, importc: "SDL_malloc",
                                       dynlib: SDL2_LIB.}
Allocate memory with the same memory allocater that SDL uses.
proc calloc*(nmemb: csize_t; size: csize_t): pointer {...}{.cdecl,
    importc: "SDL_calloc", dynlib: SDL2_LIB.}
proc realloc*(mem: pointer; size: csize_t): pointer {...}{.cdecl,
    importc: "SDL_realloc", dynlib: SDL2_LIB.}
proc free*(mem: pointer) {...}{.cdecl, importc: "SDL_free", dynlib: SDL2_LIB.}
When SDL allocates memory that you have to free, free it with this procedure.

Converters

converter toCint*(x: int): cint
converter toInt*(x: uint8): int

Templates

template ptrMath*(body: untyped)

Pointer arithmetic. Could be used for pixels manipulation.

Example:

var surface = sdl.convertSurfaceFormat(
  sourceSurface, sdl.PixelFormat_RGBA8888, 0)
discard sdl.lockSurface(surface)
var pixels = cast[ptr uint32](surface.pixels)
let pitch = surface.pitch div 4
for y in 0..surface.h-1:
  for x in 0..pitch-1:
    ptrMath:                                #################
      pixels[x + y * pitch] = uint32(x * y) # Using ptrMath #
                                            #################
sdl.unlockSurface(surface)
template fourCC*(a, b, c, d: untyped): uint32
Define a four character code as a uint32.