sdl.nim 1.2 KB

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