Issue #39 resolved

TextureSpriteRenderer has no attribute 'renderer'

harradrush
created an issue

TextureSpriteRenderer has no attribute 'renderer', that make it incompatible with SpriteFactory, for example. Instead, it named as 'sdlrenderer'. Why so?

Comments (6)

  1. harradrush reporter
    import sdl2.ext as sdl2ext
    
    sdl2ext.init()
    
    window = sdl2ext.Window('', size=(640, 480))
    window.show()
    
    renderer = sdl2ext.TextureSpriteRenderer(window)
    #renderer.renderer = renderer.sdlrenderer #this is workaround I use
    spriteFactory = sdl2ext.SpriteFactory(sprite_type=sdl2ext.TEXTURE, renderer=renderer)
    
    sprite = spriteFactory.from_color(sdl2ext.convert_to_color((255, 0, 0, 0)), (32, 32))
    renderer.render(sprite)
    
    sdl2ext.TestEventProcessor().run(window)
    sdl2ext.quit()
    

    This code gives an error:

      File "D:\programming\PyCharm\virtualenv\Python_2.7.6_with_libs\lib\site-packages\sdl2\ext\sprite.py", line 465, in from_color
        return self.from_surface(sf, True)
      File "D:\programming\PyCharm\virtualenv\Python_2.7.6_with_libs\lib\site-packages\sdl2\ext\sprite.py", line 415, in from_surface
        texture = render.SDL_CreateTextureFromSurface(renderer.renderer,
    AttributeError: 'TextureSpriteRenderer' object has no attribute 'renderer'
    

    With workaround it works with no problem.

  2. Marcus von Appen repo owner

    The SpriteFactory requires a SDL_Renderer or RenderContext as argument to its renderer flag.

    The TextureSpriteRenderer and SoftwareSpriterRenderer classes are not suitable for that, since they actually provide high-level functionality on top of the factory and renderers.

    I should rename those to be more clear about that.

  3. harradrush reporter

    Oh, thanks. So, should I use something like that in such cases?

    context = sdl2ext.RenderContext(window)
    renderer = sdl2ext.TextureSpriteRenderer(context)
    spriteFactory = sdl2ext.SpriteFactory(sprite_type=sdl2ext.TEXTURE, renderer=context)
    
  4. Marcus von Appen repo owner

    Correct. You won't need an explicit TextureSpriteRenderer, though, since the RenderContext implicitly creates one, which is accessible via context.renderer on demand.

  5. Marcus von Appen repo owner
    • fixed issue #36 and #39: the different render classes of sdl2.ext.sprite were renamed
    • the sdl2.ext.RenderContext class was renamed to sdl2.ext.Renderer to be consistent with with SDL2's naming scheme
    • sdl2.ext.SpriteRenderer was renamed to sdl2.ext.SpriteRenderSystem
    • sdl2.ext.SoftwareSpriteRenderer was renamed to sdl2.ext.SoftwareSpriteRenderSystem
    • sdl2.ext.TextureSpriteRenderer was renamed to sdl2.ext.TextureSpriteRenderSystem

    → <<cset d7246b14e4c6>>

  6. Log in to comment