Shape Window not showing on desktop

Mihail Latyshov avatarMihail Latyshov created an issue

Hello,

I try to create a "tv overlay" for racing game

If i use c with mingw from this example http://www.libsdl.org/tmp/SDL/test/testshape.c shaped window shown like this

but if i try to do the same with python, window created and shaped, but not shown on desktop

my python code is:

import sys

try:
    import sdl2
    import sdl2.ext as sdl2ext
except ImportError:
    import traceback
    traceback.print_exc()
    sys.exit(1)

from sdl2.ext import Resources
RESOURCES = Resources(__file__, "resources")

class ShapeWindow(sdl2ext.Window):
    def __init__(self, title, size, position=None, flags=None):
        if position is None:
            position = self.DEFAULTPOS
        if flags is None:
            flags = self.DEFAULTFLAGS
        window = sdl2.SDL_CreateShapedWindow(sdl2ext.compat.byteify(title, "utf-8"),
                                             position[0], position[1],
                                             size[0], size[1], flags)
        if not window:
            raise SDLError()
        self.window = window.contents
        self._renderer = None

sdl2ext.init()

# window = sdl2ext.Window("Hello World!", size=(800, 500))
window = ShapeWindow("Hello World!", size=(800, 500))
window.show()

renderer = sdl2ext.RenderContext(window)
factory = sdl2ext.SpriteFactory(sdl2ext.TEXTURE, renderer=renderer)

circle_sf = sdl2ext.load_image(RESOURCES.get_path("circle2.bmp"))
circle = factory.from_surface(circle_sf)

shape_mode = sdl2.SDL_WindowShapeMode()
shape_mode.mode = sdl2.ShapeModeColorKey
shape_mode.parameters.colorKey = (0, 0, 0, 255)
sdl2.SDL_SetWindowShape(window.window, circle_sf, shape_mode)

spriterenderer = factory.create_sprite_renderer(window)
spriterenderer.render(circle)

processor = sdl2ext.TestEventProcessor()
processor.run(window)

sdl2ext.quit()

can you point me, what i'm doing wrong?

Comments (3)

  1. Marcus von Appen

    You must give the window a position on the screen. By default, a shape window is set with a position off-screen (-1000, -1000) by SDL2. It also must be made resizable via the flags.

    window = ShapeWindow("Hello World!", (800, 500), (200, 200), sdl2.SDL_WINDOW_RESIZABLE)
    

    Once done, after setting the window shape, you should set the size of the window to the size of the surface to render:

    sdl2.SDL_SetWindowShape(window.window, circle_sf, shape_mode)
    sdl2.SDL_SetWindowSize(window.window, circle.size[0], circle.size[1])
    
  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.