def __init__(self, client, size): FBOWidget.__init__(self, Vector2i(0,0), size) self._client = client self._entities = {} self._selection = [] # current selected entities self._scale = 1.0 self._camera = Vector3(0,0,50) self._rect = Rect(0,0,0,0) self._panstart = None # position where the panning has started self._panref = None self._is_panning = False self._is_selecting = False # cannot use numpy directly as it might not be available on stupid OSs (OSX, I'm looking at you!) self._viewport = glGetInteger(GL_VIEWPORT) self._viewport[0] = 0 self._viewport[1] = 0 self._viewport[2] = 0 self._viewport[3] = 0 self._background = [None, None, None] for i, filename in enumerate(['space_0.png', 'space_1.png', 'space_2.png']): self._background[i] = glGenTextures(1) fp = resources.open(('textures/background', filename), 'rb') surface = pygame.image.load(fp).convert_alpha() data = pygame.image.tostring(surface, "RGBA", 0) glBindTexture(GL_TEXTURE_2D, self._background[i]) glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface.get_width(), surface.get_height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, data ); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBindTexture(GL_TEXTURE_2D, 0) self._calc_view_matrix()
def load_sprite(filename): if filename in _resources: return _resources[filename] texture = glGenTextures(1) fp = resources.open(('textures',filename), 'rb') surface = pygame.image.load(fp).convert_alpha() data = pygame.image.tostring(surface, "RGBA", 0) glBindTexture(GL_TEXTURE_2D, texture) glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface.get_width(), surface.get_height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, data ); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glBindTexture(GL_TEXTURE_2D, 0) _resources[filename] = texture return texture
def load_texture(self, file): if file[-4:] == '.svg': return self._rasterize_svg(file) texture = glGenTextures(1) try: surface = pygame.image.load(open(file, 'rb')).convert_alpha() except: traceback.print_exc() fp = resources.open('data/default_texture.png', 'rb') surface = pygame.image.load(fp).convert_alpha() try: data = pygame.image.tostring(surface, "RGBA", True) glBindTexture(GL_TEXTURE_2D, texture) glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface.get_width(), surface.get_height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, data ); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) except Exception, e: traceback.print_exc()