def renderImage(image, ren): # create all the blocks frame = sdl2.SDL_CreateTexture(ren.sdlrenderer, sdl2.SDL_PIXELFORMAT_ABGR8888, sdl2.SDL_TEXTUREACCESS_STATIC, 64, 48) pixels = bytearray() col = image[0] # first value is whether black or not for val in image[2:]: for count in range(val + 1): if col: pixels.append(0xff) pixels.append(0xff) pixels.append(0xff) pixels.append(0xff) else: pixels.append(0) pixels.append(0) pixels.append(0) pixels.append(0) col = not col pointer = (ctypes.c_char * len(pixels)).from_buffer(pixels) sdl2.SDL_UpdateTexture(frame, None, pointer, 64 * 4) # draw the frame sdl2.SDL_RenderCopy(ren.sdlrenderer, frame, sdl2.SDL_Rect(0, 0, 64, 48), sdl2.SDL_Rect(128, 0, 128, 96)) sdl2.SDL_DestroyTexture(frame)
def draw_rects(renderer): global current_alpha, current_color, cycle_direction rect = sdl2.SDL_Rect() viewport = sdl2.SDL_Rect() sdl2.SDL_RenderGetViewport(renderer, ctypes.byref(viewport)) for i in range(0, NUM_OBJECTS): current_color = current_color + cycle_direction if current_color < 0: current_color = 0 cycle_direction = -cycle_direction if current_color > 255: current_color = 255 cycle_direction = -cycle_direction sdl2.SDL_SetRenderDrawColor(renderer, 255, current_color, current_color, current_alpha) rect.w = (int(random.random() * 65535) % int(viewport.h / 2)) rect.h = (int(random.random() * 65535) % int(viewport.h / 2)) rect.x = ((int(random.random() * 65535) % (viewport.w * 2)) - viewport.w) - int(rect.w / 2) rect.y = ((int(random.random() * 65535) % (viewport.h * 2)) - viewport.h) - int(rect.h / 2) sdl2.SDL_RenderFillRect(renderer, ctypes.byref(rect))
def renderImage(image, blocks, ren): # create all the blocks ren_blocks = [] for block in blocks: ren_block = sdl2.SDL_CreateTexture(ren.sdlrenderer, sdl2.SDL_PIXELFORMAT_ABGR8888, sdl2.SDL_TEXTUREACCESS_STATIC, 8, 8) pixels = bytearray() for p in range(64): if block[p] == 1: pixels.append(0xff) pixels.append(0xff) pixels.append(0xff) pixels.append(0xff) else: pixels.append(0) pixels.append(0) pixels.append(0) pixels.append(0) pointer = (ctypes.c_char * len(pixels)).from_buffer(pixels) sdl2.SDL_UpdateTexture(ren_block, None, pointer, 8 * 4) ren_blocks.append(ren_block) # draw the image from the blocks for y in range(12): for x in range(16): texture = ren_blocks[image[y * 16 + x]] # texture=ren_blocks[0] sdl2.SDL_RenderCopy(ren.sdlrenderer, texture, sdl2.SDL_Rect(0, 0, 8, 8), sdl2.SDL_Rect(128 + x * 8, y * 8, 8, 8))
def reprocessImage(file, ren, all_blocks): surface = sdl_image.IMG_Load(file.encode("utf-8")) pixels = sdl2.ext.PixelView(surface.contents) image = Image() texture = sdl2.SDL_CreateTextureFromSurface(ren.sdlrenderer, surface) for y in range(0, 6): for x in range(0, 8): this_block = Block.fromPixels(pixels, x, y) # find match for block best_match = 64 match_index = -1 for index in range(len(all_blocks)): match = this_block.diffWithTolerance(all_blocks[index], best_match) if match <= best_match: # found best match so far match_index = index best_match = match if best_match == 0: # perfect match found so break # don't look further if match_index >= 0: image.append(match_index) # store best match else: print("no match found within tolerance - problem") exit(1) # draw source image sdl2.SDL_RenderCopy(ren.sdlrenderer, texture, sdl2.SDL_Rect(0, 0, 64, 48), sdl2.SDL_Rect(0, 0, 128, 96)) return image
def draw(self, renderer, text, rect, color, selected=None, kerning=True, wrap=True, lines=None): """ Renders text in the specified rect, using the specified color. If specified, selected is a set of indexes in text that should be highlighted. """ y = rect.top if lines is None: lines = list( self.layout(text, rect.width, kerning=kerning, wrap=wrap)) for line in lines: for idx, code, x, kern, extent in line: tex, size = self.glyph(renderer, code) sdl2.SDL_SetTextureColorMod(tex, color.r, color.g, color.b) sdl2.SDL_SetTextureAlphaMod(tex, color.a) dst = sdl2.SDL_Rect(rect.left + x + kern, y, size.w, size.h) sdl2.SDL_RenderCopy(renderer, tex, None, ctypes.byref(dst)) if selected and idx in selected: sdl2.SDL_SetRenderDrawColor(renderer, 20, 60, 120, 255) sdl2.SDL_SetRenderDrawBlendMode(renderer, sdl2.SDL_BLENDMODE_ADD) sdl2.SDL_RenderFillRect( renderer, sdl2.SDL_Rect(rect.left + x, y, size.w + kern, size.h)) y += self.line_height return lines
def __init__(бре, површ, положај, шкработине, име_боје): print("РамОдСлике __init__", име_боје) бре.положај = положај # претпоставка је да се положај мења споља бре.површ = површ бре.пуо = sdl2.SDL_Rect() бре.пуо.x = 0 бре.пуо.y = 0 бре.пуо.w = 16 бре.пуо.h = 16 средина = sdl2.SDL_Rect() средина.x = 3 средина.y = 3 средина.w = 10 средина.h = 10 бре.плава = sdl2.SDL_CreateRGBSurfaceWithFormat( 0, 16, 16, 32, sdl2.SDL_PIXELFORMAT_RGBA32) sdl2.SDL_SetSurfaceBlendMode(бре.плава, sdl2.SDL_BLENDMODE_BLEND) sdl2.SDL_FillRect(бре.плава, бре.пуо, инт_боја(бре.плава.contents.format, БОЈЕ[име_боје])) sdl2.SDL_FillRect( бре.плава, средина, инт_боја(бре.плава.contents.format, БОЈЕ['transparent'])) бре.шкработине = шкработине бре.шкработине.додај(2, бре)
def RenderRoom(self, world): camera = world.entity_manager.entities['camera_0'] camera_rect = sdl2.SDL_Rect(int(camera.kinematics.x),\ int(camera.kinematics.y),\ camera.shape.w,\ camera.shape.h) window_rect = self.GetWindowRect() if world.room.display.texture == None: world.room.display.texture = self.GetTexture( world.room.display.filepath) x_stretch = 1. * window_rect.w / camera_rect.w y_stretch = 1. * window_rect.h / camera_rect.h x_offset = int( (world.room.shape.w - world.room.display.source_rect.w) / 2.) y_offset = int( (world.room.shape.h - world.room.display.source_rect.h) / 2.) destination_x = int((x_offset - camera_rect.x) * x_stretch) destination_y = int((y_offset - camera_rect.y) * y_stretch) destination_w = int(world.room.display.source_rect.w * x_stretch) destination_h = int(world.room.display.source_rect.h * y_stretch) destination_rect = sdl2.SDL_Rect(destination_x, destination_y, destination_w, destination_h) flip = sdl2.SDL_RendererFlip(sdl2.SDL_FLIP_NONE) sdl2.SDL_RenderCopyEx(self.sdl_renderer, world.room.display.texture, world.room.display.source_rect, destination_rect, 0, None, flip)
def paint(self, canvas, x, y): """ Paints the frame with its top-left corner at the x,y. """ x, y = canvas.transform[-1].position(x, y) srcrect = sdl2.SDL_Rect(x=self.x, y=self.y, w=self.w, h=self.h) dstrect = sdl2.SDL_Rect(x=int(x), y=int(y), w=self.w, h=self.h) sdl2.SDL_RenderCopy(canvas.renderer, self.image.texture, srcrect, dstrect)
def processImage(file, ren): surface = sdl_image.IMG_Load(file.encode("utf-8")) pixels = sdl2.ext.PixelView(surface.contents) image = Image() blocks = [Block.black(), Block.white()] # w = surface.contents.w # h = surface.contents.h # print(f"Opened image - width:{w}, height:{h}.") # print("Processing image...") texture = sdl2.SDL_CreateTextureFromSurface(ren.sdlrenderer, surface) new_block = 0 for y in range(0, 12): for x in range(0, 16): this_block = Block() # get the next block from image for by in range(0, 8): for bx in range(0, 8): # print(f"0x{pixels[y][x]:01x}") if pixels[y * 8 + by][x * 8 + bx] == 0xffffffff: this_block.append(1) # print("1", end='') else: this_block.append(0) # print("0", end='') # print('') # this_block.append(pixels[y][x]) # check if this block has been used already found = False for index in range(len(blocks)): if this_block.diffWithTolerance(blocks[index], 5) < 5: # if this_block==old_block: found = True # store record of which block this is in output image.append(index) break if not found: # if not store it image.append(len(blocks)) # store record of which block this is in output blocks.append(this_block) # draw source image sdl2.SDL_RenderCopy(ren.sdlrenderer, texture, sdl2.SDL_Rect(0, 0, 128, 96), sdl2.SDL_Rect(0, 0, 128, 96)) # output # print(f"Image: {file}") # for y in range(0, 12): # for x in range(0, 16): # print(f" {image[x + y * 16]}", end="") # print("") # print("Blocks:",len(blocks)) return image, blocks
def draw(self, targetWindowSurf): if self.rightJustified: sdl2.SDL_BlitSurface( self.surf, None, targetWindowSurf, sdl2.SDL_Rect(self.x - self.surf.w, self.y, self.surf.w, self.surf.h)) else: sdl2.SDL_BlitSurface( self.surf, None, targetWindowSurf, sdl2.SDL_Rect(self.x, self.y, self.surf.w, self.surf.h))
def __init__(self, rend, inv): entity.__init__(self) if inv: self.texture = sdl2.SDL_CreateTextureFromSurface( rend, IMG_Load(pipe_path_inv)) self.surface = sdl2.SDL_Rect(pipeBaseX, -175, pipeWidth, pipeHeight) else: self.texture = sdl2.SDL_CreateTextureFromSurface( rend, IMG_Load(pipe_path)) self.surface = sdl2.SDL_Rect(pipeBaseX, 275, pipeWidth, pipeHeight)
def getButtonClicked(x, y): pt = sdl2.SDL_Point(x, y) if sdl2.SDL_PointInRect(pt, sdl2.SDL_Rect(*YELLOWRECT)): return YELLOW elif sdl2.SDL_PointInRect(pt, sdl2.SDL_Rect(*BLUERECT)): return BLUE elif sdl2.SDL_PointInRect(pt, sdl2.SDL_Rect(*REDRECT)): return RED elif sdl2.SDL_PointInRect(pt, sdl2.SDL_Rect(*GREENRECT)): return GREEN return None
def __init__(бре, главна_површ, стаклена_површ, обрада_догађаја, шкработине): print("Лупа __init__") обрада_догађаја.региструј(sdl2.SDL_KEYDOWN, бре.обради) бре.главна_површ = главна_површ бре.стаклена_површ = стаклена_површ бре.извор = sdl2.SDL_Rect(0, 0, 16, 16) бре.притока = sdl2.SDL_Rect(16, 16, 16*4, 16*4) бре.фокус = sdl2.SDL_CreateRGBSurfaceWithFormat(0, 16, 16, 24, sdl2.SDL_PIXELFORMAT_RGB888) sdl2.SDL_SetSurfaceBlendMode(бре.фокус, sdl2.SDL_BLENDMODE_NONE) бре.шкработине = шкработине бре.шкработине.додај(10000, бре)
def __init__(self, rend): entity.__init__(self) self.texture = [sdl2.SDL_CreateTextureFromSurface(rend, IMG_Load(img0)), sdl2.SDL_CreateTextureFromSurface(rend, IMG_Load(blank)), sdl2.SDL_CreateTextureFromSurface(rend, IMG_Load(blank))] self.isScore = True self.surface0 = sdl2.SDL_Rect(300, 25, 97-70, 129-80) self.surface1 = sdl2.SDL_Rect(300 - 40, 25, 97-70, 129-80) self.surface2 = sdl2.SDL_Rect(300 - (2 * 40), 25, 97-70, 129-80) self.count = 0 self.rend = rend self.update_textures()
def render(self, renderer, camera_x, camera_y): if self.angle != 0 and self.angle != 180: self.swap_dimensions(True) else: self.swap_dimensions(False) sdl2.SDL_RenderCopyEx( renderer, self.texture, sdl2.SDL_Rect(Vehicle.default_width * self.texture_clip, 0, Vehicle.default_width, Vehicle.default_height), sdl2.SDL_Rect(int(self.x - camera_x), int(self.y - camera_y), int(self.width), int(self.height)), 0, None, sdl2.SDL_FLIP_NONE)
def draw_bg(): for block_y in range(VP_HEIGHT_BLOCKS): for block_x in range(VP_WIDTH_BLOCKS): block_index = block_y * VP_WIDTH_BLOCKS + block_x tile = vmp['bgTiles'][block_index] flag = sdl2.SDL_FLIP_HORIZONTAL if tile['flipped'] else sdl2.SDL_FLIP_NONE tileset_block_x = tile['vcn_block'] % 32 tileset_block_y = tile['vcn_block'] // 32 src_rect = sdl2.SDL_Rect(tileset_block_x * 8, tileset_block_y * 8, 8, 8) dst_rect = sdl2.SDL_Rect(block_x * 8, block_y * 8, 8, 8) sdl2.SDL_RenderCopyEx(renderer, bg_texture, src_rect, dst_rect, c_double(0.0), None, flag)
def processImage(file, ren): surface = sdl_image.IMG_Load(file.encode("utf-8")) pixels = sdl2.ext.PixelView(surface.contents) image = Image() # w = surface.contents.w # h = surface.contents.h # print(f"Opened image - width:{w}, height:{h}.") # print("Processing image...") texture = sdl2.SDL_CreateTextureFromSurface(ren.sdlrenderer, surface) max_count = 0 count = 0 col = (pixels[0] == 0xffffffff) image.append(col) # store whether frame starts with black or white image.append(0) # for bits count for y in range(0, 48): for x in range(0, 64): pix = (pixels[y][x] == 0xffffffff) if col == pix: count += 1 else: image.append(count) max_count = max(count, max_count) count = 0 col = pix if count > 0: image.append(count) max_count = max(count, max_count) bits = 0 while 2**bits < max_count: bits += 1 image[1] = bits # draw source image sdl2.SDL_RenderCopy(ren.sdlrenderer, texture, sdl2.SDL_Rect(0, 0, 64, 48), sdl2.SDL_Rect(0, 0, 128, 96)) sdl2.SDL_DestroyTexture(texture) # output # print(f"Image: {file}") # for y in range(0, 12): # for x in range(0, 16): # print(f" {image[x + y * 16]}", end="") # print("") # print("Blocks:",len(blocks)) return image
def processImage(file, ren): surface = sdl_image.IMG_Load(file.encode("utf-8")) pixels = sdl2.ext.PixelView(surface.contents) image = Image() blocks = [Block.black(), Block.white()] # w = surface.contents.w # h = surface.contents.h # print(f"Opened image - width:{w}, height:{h}.") # print("Processing image...") texture = sdl2.SDL_CreateTextureFromSurface(ren.sdlrenderer, surface) new_block = 0 for y in range(0, 6): for x in range(0, 8): this_block = Block.fromPixels(pixels, x, y) # check if this block has been used already found = False num_blocks = len(blocks) for index in range(num_blocks): # if this_block.diffWithTolerance(blocks[index],5)<5: if this_block == blocks[index]: found = True # store record of which block this is in output image.append( index ) # storing images on first pass isn't needed, but let's me draw preview blocks[index].count += 1 break if not found: # if not store it image.append(len(blocks)) # store record of which block this is in output blocks.append(this_block) # draw source image sdl2.SDL_RenderCopy(ren.sdlrenderer, texture, sdl2.SDL_Rect(0, 0, 64, 48), sdl2.SDL_Rect(0, 0, 128, 96)) # output # print(f"Image: {file}") # for y in range(0, 12): # for x in range(0, 16): # print(f" {image[x + y * 16]}", end="") # print("") # print("Blocks:",len(blocks)) return image, blocks
def render_text(self, renderer, screen_width): # Meters width, height = self.text_dimensions(self.meters_texture) sdl2.SDL_RenderCopyEx( renderer, self.meters_texture, None, sdl2.SDL_Rect(InfoText.offset, InfoText.offset, width, height), 0.0, None, sdl2.SDL_FLIP_NONE) # Time width, height = self.text_dimensions(self.time_texture) sdl2.SDL_RenderCopyEx( renderer, self.time_texture, None, sdl2.SDL_Rect(screen_width - width - InfoText.offset, InfoText.offset, width, height), 0.0, None, sdl2.SDL_FLIP_NONE)
def prepare(): App.running = True App.num_displays = sdl2.SDL_GetNumVideoDisplays() logger.info(f"Number of displays: {App.num_displays}") for display in range(0, App.num_displays): rect = sdl2.SDL_Rect() sdl2.SDL_GetDisplayBounds(display, rect) border_width = rect.w * App.BORDER_WIDTH_PERCENT / 100 border_height = rect.h * App.BORDER_WIDTH_PERCENT / 100 window = sdl2.SDL_CreateWindow( f"{display}".encode("ascii"), 0, 0, int(rect.w - 2 * border_width), int(rect.h - 2 * border_height), int(sdl2.SDL_WINDOW_BORDERLESS), ) window_id = sdl2.SDL_GetWindowID(window) renderer = sdl2.SDL_CreateRenderer(window, -1, 0) sdl2.SDL_SetRenderDrawColor(renderer, 30, 30, 30, 255) sdl2.SDL_ShowWindow(window) sdl2.SDL_SetWindowPosition(window, int(rect.x + border_width), int(rect.y + border_height)) scale_factor = (100 - 2 * App.BORDER_WIDTH_PERCENT) / 100 internal_rect = sdl2.SDL_Rect( int(rect.x * scale_factor), int(rect.y * scale_factor), int(rect.w * scale_factor), int(rect.h * scale_factor), ) App.windows.append({ "rect": rect, "internal_rect": internal_rect, "window_id": window_id, "window": window, "renderer": renderer, }) Events.add_listener(*App.handle_window_leave) Events.add_listener(*App.handle_window_close) Events.add_listener(*App.handle_q)
def draw_paddle(self, screen, offset, paddle): if paddle != None: rect = sdl2.SDL_Rect(int((paddle.pos[0] - offset) * screen.height), int(paddle.pos[1] * screen.height), int(paddle.size[0] * screen.height), int(paddle.size[1] * screen.height)) sdl2.SDL_RenderFillRect(screen.renderer.sdlrenderer, rect)
def render_background(self, renderer, screen_width, screen_height): sdl2.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255) sdl2.SDL_RenderCopy( renderer, self.texture, None, sdl2.SDL_Rect(int(screen_width - self.size), int(screen_height - self.size), int(self.size), int(self.size)))
def put_glyph(self, pagenum, row, col, cp, is_fullwidth, fore, back, blink, underline, for_keys): """Put a character at a given position.""" if not self.text_mode: # in graphics mode, a put_rect call does the actual drawing return attr = fore + self.num_fore_attrs*back + 128*blink x0, y0 = (col-1)*self.font_width, (row-1)*self.font_height # NOTE: in pygame plugin we used a surface fill for the NUL character # which was an optimisation early on -- consider if we need speedup. try: glyph = self.glyph_dict[cp] except KeyError: logging.warning('No glyph received for code point %s', cp.encode('hex')) try: glyph = self.glyph_dict['\0'] except KeyError: logging.error('No glyph received for code point 0') return # pixels2d uses column-major mode and hence [x][y] indexing (we can change this) glyph_width = glyph.shape[0] # changle glyph color by numpy scalar mult (is there a better way?) self.pixels[pagenum][ x0:x0+glyph_width, y0:y0+self.font_height] = ( glyph*(attr-back) + back) if underline: sdl2.SDL_FillRect( self.canvas[self.apagenum], sdl2.SDL_Rect(x0, y0 + self.font_height - 1, glyph_width, 1), attr) self.screen_changed = True
def clear_rows(self, back_attr, start, stop): """Clear a range of screen rows.""" scroll_area = sdl2.SDL_Rect( 0, (start-1)*self.font_height, self.size[0], (stop-start+1)*self.font_height) sdl2.SDL_FillRect(self.canvas[self.apagenum], scroll_area, back_attr) self.screen_changed = True
def _show_cursor(self, do_show): """Draw or remove the cursor on the visible page.""" if not self.cursor_visible or self.vpagenum != self.apagenum: return screen = self.work_surface pixels = self.work_pixels top = (self.cursor_row-1) * self.font_height left = (self.cursor_col-1) * self.font_width if not do_show: pixels[left : left+self.font_width, top : top+self.font_height ] = self.under_cursor return # copy area under cursor self.under_cursor = numpy.copy( pixels[left : left+self.font_width, top : top+self.font_height]) if self.text_mode: # cursor is visible - to be done every cycle between 5 and 10, 15 and 20 if self._cycle/self.blink_cycles in (1, 3): curs_height = min(self.cursor_to - self.cursor_from+1, self.font_height - self.cursor_from) curs_rect = sdl2.SDL_Rect( self.border_x + left, self.border_y + top + self.cursor_from, self.cursor_width, curs_height) sdl2.SDL_FillRect(screen, curs_rect, self.cursor_attr) else: pixels[ left : left+self.cursor_width, top + self.cursor_from : top + self.cursor_to + 1 ] ^= self.cursor_attr self.last_row = self.cursor_row self.last_col = self.cursor_col
def render_background(self, entities, textures): sdl2.SDL_RenderCopy(self.sdl_renderer, textures.get(TextureType.GRASS), None, sdl2.SDL_Rect( int(entities.map_rectangle[0] - self.camera.x), int(entities.map_rectangle[1] - self.camera.y), entities.map_rectangle[2], entities.map_rectangle[3]))
def __renderblock(self, number, val, y): '''drawing blocks of color according the strength of blocks''' if 0 < val < 10: self.color = gameinfo.COLOR_GRID["white-green"] elif 9 < val < 20: self.color = gameinfo.COLOR_GRID["green"] elif 19 < val < 30: self.color = gameinfo.COLOR_GRID["blue-green"] elif 29 < val < 40: self.color = gameinfo.COLOR_GRID["blue"] else: self.color = gameinfo.COLOR_GRID["red"] sx = gameinfo.BLOCKSTART[number] self.fill((sx, y - gameinfo.BLOCKSIZE, gameinfo.BLOCKSIZE, gameinfo.BLOCKSIZE)) texttodisplay = "%2d" % val sur = ttf.TTF_RenderText_Solid(self.t, texttodisplay.encode(), self.BLACK) tex = sdl2.SDL_CreateTextureFromSurface(self.sdlrenderer, sur) Rblock = sdl2.SDL_Rect(sx + gameinfo.RECTSTART_X, y - gameinfo.RECTSTART_Y, gameinfo.RECTWIDTH, gameinfo.RECTHEIGHT) sdl2.SDL_RenderCopy(self.sdlrenderer, tex, None, Rblock) sdl2.SDL_FreeSurface(sur) sdl2.SDL_DestroyTexture(tex)
def draw_ball(self, screen, offset, ball): if ball != None: rect = sdl2.SDL_Rect(int((ball.pos[0] - offset) * screen.height), int(ball.pos[1] * screen.height), int(ball.size[0] * screen.height), int(ball.size[1] * screen.height)) sdl2.SDL_RenderFillRect(screen.renderer.sdlrenderer, rect)
def run(): boxes = [Box(sdl2.SDL_Rect(0, int(1080 * 0.8 / 2) - 50, 100, 100))] last_tick = sdl2.SDL_GetTicks() while App.running: for box in boxes: box.update() for window in App.windows: renderer = window["renderer"] sdl2.SDL_SetRenderDrawColor(renderer, 30, 30, 30, 255) sdl2.SDL_RenderClear(renderer) for box in boxes: box.render() for window in App.windows: renderer = window["renderer"] sdl2.SDL_RenderPresent(renderer) Events.handle_events() current_tick = sdl2.SDL_GetTicks() last_tick = last_tick + App.FRAME_DURATION delay = last_tick - current_tick sdl2.SDL_Delay(int(max(0, delay)))
def render(self, components): global camera, stars # Draw stars tmp = self.renderer.color self.renderer.color = BLACK self.renderer.clear() self.renderer.color = BLUISH_GRAY star_coords = [] # stars is a global list of Star objects... for now. for s in stars: coords = camera.star_to_screen_space(s.direction) star_coords.extend(coords) self.renderer.draw_point(star_coords) self.renderer.color = tmp # Draw sprites r = sdl2.SDL_Rect(0, 0, 0, 0) rcopy = sdl2.SDL_RenderCopy renderer = self.sdlrenderer for sp in components: if sp.depth >= 0: r.x, r.y, r.w, r.h = -1, -1, 1, 1 else: r.w = int(max(2, (sp.size[0] / (-sp.depth / 15e9)))) r.h = int(max(2, sp.size[1] / (-sp.depth / 15e9))) r.x = sp.x - r.w // 2 r.y = sp.y - r.h // 2 if rcopy(renderer, sp.texture, None, r) == -1: raise SDLError() sdl2.SDL_RenderPresent(self.sdlrenderer)