Figure out how to draw on the sdl2 window

[?]
Jul 2, 2021, 5:44 AM
IGYI5RVVRFQUQBDH6KQ2MH6ADCZ455Z634BRXKLCEYFF4ZKQ3TMQC

Dependencies

  • [2] ZRPV3GAJ Model trainer: Add function to make tensor of cartesian coordinates for drawing the map (equirectangular projection)
  • [*] ROQCAPZJ Begin function for showing the map (for now just opens SDL window)

Change contents

  • edit in trainmodel/src/drawmap.py at line 1
    [4.13]
    [2.0]
    import ctypes
  • edit in trainmodel/src/drawmap.py at line 14
    [4.235]
    [4.235]
    windowsurface = ctypes.pointer(window.get_surface())
    test_tensor = tf.constant([[[0,0,255]] * 1024] * 512)
    image = tensor_to_surface(test_tensor)
    sdl2.SDL_BlitSurface(image, None, windowsurface, None)
    window.refresh()
    sdl2.SDL_FreeSurface(image)
  • edit in trainmodel/src/drawmap.py at line 40
    [2.407]
    # TODO: refactor to only do a few pixels at a time because python is really slow
    # Keeping this function here in the meantime because it wasn't easy to figure
    # out how to write it.
    def tensor_to_surface(source):
    shape = source.shape
    height = shape[0]
    width = shape[1]
    surface = sdl2.surface.SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0)
    pixels = sdl2.ext.pixels2d(surface.contents, False)
    # pixels are 4 bytes: b g r 0
    for y in range(0,height):
    row = source[y]
    d_row = pixels[y]
    for x in range(0,width):
    pixel = row[x]
    d_row[x] = pixel[0] * 65536 + pixel[1] * 256 + pixel[2]
    print(y)
    return surface