Beispiel #1
0
 def test_SDL_GetSetSurfaceColorMod(self):
     colormods = (
         (0, 0, 0),
         (32, 64, 128),
         (10, 20, 30),
         (1, 2, 4),
         (255, 255, 255),
         (128, 128, 128),
         (127, 127, 127),
     )
     bpp = c_int()
     rmask, gmask, bmask, amask = Uint32(), Uint32(), Uint32(), Uint32()
     for fmt in pixels.ALL_PIXELFORMATS:
         if pixels.SDL_ISPIXELFORMAT_FOURCC(fmt):
             continue
         ret = pixels.SDL_PixelFormatEnumToMasks(fmt, byref(bpp),
                                                 byref(rmask), byref(gmask),
                                                 byref(bmask), byref(amask))
         self.assertEqual(ret, SDL_TRUE)
         sf = surface.SDL_CreateRGBSurface(0, 10, 10, bpp, rmask, gmask,
                                           bmask, amask)
         for r, g, b in colormods:
             sr, sg, sb = Uint8(), Uint8(), Uint8()
             surface.SDL_SetSurfaceColorMod(sf, r, g, b)
             ret = surface.SDL_GetSurfaceColorMod(sf, byref(sr), byref(sg),
                                                  byref(sb))
             self.assertEqual(ret, 0)
             self.assertEqual((sr.value, sg.value, sb.value), (r, g, b))
         surface.SDL_FreeSurface(sf)
 def test_SDL_GetRGB(self):
     # TODO: invalid parameters
     pformat = pixels.SDL_AllocFormat(pixels.SDL_PIXELFORMAT_RGBA8888)
     self.assertIsInstance(pformat.contents, pixels.SDL_PixelFormat)
     r, g, b = Uint8(), Uint8(), Uint8()
     pixels.SDL_GetRGB(0xFFAA8811, pformat, byref(r), byref(g), byref(b))
     self.assertEqual((r.value, g.value, b.value), (0xFF, 0xAA, 0x88))
     pixels.SDL_GetRGB(0x00000000, pformat, byref(r), byref(g), byref(b))
     self.assertEqual((r.value, g.value, b.value), (0x00, 0x00, 0x00))
     pixels.SDL_GetRGB(0xFFFFFFFF, pformat, byref(r), byref(g), byref(b))
     self.assertEqual((r.value, g.value, b.value), (0xFF, 0xFF, 0xFF))
     pixels.SDL_GetRGB(0x11223344, pformat, byref(r), byref(g), byref(b))
     self.assertEqual((r.value, g.value, b.value), (0x11, 0x22, 0x33))
     pixels.SDL_FreeFormat(pformat)
     fmts = (pixels.SDL_PIXELFORMAT_INDEX1LSB,
             pixels.SDL_PIXELFORMAT_INDEX1MSB)
     for fmt in fmts:
         pformat = pixels.SDL_AllocFormat(fmt)
         self.assertIsInstance(pformat.contents, pixels.SDL_PixelFormat)
         pixels.SDL_GetRGB(0x11223344, pformat, byref(r), byref(g),
                           byref(b))
         self.assertEqual((r.value, g.value, b.value), (0xFF, 0xFF, 0xFF))
         pixels.SDL_GetRGB(0x00000000, pformat, byref(r), byref(g),
                           byref(b))
         # TODO: Seems to be always (0xFF, 0xFF, 0xFF)???
         # self.assertEqual(rgb,(0x00, 0x00, 0x00))
         pixels.SDL_FreeFormat(pformat)
     fmts = (pixels.SDL_PIXELFORMAT_INDEX4LSB,
             pixels.SDL_PIXELFORMAT_INDEX4MSB)
     for fmt in fmts:
         pformat = pixels.SDL_AllocFormat(fmt)
         self.assertIsInstance(pformat.contents, pixels.SDL_PixelFormat)
         # TODO
         pixels.SDL_FreeFormat(pformat)
Beispiel #3
0
    def test_SDL_GetSetTextureAlphaMod(self):
        window = video.SDL_CreateWindow(b"Test", 10, 10, 10, 10,
                                        video.SDL_WINDOW_HIDDEN)
        self.assertIsInstance(window.contents, video.SDL_Window)
        renderer = render.SDL_CreateRenderer(window, -1, self._RENDERFLAGS)
        self.assertIsInstance(renderer.contents, render.SDL_Renderer)

        tex = render.SDL_CreateTexture(renderer,
                                       pixels.SDL_PIXELFORMAT_ARGB8888,
                                       render.SDL_TEXTUREACCESS_STREAMING, 10,
                                       10)
        self.assertIsInstance(tex.contents, render.SDL_Texture)

        for alpha in range(0, 255):
            ret = render.SDL_SetTextureAlphaMod(tex, alpha)
            self.assertEqual(ret, 0)
            talpha = Uint8()
            ret = render.SDL_GetTextureAlphaMod(tex, byref(talpha))
            self.assertEqual(ret, 0)
            self.assertEqual(talpha.value, alpha)

        render.SDL_DestroyTexture(tex)
        #self.assertRaises(sdl.SDLError, render.SDL_SetTextureColorMod, tex,
        #                  10, 20, 30)
        #self.assertRaises(sdl.SDLError, render.SDL_GetTextureColorMod, tex)

        render.SDL_DestroyRenderer(renderer)
        video.SDL_DestroyWindow(window)
        dogc()
Beispiel #4
0
    def test_SDL_GetSetRenderDrawColor(self):
        failed = 0
        rcount = render.SDL_GetNumRenderDrivers()
        for i in range(rcount):
            window = video.SDL_CreateWindow(b"Test", 10, 10, 10, 10,
                                            video.SDL_WINDOW_HIDDEN)
            self.assertIsInstance(window.contents, video.SDL_Window)
            renderer = render.SDL_CreateRenderer(window, i, self._RENDERFLAGS)
            if not (renderer and renderer.contents):
                failed += 1
                video.SDL_DestroyWindow(window)
                continue
            self.assertIsInstance(renderer.contents, render.SDL_Renderer)

            colors = (
                (16, 22, 185, 217),
                (32, 64, 128, 255),
                (64, 32, 128, 255),
                (64, 32, 255, 128),
                (255, 32, 64, 128),
                (255, 32, 128, 64),
                (0, 0, 0, 0),
                (255, 255, 255, 255),
                (128, 128, 128, 255),
            )
            for r, g, b, a in colors:
                ret = render.SDL_SetRenderDrawColor(renderer, r, g, b, a)
                self.assertEqual(ret, 0)
                dr, dg, db, da = Uint8(), Uint8(), Uint8(), Uint8()
                ret = render.SDL_GetRenderDrawColor(renderer, byref(dr),
                                                    byref(dg), byref(db),
                                                    byref(da))
                self.assertEqual(ret, 0)
                self.assertEqual((dr.value, dg.value, db.value, da.value),
                                 (r, g, b, a))
            render.SDL_DestroyRenderer(renderer)
            #self.assertRaises(sdl.SDLError, render.SDL_SetRenderDrawColor,
            #                  renderer, 10, 20, 30, 40)
            #self.assertRaises(sdl.SDLError, render.SDL_GetRenderDrawColor,
            #                  renderer)
            video.SDL_DestroyWindow(window)
        self.assertFalse(failed == rcount, "could not create a renderer")
        dogc()
Beispiel #5
0
    def test_SDL_GetSetTextureColorMod(self):
        window = video.SDL_CreateWindow(b"Test", 10, 10, 10, 10,
                                        video.SDL_WINDOW_HIDDEN)
        self.assertIsInstance(window.contents, video.SDL_Window)
        renderer = render.SDL_CreateRenderer(window, -1, self._RENDERFLAGS)
        self.assertIsInstance(renderer.contents, render.SDL_Renderer)

        tex = render.SDL_CreateTexture(renderer,
                                       pixels.SDL_PIXELFORMAT_ARGB8888,
                                       render.SDL_TEXTUREACCESS_STREAMING, 10,
                                       10)
        self.assertIsInstance(tex.contents, render.SDL_Texture)
        colors = (
            (16, 22, 185),
            (32, 64, 128),
            (64, 32, 128),
            (64, 32, 255),
            (255, 32, 64),
            (255, 32, 128),
            (0, 0, 0),
            (255, 255, 255),
            (128, 128, 128),
        )
        for r, g, b in colors:
            ret = render.SDL_SetTextureColorMod(tex, r, g, b)
            self.assertEqual(ret, 0)
            tr, tg, tb = Uint8(), Uint8(), Uint8()
            ret = render.SDL_GetTextureColorMod(tex, byref(tr), byref(tg),
                                                byref(tb))
            self.assertEqual(ret, 0)
            self.assertEqual((tr.value, tg.value, tb.value), (r, g, b))

        render.SDL_DestroyTexture(tex)
        #self.assertRaises(sdl.SDLError, render.SDL_SetTextureColorMod, tex,
        #                  10, 20, 30)
        #self.assertRaises(sdl.SDLError, render.SDL_GetTextureColorMod, tex)

        render.SDL_DestroyRenderer(renderer)
        video.SDL_DestroyWindow(window)
        dogc()
Beispiel #6
0
 def test_SDL_GetSetSurfaceAlphaMod(self):
     bpp = c_int()
     rmask, gmask, bmask, amask = Uint32(), Uint32(), Uint32(), Uint32()
     for fmt in pixels.ALL_PIXELFORMATS:
         if pixels.SDL_ISPIXELFORMAT_FOURCC(fmt):
             continue
         ret = pixels.SDL_PixelFormatEnumToMasks(fmt, byref(bpp),
                                                 byref(rmask), byref(gmask),
                                                 byref(bmask), byref(amask))
         self.assertEqual(ret, SDL_TRUE)
         sf = surface.SDL_CreateRGBSurface(0, 10, 10, bpp, rmask, gmask,
                                           bmask, amask)
         salpha = Uint8()
         ret = surface.SDL_GetSurfaceAlphaMod(sf, byref(salpha))
         self.assertEqual(ret, 0)
         self.assertEqual(salpha.value, 255)
         for alpha in range(0, 255):
             ret = surface.SDL_SetSurfaceAlphaMod(sf, alpha)
             self.assertEqual(ret, 0)
             ret = surface.SDL_GetSurfaceAlphaMod(sf, byref(salpha))
             self.assertEqual(ret, 0)
             self.assertEqual(salpha.value, alpha)
         surface.SDL_FreeSurface(sf)