summaryrefslogtreecommitdiff
path: root/window.py
diff options
context:
space:
mode:
Diffstat (limited to 'window.py')
-rw-r--r--window.py37
1 files changed, 25 insertions, 12 deletions
diff --git a/window.py b/window.py
index 29d0522..4c51bd1 100644
--- a/window.py
+++ b/window.py
@@ -3,7 +3,7 @@ from OpenGL.GLUT import *
from OpenGL.GLU import *
from time import time
-from transition import Transition
+from renderer import ImageRenderer, TransitionMix
from texture import ImageTexture
@@ -14,9 +14,12 @@ class PixDisplay:
self.image_time = 0
self.textures = []
self.current_texture_index = 0
- self.transition = Transition()
+ self.renderer = None
self.window_width = 0
self.window_height = 0
+ # TODO
+ self.max_framerate = 60
+ self.frame_time = int(1000 / self.max_framerate) # In ms
self.display_duration = 2.0
self.transition_duration = 0.5
@@ -39,9 +42,9 @@ class PixDisplay:
self.last_time = current_time
if not self.textures:
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- glLoadIdentity()
glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
+ #glLoadIdentity()
glutSwapBuffers()
return
@@ -60,25 +63,24 @@ class PixDisplay:
if window_width != self.window_width or window_height != self.window_height:
self.window_width, self.window_height = window_width, window_height
+ glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- glLoadIdentity()
+ #glLoadIdentity()
- self.transition.draw_image(self.texture_current, self.window_width, self.window_height, 1)
+ self.renderer.draw_static(self.texture_current, self.window_width, self.window_height, 1)
- glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black
glutSwapBuffers()
return
self.window_width, self.window_height = window_width, window_height
+ glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- glLoadIdentity()
+ #glLoadIdentity()
# DRAW
transition_time = self.image_time - self.display_duration
- complete = self.transition.draw(self.texture_current, self.texture_next, self.window_width, self.window_height, delta_time, transition_time, self.transition_duration)
-
- glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black
+ complete = self.renderer.draw_transition(self.texture_current, self.texture_next, self.window_width, self.window_height, delta_time, transition_time, self.transition_duration)
glutSwapBuffers()
@@ -86,6 +88,10 @@ class PixDisplay:
self.image_time = 0
self.current_texture_index = self.next_texture_index
+ def timer(self, value):
+ glutPostRedisplay()
+ glutTimerFunc(self.frame_time, self.timer, 0) # Schedule next frame
+
# Initialization and main loop
def main(self):
# Initialize the window
@@ -94,6 +100,8 @@ class PixDisplay:
glutCreateWindow("Image Viewer with Fade Transition")
glEnable(GL_TEXTURE_2D)
+ self.renderer = ImageRenderer()
+ self.renderer.set_transition(TransitionMix)
self.image_time = 0
self.start_time = time()
self.last_time = time()
@@ -104,7 +112,12 @@ class PixDisplay:
glOrtho(-1, 1, -1, 1, -1, 1)
glMatrixMode(GL_MODELVIEW)
+ # Enable alpha blending
+ glEnable(GL_BLEND)
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
+
+ # Run display
glutDisplayFunc(self.display)
- glutIdleFunc(self.display)
+ glutTimerFunc(self.frame_time, self.timer, 0)
glutMainLoop()