sdl.nim 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. when defined(Windows):
  2. const libName* = "SDL2.dll"
  3. elif defined(Linux):
  4. const libName* = "libSDL2.so"
  5. elif defined(MacOsX):
  6. const libName* = "libSDL2.dylib"
  7. type
  8. SdlWindow = object
  9. SdlWindowPtr* = ptr SdlWindow
  10. SdlRenderer = object
  11. SdlRendererPtr* = ptr SdlRenderer
  12. const INIT_VIDEO* = 0x00000020
  13. {.push dynlib: libName.}
  14. proc init*(flags: uint32): cint {.importc: "SDL_Init".}
  15. proc createWindowAndRenderer*(width, height: cint, window_flags: cuint,
  16. window: var SdlWindowPtr, renderer: var SdlRendererPtr): cint
  17. {.importc: "SDL_CreateWindowAndRenderer".}
  18. proc pollEvent*(event: pointer): cint {.importc: "SDL_PollEvent".}
  19. proc setDrawColor*(renderer: SdlRendererPtr, r, g, b, a: uint8): cint
  20. {.importc: "SDL_SetRenderDrawColor", discardable.}
  21. proc present*(renderer: SdlRendererPtr) {.importc: "SDL_RenderPresent".}
  22. proc clear*(renderer: SdlRendererPtr) {.importc: "SDL_RenderClear".}
  23. proc drawLines*(renderer: SdlRendererPtr, points: ptr tuple[x, y: cint],
  24. count: cint): cint {.importc: "SDL_RenderDrawLines", discardable.}
  25. {.pop.}