當前位置: 首頁>>代碼示例>>Python>>正文


Python sdl2.SDL_CreateWindow方法代碼示例

本文整理匯總了Python中sdl2.SDL_CreateWindow方法的典型用法代碼示例。如果您正苦於以下問題:Python sdl2.SDL_CreateWindow方法的具體用法?Python sdl2.SDL_CreateWindow怎麽用?Python sdl2.SDL_CreateWindow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sdl2的用法示例。


在下文中一共展示了sdl2.SDL_CreateWindow方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _create_handles

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_CreateWindow [as 別名]
def _create_handles(window_title, window_position, window_size, window_flags,
                    renderer_info):
    """Create the SDL2 handles."""
    window_flags = sdl2.SDL_WINDOW_SHOWN | window_flags
    if renderer_info.api == GraphicsAPI.OPENGL:
        window_flags |= sdl2.SDL_WINDOW_OPENGL
        window = sdl2.SDL_CreateWindow(
            window_title.encode(),
            window_position.x, window_position.y,
            window_size.x, window_size.y,
            window_flags)
        if not window:
            raise RuntimeError(sdl2.SDL_GetError().decode())

        context = sdl2.SDL_GL_CreateContext(window)
        if not context:
            raise RuntimeError(sdl2.SDL_GetError().decode())

        # Try to disable the vertical synchronization. It applies to the active
        # context and thus needs to be called after `SDL_GL_CreateContext`.
        sdl2.SDL_GL_SetSwapInterval(0)

        return _Handles(
            window=window,
            renderer=_GLHandles(context=context)) 
開發者ID:christophercrouzet,項目名稱:hienoi,代碼行數:27,代碼來源:gui.py

示例2: open

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_CreateWindow [as 別名]
def open(self, configuration):
        '''Open the SDL2 Window

        *Parameters:*

        - `configuration`: Configurations parameters from Application
        '''
        if sdl2.SDL_InitSubSystem(sdl2.SDL_INIT_VIDEO) != 0:
            msg = "Can't open window: %s" % sdl2.SDL_GetError()
            logger.critical(msg)
            raise SDL2Error(msg)

        flags = 0
        if configuration.fullscreen and \
           configuration.width and configuration.height:
            flags |= sdl2.SDL_WINDOW_FULLSCREEN
        elif configuration.fullscreen:
            flags |= sdl2.SDL_WINDOW_FULLSCREEN_DESKTOP
        if not configuration.decorated:
            flags |= sdl2.SDL_WINDOW_BORDERLESS
        if configuration.resizable:
            flags |= sdl2.SDL_WINDOW_RESIZABLE
        if configuration.highdpi:
            flags |= sdl2.SDL_WINDOW_ALLOW_HIGHDPI

        self.window = sdl2.SDL_CreateWindow(
            configuration.name.encode('ascii'), configuration.x,
            configuration.y, configuration.width, configuration.height, flags)

        if not self.window:
            msg = "Can't open window: %s" % sdl2.SDL_GetError()
            logger.critical(msg)
            raise SDL2Error(msg)

        logger.debug("SDL2 window opened with configuration: %s",
                     (configuration,))

        self.info = sdl2.SDL_SysWMinfo()
        sdl2.SDL_VERSION(self.info.version)
        sdl2.SDL_GetWindowWMInfo(self.window, ctypes.byref(self.info)) 
開發者ID:realitix,項目名稱:vulk,代碼行數:42,代碼來源:context.py

示例3: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_CreateWindow [as 別名]
def run():
    sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO)
    window = sdl2.SDL_CreateWindow(b"Hello World",
                                   sdl2.SDL_WINDOWPOS_CENTERED,
                                   sdl2.SDL_WINDOWPOS_CENTERED,
                                   592, 460, sdl2.SDL_WINDOW_SHOWN)
    fname = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         "resources", "hello.bmp")
    image = sdl2.SDL_LoadBMP(fname.encode("utf-8"))
    windowsurface = sdl2.SDL_GetWindowSurface(window)
    sdl2.SDL_BlitSurface(image, None, windowsurface, None)
    sdl2.SDL_UpdateWindowSurface(window)
    sdl2.SDL_FreeSurface(image)

    running = True
    event = sdl2.SDL_Event()
    while running:
        while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
            if event.type == sdl2.SDL_QUIT:
                running = False
                break
        sdl2.SDL_Delay(10)

    sdl2.SDL_DestroyWindow(window)
    sdl2.SDL_Quit()
    return 0 
開發者ID:marcusva,項目名稱:py-sdl2,代碼行數:28,代碼來源:sdl2hello.py

示例4: createWindow

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_CreateWindow [as 別名]
def createWindow(self):
		# Create the window context
		if sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) != 0:
			print(sdl2.SDL_GetError())
			return -1
		sdl2ttf.TTF_Init()
		sdl2img.IMG_Init(sdl2img.IMG_INIT_PNG)

		self.window = sdl2.SDL_CreateWindow(self.params["title"].encode(),
					   sdl2.SDL_WINDOWPOS_UNDEFINED,
					   sdl2.SDL_WINDOWPOS_UNDEFINED,
					   self.window_width,
					   self.window_height,
					   sdl2.SDL_WINDOW_OPENGL)
		sdl2.SDL_SetWindowBordered(self.window, self.show_borders)
		if not self.window:
			print(sdl2.SDL_GetError())
			return -1

		# Renderer
		self.renderer = sdl2.SDL_CreateRenderer(self.window, -1,
			sdl2.SDL_RENDERER_ACCELERATED|sdl2.SDL_RENDERER_PRESENTVSYNC)

		# Build the GUI
		self.buildElements()

		# onStart handler
		if self.onStart is not None:
			if self.onStart[1] is None:
				self.onStart[0]()
			else:
				self.onStart[0](self.onStart[1])

		# look for events
		self._loopForEvents() 
開發者ID:Romaingin,項目名稱:Antlia,代碼行數:37,代碼來源:renderer.py

示例5: _get_window

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_CreateWindow [as 別名]
def _get_window(self):
        return sdl2.SDL_CreateWindow(
            self.name.encode(),
            sdl2.SDL_WINDOWPOS_CENTERED,
            sdl2.SDL_WINDOWPOS_CENTERED,
            self.props.get('width'),
            self.props.get('height'),
            self.props.get('window_flags', 0)) 
開發者ID:cecton,項目名稱:pysdl2-sdl2ui,代碼行數:10,代碼來源:app.py

示例6: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_CreateWindow [as 別名]
def run():
    if sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) != 0:
        print(sdl2.SDL_GetError())
        return -1

    window = sdl2.SDL_CreateWindow(b"OpenGL demo",
                                   sdl2.SDL_WINDOWPOS_UNDEFINED,
                                   sdl2.SDL_WINDOWPOS_UNDEFINED, 800, 600,
                                   sdl2.SDL_WINDOW_OPENGL)
    if not window:
        print(sdl2.SDL_GetError())
        return -1

    context = sdl2.SDL_GL_CreateContext(window)

    GL.glMatrixMode(GL.GL_PROJECTION | GL.GL_MODELVIEW)
    GL.glLoadIdentity()
    GL.glOrtho(-400, 400, 300, -300, 0, 1)

    x = 0.0
    y = 30.0

    event = sdl2.SDL_Event()
    running = True
    while running:
        while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
            if event.type == sdl2.SDL_QUIT:
                running = False

        GL.glClearColor(0, 0, 0, 1)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT)
        GL.glRotatef(10.0, 0.0, 0.0, 1.0)
        GL.glBegin(GL.GL_TRIANGLES)
        GL.glColor3f(1.0, 0.0, 0.0)
        GL.glVertex2f(x, y + 90.0)
        GL.glColor3f(0.0, 1.0, 0.0)
        GL.glVertex2f(x + 90.0, y - 90.0)
        GL.glColor3f(0.0, 0.0, 1.0)
        GL.glVertex2f(x - 90.0, y - 90.0)
        GL.glEnd()

        sdl2.SDL_GL_SwapWindow(window)
        sdl2.SDL_Delay(10)
    sdl2.SDL_GL_DeleteContext(context)
    sdl2.SDL_DestroyWindow(window)
    sdl2.SDL_Quit()
    return 0 
開發者ID:marcusva,項目名稱:py-sdl2,代碼行數:49,代碼來源:opengl.py


注:本文中的sdl2.SDL_CreateWindow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。