Example #1
0
    def test_load_texture(self):
        sf = surface.create_rgb_surface(10, 10, 32)
        rd = render.create_software_renderer(sf)

        fname = "surfacetest.%s"
        for fmt in formats:
            filename = RESOURCES.get_path(fname % fmt)
            tex = sdlimage.load_texture(rd, filename)
            self.assertIsInstance(tex, render.SDL_Texture)
            render.destroy_texture(tex)

        self.assertRaises(sdl.SDLError, sdlimage.load_texture, rd, RESOURCES.get_path("rwopstest.txt"))

        self.assertRaises(sdl.SDLError, sdlimage.load_texture, rd, None)
        self.assertRaises(sdl.SDLError, sdlimage.load_texture, rd, 1234)
        self.assertRaises(
            (AttributeError, TypeError), sdlimage.load_texture, None, RESOURCES.get_path("surfacetest.bmp")
        )
        self.assertRaises(
            (AttributeError, TypeError), sdlimage.load_texture, "Test", RESOURCES.get_path("surfacetest.bmp")
        )
        self.assertRaises(
            (AttributeError, TypeError), sdlimage.load_texture, 1234, RESOURCES.get_path("surfacetest.bmp")
        )

        render.destroy_renderer(rd)
        surface.free_surface(sf)
Example #2
0
 def test_render_draw_point(self):
     points = ((-4, -3), (-4, 3), (4, -3),
               (0, 0), (1, 1), (10, 10), (99, 99),
               (4, 22), (57, 88), (45, 15),
               (100, 100)
               )
     r, g, b, a = 0xAA, 0xBB, 0xCC, 0xDD
     w, h = 100, 100
     sf = surface.create_rgb_surface(w, h, 32, 0xFF000000, 0x00FF0000,
                                     0x0000FF00, 0x000000FF)
     color = pixels.map_rgba(sf.format, r, g, b, a)
     renderer = render.create_software_renderer(sf)
     render.set_render_draw_color(renderer, r, g, b, a)
     for x, y in points:
         render.render_draw_point(renderer, x, y)
     render.render_present(renderer)
     view = pvid.PixelView(sf)
     for x, y in points:
         npx = max(x + 1, w)
         npy = max(y + 1, h)
         ppx = max(x - 1, 0)
         ppy = max(y - 1, 0)
         if x < 0 or x >= w or y < 0 or y >= h:
             continue
         self.assertEqual(hex(view[y][x]), hex(color))
         if (npx, npy) not in points:
             self.assertNotEqual(hex(view[npy][npx]), hex(color))
         if (ppx, ppy) not in points:
             self.assertNotEqual(hex(view[ppy][ppx]), hex(color))
     render.destroy_renderer(renderer)
     del view
     surface.free_surface(sf)
Example #3
0
    def test_load_texture_typed_rw(self):
        sf = surface.create_rgb_surface(10, 10, 32)
        rd = render.create_software_renderer(sf)

        fname = "surfacetest.%s"
        for fmt in formats:
            fp = RESOURCES.get(fname % fmt)
            tex = sdlimage.load_texture_typed_rw(rd, rwops.rw_from_object(fp), False, fmt.upper())
            self.assertIsInstance(tex, render.SDL_Texture)
            render.destroy_texture(tex)
        render.destroy_renderer(rd)
        surface.free_surface(sf)
Example #4
0
    def test_create_software_renderer(self):
        sf = surface.create_rgb_surface(100, 100, 32, 0xFF000000, 0x00FF0000,
                                        0x0000FF00, 0x000000FF)
        renderer = render.create_software_renderer(sf)
        self.assertIsInstance(renderer, render.SDL_Renderer)
        render.destroy_renderer(renderer)
        surface.free_surface(sf)

        self.assertRaises((AttributeError, TypeError),
                          render.create_software_renderer, None)
        self.assertRaises((AttributeError, TypeError),
                          render.create_software_renderer, 1234)
Example #5
0
    def __init__(self, target, index=-1, flags=render.SDL_RENDERER_ACCELERATED):
        """Creates a new RenderContext for the given target.

        If target is a Window or SDL_Window, index and flags are passed
        to the relevant sdl.render.create_renderer() call. If target is
        a SoftwareSprite or SDL_Surface, the index and flags arguments are
        ignored.
        """
        self.renderer = None
        self.rendertaget = None
        if isinstance(target, Window):
            self.renderer = render.create_renderer(target.window, index, flags)
            self.rendertarget = target.window
        elif isinstance(target, video.SDL_Window):
            self.renderer = render.create_renderer(target, index, flags)
            self.rendertarget = target
        elif isinstance(target, SoftwareSprite):
            self.renderer = render.create_software_renderer(target.surface)
            self.rendertarget = target.surface
        elif isinstance(target, sdlsurface.SDL_Surface):
            self.renderer = render.create_software_renderer(target)
            self.rendertarget = target
        else:
            raise TypeError("unsupported target type")
Example #6
0
    def test_load_texture_rw(self):
        sf = surface.create_rgb_surface(10, 10, 32)
        rd = render.create_software_renderer(sf)

        fname = "surfacetest.%s"
        for fmt in formats:
            if fmt == "tga":
                # SDL_image does not support loading TGA via
                # IMG_LoadTexture_RW()
                continue
            fp = RESOURCES.get(fname % fmt)
            tex = sdlimage.load_texture_rw(rd, rwops.rw_from_object(fp), False)
            self.assertIsInstance(tex, render.SDL_Texture)
            render.destroy_texture(tex)

        render.destroy_renderer(rd)
        surface.free_surface(sf)