def main(): cont = logic.getCurrentController() owner = cont.owner secondary = owner.sensors["Secondary"] if secondary.positive and owner["Character Selected"]: owner["Character Selected"] = False objects = logic.getCurrentScene().objects select_character_text = objects["Select Character Text"] select_character_text.text = "SELECT CHARACTER" character_portrait_glow = objects["Character Portrait Glow"] character_portrait_glow.visible = False character_portrait = objects["Character Portrait"] matID = texture.materialID(character_portrait, "MA" + "Character Portrait") tex = texture.Texture(character_portrait, matID, 0) # Specify path to image. os.chdir(logic.expandPath("//")) os.chdir("../Rendered Images/Character Portraits") cwd = os.getcwd() image_path = cwd + "/black.png" tex.source = texture.ImageFFmpeg(image_path) owner["texture_property"] = tex tex.refresh(True)
def reload(self, path): bgl.glEnable(bgl.GL_TEXTURE_2D) if path == self.path: return if path in logic.texture_cache: img = logic.texture_cache[path] else: img = texture.ImageFFmpeg(path) img.scale = False if self._cache: logic.texture_cache[path] = img data = img.image if data == None: print("Could not load the image", img) self.valid = False return self.bind() bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA, img.size[0], img.size[1], 0, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, data) self.size = img.size[:] self.path = path img = None
def reload(self, image): if image == self.path: return if image in ImageTexture._cache: # Image has already been loaded from disk, recall it from the cache img = ImageTexture._cache[image] else: # Load the image data from disk img = texture.ImageFFmpeg(image) img.scale = False img.flip = False if self._caching: ImageTexture._cache[image] = img data = img.image if data is None: self.valid = False #print("Unable to load the image", image) return # Upload the texture data self.bind() glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.size[0], img.size[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, data) self.size = img.size[:] self.path = image img = None
def loadtexture(filepath): """ Loads a texture from an image (tga, jpg...any format supported by FFMPEG) and returns the texture buffer ID. """ id_buf = bgl.Buffer(bgl.GL_INT, 1) bgl.glGenTextures(1, id_buf) id = id_buf.to_list()[0] if hasattr(id_buf, "to_list") else id_buf.list[0] bgl.glBindTexture(bgl.GL_TEXTURE_2D, id) image = texture.ImageFFmpeg(filepath) if not image.image: logger.error("Error when loading " + filepath + ". File not found? Format not " "supported by FFMPEG? (tga, jpg, png do work)") return -1 else: im_buf = image.image bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR) bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_MODULATE) bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA, image.size[0], image.size[1], 0, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, im_buf) return id
def __init__(self, path): self.worldPosition = [0, 0, 0] self.visible = True self.path = path self.fullpath = logic.expandPath("//../data/" + path) self.texture = texture.ImageFFmpeg(self.fullpath) self.clipping = None self._tex_id = glGenTextures(1) self.size = [0, 0] bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_MODULATE) self.reload() self.texco = [(0, 0), (1, 0), (1, 1), (0, 1)] self.color = [1, 1, 1, 1] x = render.getWindowWidth() / 2 y = render.getWindowHeight() / 2 size = [50, 50] width = size[0] height = size[1] self._size = [width, height] # The "private" position returned by setter self._position = [x, y] self._last_position = self._position self.calculate_glposition() module.scene_gui.post_draw.append(self.draw) self.scale = 0.5, 0.5
def main(): cont = logic.getCurrentController() owner = cont.owner # Insert material name material_name = "Stock Mode Button" matID = texture.materialID(owner, "MA" + material_name) tex = texture.Texture(owner, matID, 0) click = cont.sensors["Click"] mouse_over = cont.sensors["Mouse Over"] if click.positive and mouse_over.positive: objects = logic.getCurrentScene().objects props = objects["Properties"] stock_mode = props["Stock Mode"] if stock_mode == "Stock All": new_stock_mode = "Stock Pick" image_path = "stock_pick.png" else: new_stock_mode = "Stock All" image_path = "stock_all.png" props["Stock Mode"] = new_stock_mode os.chdir(logic.expandPath("//")) tex.source = texture.ImageFFmpeg(image_path) owner["texture_property"] = tex tex.refresh(True)
def main(): cont = logic.getCurrentController() owner = cont.owner message = owner.sensors["Message"] if message.positive: subject = message.subjects[0] matID = texture.materialID(owner, "MA" + "Stage Card") tex = texture.Texture(owner, matID, 0) cwd = logic.expandPath("//") os.chdir(cwd) os.chdir("../../2D Art Files/UI Textures/Stage Card Textures") texture_path_dict = { "-2": "/Rock_Concert_card.png", "-1": "/game_test_card.png", "0": "/random_stage_card.png", "1": "/Belair_Estate_card.png", "2": "/Sunset_Pier_card.png", } texture_path = texture_path_dict[subject] new_cwd = os.getcwd() image_path = new_cwd + texture_path tex.source = texture.ImageFFmpeg(image_path) owner["texture_property"] = tex tex.refresh(True)
def texture_new(self, new_tex): ''' Application de la nouvelle texture''' # Nouvelle source self.url = gl.expandPath(new_tex) print("Path du fichier", new_tex, "=", self.url) self.new_source = texture.ImageFFmpeg(self.url) # Remplacement self.obj_texture.source = self.new_source self.obj_texture.refresh(False)
def texture_new(self, directory, new_tex): ''' Apply new texture. directory : set relative path "//" is the current directory. ''' # New source self.url = gl.expandPath(directory + new_tex) self.new_source = texture.ImageFFmpeg(self.url) # Apply self.obj_texture.source = self.new_source self.obj_texture.refresh(False)
def __init__(self, fileName, interp=GL_LINEAR): img = vtex.ImageFFmpeg(fileName) img.scale = False img.flip = False data = img.image w, h = img.size super().__init__(w, h, numpy.array(data, dtype=numpy.uint8), interp) if not data: self.valid = False self.__del__() return img = None
def replaceTexture(self, filepath): """ Change the texture of the object by another, external, texture. :param string filepath: The relative path (from the data folder) of the texture/image to replace. """ if filepath == None: try: del self.texture except: pass try: del self.video.source except: pass try: del self.video except: pass return path = logic.expandPath("//../data/" + filepath) self.texture = texture.Texture(self.obj, 0) self.texture.source = texture.ImageFFmpeg(path) self.texture.refresh(False)
def texture_new(self, new_tex): """ Application de la nouvelle image de la texture. Répéter la fonction plusieurs fois (ex 5x) pour que le changement marche. Tous les object avec le matériau seront changés. """ # Nouvelle source url = gl.expandPath(new_tex) print("Path du fichier", new_tex, "=", url) new_source = texture.ImageFFmpeg(url) # Remplacement self.obj_texture.source = new_source self.obj_texture.refresh(False)
def main(): cont = logic.getCurrentController() owner = cont.owner mouse_over = cont.sensors["Mouse Over"] if mouse_over.positive: name = owner.name[:-7] if name == "Stage1": image_name = "/game_test_card.png" elif name == "Stage2": image_name = "/Rock_Concert_card.png" elif name == "Stage3": image_name = "/Belair_Estate_card.png" elif name == "Stage4": image_name = "/Sunset_Pier_card.png" else: image_name = "/no_stage_card.png" objects = logic.getCurrentScene().objects stage_card = objects["Stage Card"] matID = texture.materialID(stage_card, "MA" + "Stage Card") tex = texture.Texture(stage_card, matID, 0) # Specifying the path to the image. cwd = logic.expandPath("//") os.chdir(cwd) os.chdir("../../2D Art Files/PNG/UI PNG/Stage Cards PNG") new_cwd = os.getcwd() image_path = new_cwd + image_name tex.source = texture.ImageFFmpeg(image_path) owner["texture_property"] = tex tex.refresh(True)
def reload(self, image): if image == self.path: return if image in ImageTexture._cache: # Image has already been loaded from disk, recall it from the cache img = ImageTexture._cache[image] else: # Load the image data from disk if USING_BGE_TEXTURE: img = texture.ImageFFmpeg(image) img.scale = False if self._caching: ImageTexture._cache[image] = img else: img = QtGui.QImage(image) if USING_BGE_TEXTURE: data = img.image if data == None: print("Unabled to load the image", image) return # Upload the texture data self.bind() glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.size[0], img.size[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, data) self.image_size = img.size[:] else: if img.isNull(): print("Unable to load the image", image) return glDeleteTextures([self._tex_id]) self._tex_id = QtOpenGL.QGLContext.currentContext().bindTexture( img) self.interp_mode = self.interp_mode self.image_size = [img.width(), img.height()] # Save the image name self.path = image img = None
def __init__(self, filename): from bge import texture self.region = None if not filename.startswith('/'): f = inspect.getframeinfo(inspect.currentframe()).filename d = os.path.dirname(f) filename = os.path.join(d, 'data', filename) m = Texture.atlas.match(filename) self.filename = filename if not m is None: self.setup_atlas(m.group(1), m.group(2)) else: self.source = texture.ImageFFmpeg(self.filename) self.buffer = texture.imageToArray(self.source, 'RGBA') if self.buffer is None: print('Error loading {0}: {1}'.format(filename, texture.getLastError())) self.glid = bgl.Buffer(bgl.GL_INT, 1) bgl.glGenTextures(1, self.glid) self.bind() bgl.glTexEnvi(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_REPLACE) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST) bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA, self.width, self.height, 0, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, self.buffer) self.unbind()
def createTexture(cont): """Create a new Dynamic Texture""" obj = cont.owner # get the reference pointer (ID) of the internal texture ID = texture.materialID(obj, 'IMoriginal.png') # create a texture object object_texture = texture.Texture(obj, ID) # create a new source with an external image url = logic.expandPath("//newtexture.jpg") new_source = texture.ImageFFmpeg(url) # the texture has to be stored in a permanent Python object logic.texture = object_texture # update/replace the texture logic.texture.source = new_source logic.texture.refresh(False)
def main(): cont = logic.getCurrentController() owner = cont.owner # Insert material name. material_name = "Stock Mode Button" matID = texture.materialID(owner, "MA" + material_name) tex = texture.Texture(owner, matID, 0) click = cont.sensors["Click"] mouse_over = cont.sensors["Mouse Over"] if click.positive and mouse_over.positive: objects = logic.getCurrentScene().objects properties = objects["Character Select Properties"] stock_mode = properties["Stock Mode"] if stock_mode == "Stock All": new_stock_mode = "Stock Pick" image_path = "stock_pick.png" else: new_stock_mode = "Stock All" image_path = "stock_all.png" properties["Stock Mode"] = new_stock_mode cwd = logic.expandPath("//") os.chdir(cwd) path_extension = "../../2D Art Files/PNG/UI PNG/" os.chdir(path_extension) # Applies and refreshes the new texture. tex.source = texture.ImageFFmpeg(image_path) owner["texture_property"] = tex tex.refresh(True)
def updateTexture(animated=False): print('animated: ', animated) obj = logic.scene.objects['Sphere'] ID = texture.materialID(obj, 'MAsky') objectTextures = texture.Texture(obj, ID) # create a new source with an external image if animated: source = texture.VideoFFmpeg(logic.mvb.bgImage) else: source = texture.ImageFFmpeg(logic.mvb.bgImage) # the texture has to be stored in a permanent Python object logic.skyTexture = objectTextures logic.skyTexture.source = source logic.skyTextureAnimated = animated if animated: logic.skyTexture.source.repeat = -1 logic.skyTexture.source.play() logic.skyTexture.refresh(True)
def __init__(self, baseObj, img, mat, viewport=[0.0, 100.0, 0.0, 100.0], rect=None, col=[1.0, 1.0, 1.0, 1.0], verco=None, texco=[(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]): """Initialisation de l'image Parametres : - baseObj : Objet contenant la texture de base - img : Nom de l'image - mat : Material de l'objet correspondant a l'image - viewport : Coordonnees minimales et maximales de l'affichage : [xmin, ymax, xmax, ymin] - rect : Coordonnees des coins de l'image pour un affichage rectangulaire : [x1, y1, x2, y2] - col : Couleur RVBA de l'image : [r, v, b, a] - verco : Liste des coordonnees x/y de chaque vertice. - texco : Liste des coordonnees u/v de chaque vertice.""" VT = __class__.VT gl = __class__.gl self.ok = True self.angle = 0 if verco == None and rect == None: verco = [(0.0, 0.0), (100.0, 0.0), (100.0, 100.0), (0.0, 100.0)] elif verco == None: verco = [(rect[0], rect[1]), (rect[2], rect[1]), (rect[2], rect[3]), (rect[0], rect[3])] self.texco = texco self.verco = verco self.bary = [0, 0] for i in range(len(self.verco)): self.bary[0] += self.verco[i][0] self.bary[1] += self.verco[i][1] self.bary[0] /= len(self.verco) self.bary[1] /= len(self.verco) self.couleur = col self.viewport = viewport root = gl.expandPath("//") VT_img_Img = VT.ImageFFmpeg(root + img) if VT_img_Img.status == 0: print("Erreur: Image introuvable a l'adresse '" + root + img + "'") self.ok = False return VT_img_Mat = VT.materialID(baseObj, "MA" + mat) VT_img_Tex = VT.Texture(baseObj, VT_img_Mat) VT_img_Tex.source = VT_img_Img self.VT_img = VT_img_Tex self.rafraichir() return
def _getSource(self, frame): """""" url = self._getSourcePath(frame) source = texture.ImageFFmpeg(url) return source
def reload(self, image): if image == self.path: return print(image) img = None if image in ImageTexture._cache: # Image has already been loaded from disk, recall it from the cache img = ImageTexture._cache[image] else: # Load the image data from disk, try to use BGE first if HAVE_BGE_TEXTURE: img = texture.ImageFFmpeg(image) img.scale = False # if not img.valid or img.image is None: if img.image is None: img = None elif self._caching: ImageTexture._cache[image] = img # Try to use PyQt (or PySide) if BGE has failed if img is None and HAVE_PYQT_TEXTURE: qt_img = QtGui.QImage(image) if qt_img.isNull(): img = None else: # Qt returns the image with a lot of weird format, so some # operations must be applied before qt_img = qt_img.convertToFormat(QtGui.QImage.Format_ARGB32) qt_img = qt_img.mirrored() qt_img = qt_img.rgbSwapped() # Now we can extract the image data and create a valid # object for BGE data = qt_img.constBits() size = qt_img.size() data.setsize(qt_img.byteCount()) data = memoryview(data).tobytes() channels = len(data) / (size.width() * size.height()) buff = Buffer(GL_BYTE, [len(data)], data) img = ImageFromBuff(buff, size.width(), size.height()) if self._caching: ImageTexture._cache[image] = img if img is None: print("Unable to load the image", image) return # Show the image with the appropiated backend data = img.image if not img.valid or data is None: print("Unhandled image exception...", image) return # Upload the texture data self.bind() glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.size[0], img.size[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, data) self.image_size = img.size[:] # Save the image name self.path = image img = None