Use proper texture loading techniques.

This commit is contained in:
Quantum 2018-08-24 17:02:58 -04:00
parent 9193f1bc57
commit 1524a6f27e
2 changed files with 21 additions and 7 deletions

View file

@ -277,7 +277,7 @@ class SphericalBody(Body):
self.cloudmap_id = compile(sphere, self.radius + 2, division, division, cloud_texture, lighting=False) self.cloudmap_id = compile(sphere, self.radius + 2, division, division, cloud_texture, lighting=False)
if corona_texture is not None: if corona_texture is not None:
corona = get_best_texture(corona_texture) corona = get_best_texture(corona_texture, clamp=True)
corona_size = atmosphere_data.get('corona_size', self.radius / 2) corona_size = atmosphere_data.get('corona_size', self.radius / 2)
corona_division = atmosphere_data.get('corona_division', 100) corona_division = atmosphere_data.get('corona_division', 100)
corona_ratio = atmosphere_data.get('corona_ratio', 0.5) corona_ratio = atmosphere_data.get('corona_ratio', 0.5)
@ -285,7 +285,7 @@ class SphericalBody(Body):
corona_ratio, corona) corona_ratio, corona)
if atm_texture is not None: if atm_texture is not None:
atm_texture = get_best_texture(atm_texture) atm_texture = get_best_texture(atm_texture, clamp=True)
self.atmosphere_id = compile(disk, self.radius, self.radius + atm_size, 30, atm_texture) self.atmosphere_id = compile(disk, self.radius, self.radius + atm_size, 30, atm_texture)
if 'ring' in info: if 'ring' in info:
@ -299,7 +299,7 @@ class SphericalBody(Body):
self.ring_rotation = pitch, yaw, roll self.ring_rotation = pitch, yaw, roll
self.ring_id = compile(disk, distance, distance + size, 30, self.ring_id = compile(disk, distance, distance + size, 30,
get_best_texture(info['ring'].get('texture', None))) get_best_texture(info['ring'].get('texture', None), clamp=True))
def _draw_sphere(self): def _draw_sphere(self):
with glMatrix(self.location, self.rotation), glRestore(GL_CURRENT_BIT | GL_ENABLE_BIT): with glMatrix(self.location, self.rotation), glRestore(GL_CURRENT_BIT | GL_ENABLE_BIT):

View file

@ -170,7 +170,7 @@ def load_image(file, path):
return path, width, height, len(raw.format), mode, flip_vertical(texture, width, height) return path, width, height, len(raw.format), mode, flip_vertical(texture, width, height)
def load_texture(file): def load_texture(file, clamp=False):
if os.path.isabs(file): if os.path.isabs(file):
path = file path = file
file = os.path.basename(path) file = os.path.basename(path)
@ -188,9 +188,23 @@ def load_texture(file):
glBindTexture(GL_TEXTURE_2D, id) glBindTexture(GL_TEXTURE_2D, id)
if gl_info.have_version(3) or gl_info.have_extension('GL_ARB_framebuffer_object'):
glTexImage2D(GL_TEXTURE_2D, 0, {
GL_RGB: GL_RGB8,
GL_BGR: GL_RGB8,
GL_RGBA: GL_RGBA8,
GL_BGRA: GL_RGBA8,
}[mode], width, height, 0, mode, GL_UNSIGNED_BYTE, texture)
glGenerateMipmap(GL_TEXTURE_2D)
else:
gluBuild2DMipmaps(GL_TEXTURE_2D, depth, width, height, mode, GL_UNSIGNED_BYTE, texture)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
gluBuild2DMipmaps(GL_TEXTURE_2D, depth, width, height, mode, GL_UNSIGNED_BYTE, texture)
if clamp:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
cache[path] = id cache[path] = id
return id return id
@ -228,11 +242,11 @@ def load_clouds(file):
return id return id
def get_best_texture(info, loader=load_texture): def get_best_texture(info, loader=load_texture, **kwargs):
if isinstance(info, list): if isinstance(info, list):
for item in info: for item in info:
try: try:
return loader(item) return loader(item, **kwargs)
except ValueError: except ValueError:
pass pass
else: else: