Skip to content

Commit

Permalink
Example tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
einarf committed Nov 28, 2024
1 parent 9b97b0b commit 82702c3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
28 changes: 16 additions & 12 deletions examples/advanced/animated_gif.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
"""
Loads two gif files into texture arrays and renders them into an offscreen buffer
that is then displayed on the screen using nearest neighbor filtering.
Possible improvements:
- Make the example configurable to load any gif file(s)
- Load the raw byte data for each frame and instead use a palette texture to
reduce the memory footprint
- Take the gif transparency key into account?
"""

from pathlib import Path

import glm
Expand All @@ -6,12 +17,8 @@
import moderngl_window as mglw
from moderngl_window import geometry

# from moderngl_window.conf import settings
# settings.SCREENSHOT_PATH = 'screenshots'
# from moderngl_window import screenshot


class Test(mglw.WindowConfig):
class AnimatedGif(mglw.WindowConfig):
title = "Animated Sprite"
resource_dir = (Path(__file__) / "../../resources").resolve()
aspect_ratio = 320 / 256
Expand All @@ -25,7 +32,8 @@ def __init__(self, **kwargs):
self.background_texture.repeat_x = False
self.background_texture.repeat_y = False
self.caveman_texture = self.load_texture_array(
"textures/animated_sprites/player_2.gif", layers=35
"textures/animated_sprites/player_2.gif",
layers=35, # Number of frames in the gif
)
self.caveman_texture.repeat_x = False
self.caveman_texture.repeat_y = False
Expand Down Expand Up @@ -69,10 +77,7 @@ def on_render(self, time, frame_time):
self.offscreen_texture.use(location=0)
self.quad_fs.render(self.texture_program)

# if self.wnd.frames < 100:
# screenshot.create(self.ctx.screen)

def render_sprite(self, texture, blend=False, frame=0, position=(0, 0)):
def render_sprite(self, texture: moderngl.TextureArray, blend=False, frame=0, position=(0, 0)):
if blend:
self.ctx.enable(moderngl.BLEND)

Expand All @@ -86,5 +91,4 @@ def render_sprite(self, texture, blend=False, frame=0, position=(0, 0)):


if __name__ == "__main__":
mglw.run_window_config(Test)
# Test.run()
AnimatedGif.run()
2 changes: 1 addition & 1 deletion examples/advanced/compute_render_to_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ def on_render(self, time, frame_time):


if __name__ == "__main__":
mglw.run_window_config(ComputeRenderToTexture)
ComputeRenderToTexture.run()
2 changes: 1 addition & 1 deletion examples/advanced/shader_includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ def on_render(self, time, frame_time):


if __name__ == "__main__":
mglw.run_window_config(ShaderInclude)
ShaderInclude.run()
2 changes: 1 addition & 1 deletion examples/geometry_quad_fs_mouse_scroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def on_mouse_drag_event(self, x, y, dx, dy):


if __name__ == "__main__":
moderngl_window.run_window_config(QuadFullscreenScroll)
QuadFullscreenScroll.run()
2 changes: 1 addition & 1 deletion examples/window_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BasicWindowConfig(moderngl_window.WindowConfig):
def __init__(self, **kwargs):
super().__init__(**kwargs)

def on_render(self, time, frametime):
def on_render(self, time: float, frametime: float):
self.ctx.clear(
(math.sin(time) + 1.0) / 2,
(math.sin(time + 2) + 1.0) / 2,
Expand Down

0 comments on commit 82702c3

Please sign in to comment.