1. # draw lines on the current rendering target (raw SDL2 version)
  2.  
  3. from sdl2 import *
  4. from ctypes import *
  5. import sdl2.ext
  6.  
  7. # initialize
  8. SDL_Init(SDL_INIT_VIDEO)
  9.  
  10. # create window
  11. win = SDL_CreateWindow(b"RenderDrawLines",
  12.     SDL_WINDOWPOS_CENTERED,
  13.     SDL_WINDOWPOS_CENTERED,
  14.     640, 480, SDL_WINDOW_SHOWN)
  15.  
  16. # create renderer
  17. renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)
  18.  
  19. # fill background with white
  20. SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE)
  21. SDL_RenderClear(renderer)
  22.  
  23. # draw a black line
  24. SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE)
  25.  
  26. # create python list of SDL_Points
  27. points = [SDL_Point(0,0), SDL_Point(640,480)]
  28.  
  29. # convert SDL_Point list to SDL_Point C array
  30. cnt = len(points)
  31. pointsArray = pointer((SDL_Point * cnt)())
  32. for i in range(cnt):
  33.   pointsArray.contents[i] = points[i]
  34.  
  35. SDL_RenderDrawLines(renderer, pointsArray.contents[0], cnt)
  36.  
  37. # show
  38. SDL_RenderPresent(renderer)
  39.  
  40. # run event loop
  41. running = True
  42. while running:
  43.   events = sdl2.ext.get_events()
  44.   for event in events:
  45.     if event.type == SDL_QUIT:
  46.       running = False
  47.       break
  48.   SDL_Delay(40)
  49.  
  50. # clean up
  51. SDL_DestroyRenderer(renderer)
  52. SDL_DestroyWindow(win)
  53. SDL_Quit()
  54.  
[raw code]