def main(): phrase = sys.argv[2] sdl.ttf.init() font = sdl.ttf.openFont(sys.argv[1], 72) rc = font.sizeUTF8(phrase) size = rc[1:] print(phrase) print(size) sdl.init(sdl.INIT_VIDEO) window = sdl.createWindow(phrase, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, size[0] + 20, size[1] + 20, sdl.WINDOW_SHOWN) renderer = sdl.createRenderer(window, -1, 0) renderer.setRenderDrawColor(0xff, 0xff, 0xff, 0xff) renderer.renderClear() text = font.renderUTF8_Blended(phrase, sdl.Color((0, 0, 0, 0xff)).cdata[0]) texture = renderer.createTextureFromSurface(text) # None means copy the whole texture: renderer.renderCopy(texture, None, (10, 10, size[0], size[1])) renderer.renderPresent() time.sleep(10) text.freeSurface() texture.destroyTexture() renderer.destroyRenderer() window.destroyWindow()
def init(self): sdl.init(sdl.INIT_EVERYTHING) sdl.image.init(sdl.image.INIT_PNG) sdl.ttf.init() self.window = sdl.createWindow(self.window_title, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, 1280, 720, sdl.WINDOW_HIDDEN) self.renderer = self.window.createRenderer(-1, sdl.RENDERER_PRESENTVSYNC)
def main(): """Prepare the display, load images, and get our programming running.""" global IMAGES, window, renderer os.environ["SDL_VIDEO_CENTERED"] = "True" sdl.init(sdl.INIT_VIDEO) try: window = sdl.createWindow(CAPTION.encode('utf-8'), sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, SCREEN_SIZE[0], SCREEN_SIZE[1], 0) window = sdl.Window(window) renderer = sdl.Renderer(sdl.createRenderer(window, -1, 0)) IMAGES = load_resources() Control().main_loop() finally: sdl.quit()
def __init__(self, title, width, height, x=POS_CENTERED, y=POS_CENTERED): # TODO: flag control self.handle = check(sdl.createWindow(title, x, y, width, height, sdl.WINDOW_OPENGL), "Could not create window") self.winid = sdl.getWindowID(self.handle) self.size = width, height _windows[self.winid] = self
def main(): event = sdl.Event() sdl.init(sdl.INIT_VIDEO) # Initialize test framework # state = SDLTest_CommonCreateState(argv, sdl.INIT_VIDEO) # if not state: # return 1 # for (i = 1; i < argc;) { # # consumed = SDLTest_CommonArg(state, i) # if consumed == 0: # sdl.Log("Usage: %s %s\n" % (argv[0], SDLTest_CommonUsage(state))) # return 1 # i += consumed # if not SDLTest_CommonInit(state): # quit(2) drawstates = [DrawState()] for i in range(len(drawstates)): drawstate = drawstates[i] drawstate.window = sdl.createWindow("Scale %d" % i, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, sdl.WINDOW_SHOWN) drawstate.renderer = sdl.createRenderer(drawstate.window, -1, 0) drawstate.sprite = LoadTexture(drawstate.renderer, "icon.bmp", True) drawstate.background = LoadTexture(drawstate.renderer, "sample.bmp", False) if not drawstate.sprite or not drawstate.background: quit(2) rc, format, access, w, h = sdl.queryTexture(drawstate.sprite) drawstate.sprite_rect.w = w drawstate.sprite_rect.h = h drawstate.scale_direction = 1 # Main render loop frames = 0 then = sdl.getTicks() done = 0 while not done: # Check for events frames += 1 while sdl.pollEvent(event): if event.type == sdl.QUIT: done = 1 for i in range(len(drawstates)): if not drawstates[i].window: continue Draw(drawstates[i]) # Print out some timing information now = sdl.getTicks() if now > then: fps = (frames * 1000) / (now - then) sys.stderr.write("%2.2f frames per second\n" % (fps)) # TODO for x in drawstates: free stuff quit(0) return 0
def run(): frames = 0 last_ticks = 0 sdl.init(sdl.INIT_VIDEO) window = sdl.createWindow( "TMX Render Example", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, 1280, # ignored for fs desktop 720, # ignored for fs desktop sdl.WINDOW_SHOWN) renderer = sdl.createRenderer(window, -1, flags=0) window = sdl.Window(window) width, height = window.getWindowSize() # Logical size: width = width // 2 height = height // 2 renderer.renderSetLogicalSize(width, height) try: map = tmxrender.TMXRender(sys.argv[1]) except: sys.stderr.write("Pass the path of a .tmx map as the first argument.") raise # Load the map's image data map.load(renderer) pos = [0, 0] k_up, k_down, k_left, k_right = (sdl.SCANCODE_UP, sdl.SCANCODE_DOWN, sdl.SCANCODE_LEFT, sdl.SCANCODE_RIGHT) class Hero(object): def __init__(self): self.x = 0 self.y = 0 hero = Hero() event = sdl.Event() running = True while running: renderer.setRenderDrawColor(0, 0, 0, 255) renderer.renderClear() while event.pollEvent(): if event.type == sdl.QUIT: running = False break elif event.type == sdl.KEYDOWN: keysym = event.key.keysym if (event.key.keysym.scancode == sdl.SCANCODE_ESCAPE or event.key.keysym.sym == sdl.K_q): running = False break # Movement with arrow keys keystate, keystate_length = sdl.getKeyboardState() hero.x += (-1 * keystate[k_left]) + (1 * keystate[k_right]) hero.y += (-1 * keystate[k_up]) + (1 * keystate[k_down]) # Draw the map under the centered hero position pos[0] = int(hero.x - width / 2) pos[1] = int(hero.y - height / 2) map.render(renderer, pos) renderer.renderPresent() # Keep track of frame rate frames += 1 ticks = sdl.getTicks() if ticks - last_ticks > 1000: last_ticks = ticks print("Frames: %s" % frames) frames = 0
def __init__(self): self.frame = 0 self.surface = point.Surface() d = self.d = self.surface.d self.data = self.surface.data self.keys_down = set() self.cursor = P(0, 0) self.cursor_move = P(0, 0) self.cursor_surface = 2 self.show_material = True self.show_bounds = True self.show_paths = True self.show_jogs = True self.show_headings = True self.show_scans = True self.show_path_meets_bound = True self.show_path_leaves_bound = True sdl.init(sdl.INIT_EVERYTHING) sdl.ttf.init() sdl.setHint("render_scale_quality", "linear") self.window = sdl.createWindow("Test", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, d.x, d.y, sdl.WINDOW_RESIZABLE) self.render = self.window.createRenderer(-1, sdl.RENDERER_ACCELERATED) # self.render = self.window.createRenderer(-1, sdl.RENDERER_TARGETTEXTURE) # self.frame_texture = self.render.createTexture(sdl.PIXELFORMAT_ARGB8888, sdl.TEXTUREACCESS_TARGET, d.x, d.y) # self.overlay_texture = self.render.createTexture(sdl.PIXELFORMAT_ARGB8888, sdl.TEXTUREACCESS_TARGET, d.x, d.y) self.animation_textures = [] for frame in range(9): texture = self.render.createTexture(sdl.PIXELFORMAT_ARGB8888, sdl.TEXTUREACCESS_STATIC, d.x, d.y) self.animation_textures.append(texture) self.animation_textures[0].setTextureBlendMode(sdl.BLENDMODE_NONE) self.animation_textures[1].setTextureBlendMode(sdl.BLENDMODE_BLEND) self.animation_textures[2].setTextureBlendMode(sdl.BLENDMODE_BLEND) self.animation_textures[3].setTextureBlendMode(sdl.BLENDMODE_BLEND) self.animation_textures[4].setTextureBlendMode(sdl.BLENDMODE_BLEND) self.animation_textures[5].setTextureBlendMode(sdl.BLENDMODE_BLEND) self.animation_textures[6].setTextureBlendMode(sdl.BLENDMODE_BLEND) self.animation_textures[7].setTextureBlendMode(sdl.BLENDMODE_BLEND) self.animation_textures[8].setTextureBlendMode(sdl.BLENDMODE_BLEND) self.render.setRenderTarget(sdl.ffi.NULL) self._io_event = sdl.Event() self.event_map = { sdl.KEYDOWN: (self.io_keydown, lambda e: e.key), sdl.KEYUP: (self.io_keyup, lambda e: e.key), sdl.MOUSEMOTION: (self.io_mousemotion, lambda e: e.motion), sdl.MOUSEBUTTONDOWN: (self.io_mousedown, lambda e: e.button), sdl.MOUSEBUTTONUP: (self.io_mouseup, lambda e: e.button), sdl.MOUSEWHEEL: (self.io_mousewheel, lambda e: e.wheel), sdl.QUIT: (self.io_quit, lambda e: e.quit), sdl.SYSWMEVENT: (self.io_syswm, lambda e: e.syswm), sdl.WINDOWEVENT: (self.io_window, lambda e: e.window), }