sdl_test.nim 862 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. discard """
  2. action: compile
  3. """
  4. import os
  5. import sdl
  6. if sdl.init(INIT_VIDEO) == -1:
  7. quit("Couldn't initialise SDL")
  8. var window: SdlWindowPtr
  9. var renderer: SdlRendererPtr
  10. if createWindowAndRenderer(640, 480, 0, window, renderer) == -1:
  11. quit("Couldn't create a window or renderer")
  12. discard pollEvent(nil)
  13. renderer.setDrawColor 29, 64, 153, 255
  14. renderer.clear
  15. renderer.setDrawColor 255, 255, 255, 255
  16. when defined(c):
  17. # just to ensure code from NimInAction still works, but
  18. # the `else` branch would work as well in C mode
  19. var points = [
  20. (260'i32, 320'i32),
  21. (260'i32, 110'i32),
  22. (360'i32, 320'i32),
  23. (360'i32, 110'i32)
  24. ]
  25. else:
  26. var points = [
  27. (260.cint, 320.cint),
  28. (260.cint, 110.cint),
  29. (360.cint, 320.cint),
  30. (360.cint, 110.cint)
  31. ]
  32. renderer.drawLines(addr points[0], points.len.cint)
  33. renderer.present
  34. sleep(5000)