# HG changeset patch # User Thibaut Girka # Date 1312273308 -7200 # Node ID 02a5f5314a19ea4904f8c554a2288de42d39b98e # Parent 9159fa222923276930b98ae6aab761c2aece01c6 Add preliminary fog support diff --git a/stageviewer.py b/stageviewer.py --- a/stageviewer.py +++ b/stageviewer.py @@ -140,11 +140,13 @@ def main(path, stage_num): glLoadIdentity() gluPerspective(30, float(window.get_width())/window.get_height(), 20, 2000) + glHint(GL_FOG_HINT, GL_NICEST) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glEnable(GL_DEPTH_TEST) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_TEXTURE_2D) + glEnable(GL_FOG) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_TEXTURE_COORD_ARRAY) @@ -185,6 +187,7 @@ def main(path, stage_num): x, y, z = 0, 0, 0 frame = 0 interpolation = 0, 0, 0 + interpolation2 = 0, 0, 0 # Main loop clock = pygame.time.Clock() @@ -199,14 +202,21 @@ def main(path, stage_num): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) for frame_num, message_type, data in stage.script: + if frame_num == frame and message_type == 1: + #TODO: move interpolation elsewhere + next_fog_b, next_fog_g, next_fog_r, _, next_fog_start, next_fog_end = struct.unpack(' frame and message_type == 0: next_message = frame_num, message_type, data break @@ -215,9 +225,26 @@ def main(path, stage_num): truc = float(frame - interpolation[0]) / interpolation[1] unknownx = old_unknownx + (next_unknownx - old_unknownx) * truc dy = old_dy + (next_dy - old_dy) * truc - fov = old_fov + (next_fov - old_fov) * truc + dz = old_dz + (next_dz - old_dz) * truc else: - unknownx, dy, fov = next_unknownx, next_dy, next_fov + unknownx, dy, dz = next_unknownx, next_dy, next_dz + + if frame < interpolation2[2]: + truc = float(frame - interpolation2[0]) / interpolation2[1] + fog_b = old_fog_b + (next_fog_b - old_fog_b) * truc + fog_g = old_fog_g + (next_fog_g - old_fog_g) * truc + fog_r = old_fog_r + (next_fog_r - old_fog_r) * truc + fog_start = old_fog_start + (next_fog_start - old_fog_start) * truc + fog_end = old_fog_end + (next_fog_end - old_fog_end) * truc + else: + fog_r, fog_g, fog_b, fog_start, fog_end = next_fog_r, next_fog_g, next_fog_b, next_fog_start, next_fog_end + + + glFogi(GL_FOG_MODE, GL_LINEAR) + glFogf(GL_FOG_START, fog_start) + glFogf(GL_FOG_END, fog_end) + glFogfv(GL_FOG_COLOR, (fog_r / 255., fog_g / 255., fog_b / 255., 1.)) + x1, y1, z1 = struct.unpack('