PySDL2 LockTexture and modify pixels

1

I can't find any valuable example of locking a texture and modifying pixels in PySDL2

Here's my code :

def run():
    sdl2.ext.init()
    window = SDL_CreateWindow(b"test" sdl2.SDL_WINDOWPOS_CENTERED, sdl2.SDL_WINDOWPOS_CENTERED, 1024, 768, sdl2.SDL_WINDOW_SHOWN)
    renderer = SDL_CreateRenderer(window, -1, sdl2.SDL_RENDERER_ACCELERATED)
    texture = SDL_CreateTexture(renderer, sdl2.SDL_PIXELFORMAT_RGB888, sdl2.SDL_TEXTUREACCESS_STREAMING, 1024, 768)
    surface = SDL_CreateRGBSurface(0, 128, 128, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000)

    running = True
    while running:
        events = sdl2.ext.get_events()
        for event in events:
            if event.type == sdl2.SDL_QUIT or event.type == sdl2.SDL_MOUSEBUTTONDOWN:
                running = False
                break

        sdl2.SDL_LockTexture(texture, None, ctypes.byref(ctypes.c_void_p(surface.contents.pixels)), ctypes.byref(ctypes.c_int(surface.contents.pitch)))

        #
        # How to change the pixels ???
        # surface.contents.pixels[0][0] = Color(0, 255, 255)


        sdl2.SDL_UnlockTexture(texture)

        # window.refresh()
        sdl2.SDL_RenderPresent(renderer)

    return 0

How to change pixels in surface.contents.pixels ?

Thx !

pysdl2
asked on Stack Overflow Jan 19, 2020 by iliak

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0