コード例 #1
0
ファイル: sdlttf_test.py プロジェクト: gdos/pgreloaded
 def test_init_quit(self):
     sdlttf.init()
     sdlttf.init()
     sdlttf.init()
     sdlttf.quit()
     sdlttf.quit()
     sdlttf.init()
コード例 #2
0
ファイル: gl.py プロジェクト: lxnt/fgtestbed
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
コード例 #3
0
ファイル: sdlttf_test.py プロジェクト: gdos/pgreloaded
 def setUp(self):
     if sys.version.startswith("3.1"):
         self.assertIsInstance = \
             lambda x, t: self.assertTrue(isinstance(x, t))
     sdl.init(0)
     sdlttf.init()