def prepare(self): self.prepare_content() getstyle = self.getstyle bg = getstyle("bg") tex = getstyle("texture") if bg: if isinstance(tex, basestring): self.tex = resource.texture(tex) # self.tex = image.load(tex).get_mipmapped_texture() self.tex_id = self.tex.id elif hasattr(tex, "id"): self.tex = tex self.tex_id = tex.id elif isinstance(tex, int): self.tex = tex self.tex_id = tex else: self.tex = None self.tex_id = 0 bd = getstyle("bd") border = getstyle("border") with gl_compile(self.bgdl): if bg: self.render_background() with gl_compile(self.bddl): if bd and border: self.render_border()
def __init__(self, filename, tiledim): img = resource.texture(filename) self.tiledim = tiledim self._tw = img.width // tiledim self._th = img.height // tiledim self._grid = image.ImageGrid(img, self._th, self._tw)
def load_image(name, centered=False): if name in resource.get_cached_texture_names(): img = resource.texture(name) else: img = resource.texture(name) assert img.width in [1,2,4,8,16,32,64,128,256,512], "Carrie! Resize %s" % name assert img.height in [1,2,4,8,16,32,64,128,256,512], "Carrie! Resize %s" % name glBindTexture(img.texture.target, img.texture.id) glTexParameteri(img.texture.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) data = img.texture.image_data.get_data('RGBA', img.texture.width * 4) gluBuild2DMipmaps(GL_TEXTURE_2D, 4, img.texture.width, img.texture.height, GL_RGBA, GL_UNSIGNED_BYTE, data) img.texture.tex_coords = (0,0,0,1,0,0,1,1,0,0,1,0) if centered: img.texture.anchor_x = img.texture.width // 2 img.texture.anchor_y = img.texture.height // 2 return img.texture
def prepare(self): self.prepare_content() getstyle = self.getstyle bg = getstyle("bg") tex = getstyle("texture") if bg: if isinstance(tex,basestring): self.tex = resource.texture(tex) # self.tex = image.load(tex).get_mipmapped_texture() self.tex_id = self.tex.id elif hasattr(tex,"id"): self.tex = tex self.tex_id = tex.id elif isinstance(tex,int): self.tex = tex self.tex_id = tex else: self.tex = None self.tex_id = 0 bd = getstyle("bd") border = getstyle("border") with gl_compile(self.bgdl): if bg: self.render_background() with gl_compile(self.bddl): if bd and border: self.render_border()
def load(self): # loads all the things. TODO: make a gameState that only loads sepcific things resource.path = [self.basePath] resource.reindex() texturePath = 'Graphics/Textures/' for key, fileName in self.textures.items(): self.textures[key] = image.TileableTexture.create_for_image( resource.texture(texturePath + fileName) )
def addTexture(self, imgPath): dir, file = path.split(imgPath) if dir not in resource.path: resource.path.append(dir) resource.reindex() texture = resource.texture(file) self.textures.append(texture) gl.glBindTexture(texture.target, texture.id) gl.glGenerateMipmap(gl.GL_TEXTURE_2D) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST_MIPMAP_LINEAR)
def load(self,fname): mtllines = resource.file(fname,"ru") mname = None mat_dl = None mat_params = {'Ka':GL_AMBIENT, 'Kd': GL_DIFFUSE, 'Ks':GL_SPECULAR, 'Ke':GL_EMISSION} tname = None for line in mtllines: tokens = line.split() if not tokens or line[0] == '#': continue if tokens[0] == 'newmtl': if mname: if not tname: glDisable(GL_TEXTURE_2D) glEndList() tname = None mname = tokens[1] mat_dl = self.mat_dls.get(mname) if mat_dl is None: mat_dl = self.mat_dls[mname] = glGenLists(2) glNewList(mat_dl, GL_COMPILE) elif tokens[0] == 'Ns': glMaterialf(GL_FRONT, GL_SHININESS, float(tokens[1])) elif tokens[0] in mat_params: params = map(float,tokens[1:]) floats4 = Mat4Floats(1.0,1.0,1.0,1.0) for i,f in enumerate(params): floats4[i] = f self.mat_trans[mname] = (floats4[3] < 1.0) glMaterialfv(GL_FRONT, mat_params[tokens[0]],floats4) elif tokens[0] == 'map_Kd' and not NOTEXTURES: # need a texture glEnable(GL_TEXTURE_2D) glCallList(mat_dl+1) # will bind texture glEndList() tname = tokens[1] tex = resource.texture(tokens[1]) glNewList(mat_dl+1,GL_COMPILE) if tex: self.mat_textures[tname] = tex trans = self.mat_trans.get(mname,False) self.mat_trans[mname] = trans glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D,tex.id) # will end list before starting next one, or at end if mname: if not tname: glDisable(GL_TEXTURE_2D) glEndList()
def load(self,fname): mtllines = resource.location(fname).open(fname,"r") mname = None mat_dl = None mat_params = {'Ka':GL_AMBIENT, 'Kd': GL_DIFFUSE, 'Ks':GL_SPECULAR} tname = None for line in mtllines: tokens = line.split() if not tokens or line[0] == '#': continue if tokens[0] == 'newmtl': if mname: if not tname: glDisable(GL_TEXTURE_2D) glEndList() tname = None mname = tokens[1] mat_dl = self.mat_dls.get(mname) if mat_dl is None: mat_dl = self.mat_dls[mname] = glGenLists(2) glNewList(mat_dl, GL_COMPILE) elif tokens[0] == 'Ns': glMaterialf(GL_FRONT, GL_SHININESS, float(tokens[1])) elif tokens[0] in mat_params: params = map(float,tokens[1:]) floats4 = Mat4Floats(1.0,1.0,1.0,1.0) for i,f in enumerate(params): floats4[i] = f self.mat_trans[mname] = (floats4[3] < 1.0) glMaterialfv(GL_FRONT, mat_params[tokens[0]],floats4) elif tokens[0] == 'map_Kd' and not NOTEXTURES: # need a texture glEnable(GL_TEXTURE_2D) glCallList(mat_dl+1) # will bind texture glEndList() tname = tokens[1] tex = resource.texture(tokens[1]) glNewList(mat_dl+1,GL_COMPILE) if tex: self.mat_textures[tname] = tex trans = self.mat_trans.get(mname,False) self.mat_trans[mname] = trans glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D,tex.id) # will end list before starting next one, or at end if mname: if not tname: glDisable(GL_TEXTURE_2D) glEndList()
def get_map_environment_secondary(map_id, tracks, tiers): return resource.texture(f'secondary_m{map_id}t{tracks}e{tiers}.dds')
def get_map_environment_primary(map_id, tiers): return resource.texture(f'primary_m{map_id}e{tiers}.dds')
def get_map_tracks(map_id, tracks): return resource.texture(f'tracks_m{map_id}t{tracks}.dds')
'exp_money_time': OrderedGroup(9), 'button_text': OrderedGroup(10) } # mouse cursor shapes HAND_CURSOR: Final = WINDOW.get_system_mouse_cursor(WINDOW.CURSOR_HAND) DEFAULT_CURSOR: Final = WINDOW.get_system_mouse_cursor(WINDOW.CURSOR_DEFAULT) # button states HOVER: Final = 'hover' PRESSED: Final = 'pressed' NORMAL: Final = 'normal' _car_collections_implemented = [20, 10] MAXIMUM_CAR_COLLECTIONS: Final = [20, 10] resource.path = ['font', 'img', 'img/textures.zip'] resource.reindex() _atlas = resource.texture('atlas.dds') resource.add_font('perfo-bold.ttf') # CAR_HEAD_IMAGE includes all textures for leading carriage PASSENGER_CAR_HEAD_IMAGE: Final = [] for i in range(_car_collections_implemented[0]): PASSENGER_CAR_HEAD_IMAGE.append([]) for j in range(4): PASSENGER_CAR_HEAD_IMAGE[i].append( _atlas.get_region((j % 2) * 251, 3072 + i * 47 + 3, 251, 41)) FREIGHT_CAR_HEAD_IMAGE: Final = [] for i in range(_car_collections_implemented[1]): FREIGHT_CAR_HEAD_IMAGE.append([]) for j in range(10): FREIGHT_CAR_HEAD_IMAGE[i].append(
def __init__(self, filename: str): texture = resource.texture(filename) super().__init__(texture, batch=batch)
def setup(): # One-time GL setup global light0pos global light1pos global texture global cubemap # light0pos = [.5, .5, 1, 0] light0pos = [20.0, 20.0, 20.0, 1.0] # positional light ! light1pos = [-20.0, -20.0, 20.0, 0.0] # infinitely away light ! glClearColor(1, 1, 1, 1) glColor4f(1.0, 0.0, 0.0, 0.5 ) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_TEXTURE_2D) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) # GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ) # GL_NEAREST) texture = [] for i in range (texturecount): texturefile = 'Texturemap' + str(i) + '.jpg' print "Loading Texture", texturefile textureSurface = resource.texture(texturefile) texture.append( textureSurface ) glBindTexture(GL_TEXTURE_2D, texture[i].id) print "Texture ", i, " bound to ", texture[i].id glEnable(GL_TEXTURE_CUBE_MAP) cubemap = GLuint() glGenTextures( 1, byref(cubemap)) cubemap = cubemap.value print "CubeTexture is bound to", cubemap glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap) glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) # GL_NEAREST) glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR ) # GL_NEAREST) cubename = ['cube_map_positive_x.jpg', 'cube_map_negative_x.jpg', 'cube_map_negative_y.jpg', 'cube_map_positive_y.jpg', 'cube_map_negative_z.jpg', 'cube_map_positive_z.jpg'] for i in range (6): cubefile = cubename[i] print "Loading Cube Texture", cubefile cube = resource.texture(cubefile) # instance of class AbstractImage data = cube.get_image_data().get_data('RGBA', cube.width * 4) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA8, # texture.format, # 0, # format cube.width, cube.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data) glDisable(GL_TEXTURE_CUBE_MAP) # byref((GLubyte * (texture.width * texture.height *4))(texture.get_image_data().get_data('RGBA', texture.width * 4))) ) # glGenerateMipmap(GL_TEXTURE_CUBE_MAP) # if MIN_FILTER = GL_LINEAR_MIPMAP_LINEAR # Uncomment this line for a wireframe view #glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # Simple light setup. On Windows GL_LIGHT0 is enabled by default, # but this is not the case on Linux or Mac, so remember to always # include it. glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_LIGHT1) glLightfv(GL_LIGHT0, GL_POSITION, vec(*light0pos)) glLightfv(GL_LIGHT0, GL_AMBIENT, vec(0.3, 0.3, 0.3, 1.0)) glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(0.9, 0.9, 0.9, 1.0)) glLightfv(GL_LIGHT0, GL_SPECULAR, vec(1.0, 1.0, 1.0, 1.0)) glLightfv(GL_LIGHT1, GL_POSITION, vec(*light1pos)) glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(.6, .6, .6, 1.0)) glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1.0, 1.0, 1.0, 1.0)) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.8, 0.5, 0.5, 1.0)) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1)) glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50)
def setup(): # One-time GL setup global light0pos global light1pos global texture global cubemap # light0pos = [.5, .5, 1, 0] light0pos = [20.0, 20.0, 20.0, 1.0] # positional light ! light1pos = [-20.0, -20.0, 20.0, 0.0] # infinitely away light ! glClearColor(1, 1, 1, 1) glColor4f(1.0, 0.0, 0.0, 0.5 ) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_TEXTURE_2D) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) # GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ) # GL_NEAREST) texture = [] for i in range (texturecnt): texturefile = 'Texturemap' + str(i) + '.jpg' print "Loading Texture", texturefile textureSurface = resource.texture(texturefile) texture.append( textureSurface ) glBindTexture(GL_TEXTURE_2D, texture[i].id) print "Texture ", i, " bound to ", texture[i].id glEnable(GL_TEXTURE_CUBE_MAP) cubemap = GLuint() glGenTextures( 1, byref(cubemap)) cubemap = cubemap.value print "CubeTexture is bound to", cubemap glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap) glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) # GL_NEAREST) glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR ) # GL_NEAREST) cubename = ['left_wall_texture.jpg', 'right_wall_texture.jpg', 'front_wall_texture.jpg', 'back_wall_texture3.jpg', 'pool_tex2.jpg', 'ceil_wall_tex.jpg'] for i in range (6): cubefile = cubename[i] print "Loading Cube Texture", cubefile cube = resource.texture(cubefile) # instance of class AbstractImage data = cube.get_image_data().get_data('RGBA', cube.width * 4) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA8, # texture.format, # 0, # format cube.width, cube.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data) glDisable(GL_TEXTURE_CUBE_MAP) # Uncomment this line for a wireframe view #glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # Simple light setup. On Windows GL_LIGHT0 is enabled by default, # but this is not the case on Linux or Mac, so remember to always # include it. glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_LIGHT1) glLightfv(GL_LIGHT0, GL_POSITION, vec(*light0pos)) glLightfv(GL_LIGHT0, GL_AMBIENT, vec(0.3, 0.3, 0.3, 1.0)) glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(0.9, 0.9, 0.9, 1.0)) glLightfv(GL_LIGHT0, GL_SPECULAR, vec(1.0, 1.0, 1.0, 1.0)) glLightfv(GL_LIGHT1, GL_POSITION, vec(*light1pos)) glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(.6, .6, .6, 1.0)) glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1.0, 1.0, 1.0, 1.0)) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.8, 0.5, 0.5, 1.0)) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1)) glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50)