コード例 #1
0
    def test_SDL_GetSetRenderDrawBlendMode(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)

            modes = (
                blendmode.SDL_BLENDMODE_NONE,
                blendmode.SDL_BLENDMODE_ADD,
                blendmode.SDL_BLENDMODE_BLEND,
                blendmode.SDL_BLENDMODE_MOD,
            )
            for mode in modes:
                ret = render.SDL_SetRenderDrawBlendMode(renderer, mode)
                bmode = blendmode.SDL_BlendMode()
                ret = render.SDL_GetRenderDrawBlendMode(renderer, byref(bmode))
                self.assertEqual(ret, 0)
                self.assertEqual(bmode.value, mode)
            render.SDL_DestroyRenderer(renderer)
            #self.assertRaises(sdl.SDLError, render.SDL_SetRenderDrawBlendMode,
            #                  renderer, video.SDL_BLENDMODE_ADD)
            #self.assertRaises(sdl.SDLError, render.SDL_GetRenderDrawBlendMode,
            #                  renderer)
            video.SDL_DestroyWindow(window)
        self.assertFalse(failed == rcount, "could not create a renderer")
        dogc()
コード例 #2
0
    def test_SDL_GetSetTextureBlendMode(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)

        modes = (
            blendmode.SDL_BLENDMODE_NONE,
            blendmode.SDL_BLENDMODE_ADD,
            blendmode.SDL_BLENDMODE_BLEND,
            blendmode.SDL_BLENDMODE_MOD,
        )
        for mode in modes:
            ret = render.SDL_SetTextureBlendMode(tex, mode)
            self.assertEqual(ret, 0)
            tmode = blendmode.SDL_BlendMode()
            ret = render.SDL_GetTextureBlendMode(tex, byref(tmode))
            self.assertEqual(ret, 0)
            self.assertEqual(tmode.value, mode)

        render.SDL_DestroyTexture(tex)
        #self.assertRaises(sdl.SDLError, render.SDL_SetTextureBlendMode, tex,
        #                  modes[2])
        #self.assertRaises(sdl.SDLError, render.SDL_GetTextureBlendMode, tex)

        render.SDL_DestroyRenderer(renderer)
        video.SDL_DestroyWindow(window)
        dogc()
コード例 #3
0
ファイル: surface_test.py プロジェクト: hikaru1997/py-sdl2
 def test_SDL_GetSetSurfaceBlendMode(self):
     modes = (blendmode.SDL_BLENDMODE_NONE, blendmode.SDL_BLENDMODE_BLEND,
              blendmode.SDL_BLENDMODE_ADD, blendmode.SDL_BLENDMODE_MOD)
     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 mode in modes:
             smode = blendmode.SDL_BlendMode()
             ret = surface.SDL_SetSurfaceBlendMode(sf, mode)
             self.assertEqual(ret, 0)
             surface.SDL_GetSurfaceBlendMode(sf, byref(smode))
             self.assertEqual(smode.value, mode)
         surface.SDL_FreeSurface(sf)