def test_gl_create_delete_context(self): self.assertRaises((AttributeError, TypeError), video.gl_create_context, None) self.assertRaises((AttributeError, TypeError), video.gl_create_context, "Test") self.assertRaises((AttributeError, TypeError), video.gl_create_context, 1234) window = video.create_window("No OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_BORDERLESS) self.assertRaises(sdl.SDLError, video.gl_create_context, window) video.destroy_window(window) self.assertTrue(video.gl_load_library()) window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) video.gl_delete_context(ctx) video.destroy_window(window) window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) video.destroy_window(window) video.gl_delete_context(ctx) video.gl_unload_library()
def test_gl_get_set_swap_interval(self): self.assertRaises(ValueError, video.gl_set_swap_interval, None) self.assertRaises(ValueError, video.gl_set_swap_interval, "Test") self.assertRaises(ValueError, video.gl_set_swap_interval, 1234) # No current OpenGL context yet. # Might crash on certain platforms, since the internal state of # SDL2 does not support calling GL functions without having a # GL library loaded. # self.assertRaises(sdl.SDLError, video.gl_set_swap_interval, 1) # self.assertRaises(sdl.SDLError, video.gl_set_swap_interval, 0) self.assertTrue(video.gl_load_library()) window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) video.gl_make_current(window, ctx) video.gl_set_swap_interval(0) self.assertEqual(video.gl_get_swap_interval(), 0) video.gl_set_swap_interval(1) self.assertEqual(video.gl_get_swap_interval(), 1) video.gl_delete_context(ctx) video.destroy_window(window) video.gl_unload_library()
def test_gl_get_set_attribute(self): self.assertRaises(sdl.SDLError, video.gl_get_attribute, video.SDL_GL_DEPTH_SIZE) self.assertRaises(sdl.SDLError, video.gl_set_attribute, 1455, 24) self.assertTrue(video.gl_load_library()) window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) depth = video.gl_get_attribute(video.SDL_GL_DEPTH_SIZE) video.gl_delete_context(ctx) video.destroy_window(window) newdepth = 24 if depth == 8: newdepth = 16 elif depth == 16: newdepth = 24 elif depth == 24: newdepth = 16 video.gl_set_attribute(video.SDL_GL_DEPTH_SIZE, newdepth) window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) val = video.gl_get_attribute(video.SDL_GL_DEPTH_SIZE) self.assertNotEqual(depth, val) self.assertEqual(val, newdepth) video.gl_delete_context(ctx) video.destroy_window(window) video.gl_unload_library()
def test_gl_extension_supported(self): self.assertFalse(video.gl_extension_supported("GL_EXT_bgra")) self.assertTrue(video.gl_load_library()) window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) self.assertTrue(video.gl_extension_supported("GL_EXT_bgra")) video.gl_delete_context(ctx) video.destroy_window(window) video.gl_unload_library() self.assertFalse(video.gl_extension_supported("GL_EXT_bgra"))
def test_gl_get_proc_address(self): procaddr = video.gl_get_proc_address("glGetString") self.assertIsNone(procaddr) self.assertTrue(video.gl_load_library()) # Behaviour is undefined as long as there is no window and context. window = video.create_window("OpenGL", 10, 10, 10, 10, video.SDL_WINDOW_OPENGL) ctx = video.gl_create_context(window) procaddr = video.gl_get_proc_address("glGetString") self.assertTrue(procaddr is not None and int(procaddr) != 0) procaddr = video.gl_get_proc_address("glForWhackoPeople") self.assertIsNone(procaddr) video.gl_delete_context(ctx) video.destroy_window(window) video.gl_unload_library() procaddr = video.gl_get_proc_address("glGetString") self.assertIsNone(procaddr)
def sdl_init(size=(1280, 800), title = "DFFG testbed", icon = None, gldebug=False, fwdcore=False): log = logging.getLogger('fgt.sdl_init') sdlhints.set_hint(SDL_HINT_RENDER_DRIVER, 'software') # do not need no renderer sdlhints.set_hint(SDL_HINT_FRAMEBUFFER_ACCELERATION, '0') # do not need no window surface sdl.init(sdl.SDL_INIT_VIDEO | sdl.SDL_INIT_NOPARACHUTE) cflags = 0 cmask = 0 fwdcore = False # mesa doesn't support it :( if fwdcore: cflags |= SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG cmask |= SDL_GL_CONTEXT_PROFILE_CORE else: cmask |= SDL_GL_CONTEXT_PROFILE_COMPATIBILITY if gldebug: cflags |= SDL_GL_CONTEXT_DEBUG_FLAG gl_attrs = ( (SDL_GL_RED_SIZE, "SDL_GL_RED_SIZE", 8), (SDL_GL_GREEN_SIZE, "SDL_GL_GREEN_SIZE", 8), (SDL_GL_BLUE_SIZE, "SDL_GL_BLUE_SIZE", 8), (SDL_GL_ALPHA_SIZE, "SDL_GL_ALPHA_SIZE", 8), (SDL_GL_DEPTH_SIZE, "SDL_GL_DEPTH_SIZE", 0), (SDL_GL_STENCIL_SIZE, "SDL_GL_STENCIL_SIZE", 0), (SDL_GL_DOUBLEBUFFER, "SDL_GL_DOUBLEBUFFER", 1), (SDL_GL_CONTEXT_MAJOR_VERSION, "SDL_GL_CONTEXT_MAJOR_VERSION", 3), (SDL_GL_CONTEXT_MINOR_VERSION, "SDL_GL_CONTEXT_MINOR_VERSION", 0), (SDL_GL_CONTEXT_PROFILE_MASK, "SDL_GL_CONTEXT_PROFILE_MASK", cmask), (SDL_GL_CONTEXT_FLAGS, "SDL_GL_CONTEXT_FLAGS", cflags), ) for attr, name, val in gl_attrs: log.debug("requesting {} [{}] = {}".format(name, attr, val)) sdlvideo.gl_set_attribute(attr, val) window = sdlvideo.create_window(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, size[0], size[1], SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE) if icon: sdlvideo.set_window_icon(window, icon) context = sdlvideo.gl_create_context(window) gldumplog("just after context", logger=log) # this catches PyOpenGL's try: glGetString() except: glGetStringiv() unsanity for attr, name, val in gl_attrs: got = sdlvideo.gl_get_attribute(attr) log.debug("{} requested {} got {}".format(name, val, got)) try: log.info("glGet: vers = {}.{} flags={} " .format( glGetInteger(GL_MAJOR_VERSION), glGetInteger(GL_MINOR_VERSION), glGetInteger(GL_CONTEXT_FLAGS))) except KeyError: pass if not fwdcore: glEnable(GL_POINT_SPRITE) glEnable(GL_VERTEX_PROGRAM_POINT_SIZE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glDisable(GL_DEPTH_TEST) sdlttf.init() sdlimage.init() return window, context