r/pyglet • • Jan 28 '14

Help with video playback

0 Upvotes

I'm have trouble with getting pyglet to playback video on my desktop. here is the code I found and am using:

import pyglet
vidPath="phantom.mpg"
window = pyglet.window.Window()
player = pyglet.media.Player()
source = pyglet.media.StreamingSource()
MediaLoad = pyglet.media.load(vidPath)

player.queue(MediaLoad)
player.play()

@window.event
def on_draw():
    window.clear()
    if player.source and player.source.video_format:
        player.get_texture().blit(0,0)

pyglet.app.run()

It works fine on my laptop, but simply displays a black window and no sound on my desktop. I'm not getting any errors and avbin is installed properly (was getting an error, but adding the dll to sysWOW 64 fixed). Other python scripts work fine, and I've tried re-installing pyglet (though might try again). Any ideas? So far I've tried .avi's, .mp4's, and .mpg's

Thanks

Specs: Desktop Intel i7 920 12 gb ram HSI HD 7850 2gb win 7 64 pro python 2.7 32 bit and pyglet 32 bit working in pyscripter 2.7

Laptop lenovo x220 i5 2450m 16 gb ram intel integrated graphics (I think 3000) win 7 64 home python 2.7 32 bit and pyglet 32 bit working in pyscripter 2.7


r/pyglet • • Jun 26 '25

Discussion About loading screens

3 Upvotes

I honestly haven't found any projects (that I can run) with a loading screen.

In Pyglet, are loading screens still important in large projects?

And if so, when should you take advantage of the opportunity to load the resources or how should you do it?

I know it seems like a silly question but I'm curious


r/pyglet • • May 18 '22

Support Request Weird error with basic guide program

Post image
5 Upvotes

r/pyglet • • May 04 '25

Pyglet Projects Tengine - a modular ecs game engine built with pyglet

3 Upvotes

I’ve been working on a project called Tengine — a modular game engine with Entity-Component-System (ECS) architecture, written in Python. The goal is to create a simple, flexible engine that developers can easily modify and extend with plugins. I’ve made it fully modular, so you can add things like rendering, physics, input systems, etc., by simply adding plugins.

You can find the project on GitHub, and I’d love to get some feedback from you all! I'm especially looking for ideas to improve it or any bugs you might find.

Here’s a quick overview:

  • ECS architecture for clean, scalable game design

  • Modular plugins for rendering, input, and more

  • Written in Python (for easy learning and rapid prototyping)

Check it out, and let me know what you think! 🚀


r/pyglet • • Mar 29 '16

pyglet.window.key number keys vs. number pad

1 Upvotes

Why are the top row number keys protected but the keypad number keys are not? Yes, I'm new to pyglet :P


r/pyglet • • Oct 07 '16

How to fill a shape with a color, or better yet a gradient

2 Upvotes

If I have a GL_QUAD how would I fill it with a color or gradient of two colors


r/pyglet • • Sep 02 '15

Pyglet 1.2.4

8 Upvotes

I just released pyglet 1.2.4 into the wild: https://pypi.python.org/pypi/pyglet/1.2.4

Release notes

Minor bugfix release.

Bugfixes

  • X11: Fix ContextException due to negative return value (#51)

  • X11: Fix segmentation fault in GdkPixBuf (#50)

  • OpenAL: Fix incompatibility with Python 3 (#57)


r/pyglet • • Dec 25 '17

My programe is really slow while rendering 128 particles

1 Upvotes

Hello, I'm a newbie in OpenGL and I wonder, why is my program slow while rendering 128 particles? I think that's not enough to get less fps than 30.

All I do is rendering 128 particles and giving them some basic gravitation

Can anyone help me?

on_draw function: https://pastebin.com/HhYta5Xj Particle class: https://pastebin.com/izSu9AP2


r/pyglet • • Aug 18 '15

Lesson 1: Basic 3D Concepts

Thumbnail
python3d.weebly.com
2 Upvotes

r/pyglet • • Feb 10 '24

Slower updates when scheduling / unscheduling clock and running / exiting app multiple times

1 Upvotes

Hi, I switched from Pyglet v1 to Pyglet v2 (2.0.10). After switching, each 'Trial' (ie. stopping / unscheduling then scheduling / starting), the time between updates increases ~0.007 seconds.

Trial 0: ~0.0071 between updates

Trial 1: ~0.0142

Trial 2: ~0.0212

Why is this happening? Is there a better way to start / stop pyglet app so this doesn't happen?

import math

import os, sys

import pyglet

from pyglet.gl import *

class utils():

def __init__(self):

self.config = pyglet.gl.Config(double_buffer=True, sample_buffers=1, samples=4, depth_size=16)

self.glClearColor = [1.0,1.0,1.0,1.0]

def init_screen(self):

self.window = pyglet.window.Window(width=1920, height=1080, resizable=True, config=self.config)

pyglet.gl.glClearColor(1.0,1.0,1.0,1.0)

self.window.set_fullscreen(True)

class motion_demo():

def __init__(self):

self.utils = utils()

self.utils.init_screen()

self.spot = pyglet.shapes.Circle(0, 150, 7, color=(0, 0, 0))

self.deg = 0

self.prev_deg = 0

self.n_drops = 0

self.n_frames = 0

self.n_trial = 0

self.FPS = 144

self.radius = 450

self.rotations_per_second = 0.25

self.FPS_label = pyglet.window.FPSDisplay(window=self.utils.window)

self.run()

def init_events(self):

self.utils.window.push_handlers(

on_draw = self.on_draw,

on_key_press = self.on_key_press)

return

def on_draw(self):

self.utils.window.clear() # this can load the graphics card

self.spot.draw()

self.FPS_label.draw()

return

def on_key_press(self, _symbol, _modifier):

if _symbol == pyglet.window.key.ESCAPE:

self.kill()

return pyglet.event.EVENT_HANDLED

elif _symbol == pyglet.window.key.UP:

self.rotations_per_second += .05

return pyglet.event.EVENT_HANDLED

elif _symbol == pyglet.window.key.DOWN:

self.rotations_per_second -= .05

return pyglet.event.EVENT_HANDLED

return

def update(self, _dt):

print('update _dt: %2.4f' % _dt)

self.n_frames += 1

if _dt > 1.5/self.FPS:

pyglet.gl.glClearColor(1.0,0.0,0.0,0.0) # flash a red screen

self.n_drops += 1

else:

pyglet.gl.glClearColor(self.utils.glClearColor[0],self.utils.glClearColor [1],self.utils.glClearColor[2],self.utils.glClearColor[3])

self.prev_deg = self.deg

self.deg += 360 * (self.rotations_per_second/self.FPS)

self.spot.x = self.utils.window.width/2 + math.cos(math.radians(self.deg)) * self.radius

self.spot.y = self.utils.window.height/2 + math.sin(math.radians(self.deg)) * self.radius

if self.deg % 90 < self.prev_deg % 90:

pyglet.app.exit()

return

def Trial(self):

pyglet.clock.schedule_interval(self.update,1/(self.FPS))

pyglet.app.run(1/(self.FPS))

pyglet.clock.unschedule(self.update)

return

def run(self):

self.init_events()

while (self.n_trial<5):

self.Trial()

self.n_trial += 1

self.kill()

def kill(self):

pyglet.app.exit()

self.utils.window.pop_handlers()

self.utils.window.close()

print('[MOTION DEMO] exiting, dropped frames: %d, total: %d (%.2f %%); %.1f seconds' % (self.n_drops,self.n_frames,self.n_drops/self.n_frames, self.n_frames/self.FPS ))

sys.exit()

return

if __name__ == "__main__":

motion_demo()


r/pyglet • • Mar 20 '24

Development News Pyglet Release v2.0.14 beta

Thumbnail
github.com
1 Upvotes

r/pyglet • • Mar 16 '23

Development News Pyglet Release v2.0.5

Thumbnail
github.com
4 Upvotes

r/pyglet • • Feb 26 '23

Pyglet Projects Paint Program in Pyglet

Thumbnail
youtu.be
3 Upvotes

r/pyglet • • Jun 06 '22

Minecraft-like engine...having a hard time getting geometry on screen fast enough

2 Upvotes

Hello,

I'm working on a minecraft-like game engine, using Pyglet. Source is here which is based on this

For the longest time, I assumed that I was not able to expand the view distance as far as I'd like, because Python was not able to generate the blocks fast enough. However, I recently discovered that it is generating the blocks more quickly than they're being rendered, as I can collide with unrendered ones. They do eventually pop in, but takes a hot minute. I'm not sure why I didn't notice it before, but nonetheless, it seems like I'm missing something on the Pyglet side. I believe I have implemented batch rendering, but I don't really have frame rate issues either way - just my geometry is taking its sweet time to hit the screen.

Of course, any ideas/insight is greatly appreciated!

Thank you for reading

p.s. I even started porting to C, thinking block generation time was at fault, but didn't finish that before realizing the geometry just hadn't made it to the screen yet. The problem could still be on the scheduling side, as it is not multi-threaded, but I'm not finding much information on how to implement w/ Pyglet, or even if that would help me here.

edit: Some guidance for reading the code...

main.py is where most of the Pyglet stuff happens

world.py is where most/all of the scheduling happens...I understand what it does, but I'm not sure how to optimize it any further.

terrain.py is where the terrain generation functions reside

util.py is mostly helper functions & config vars


r/pyglet • • Jul 08 '22

Pyglet Projects Dollarstore Flappy Bird

1 Upvotes

r/pyglet • • Jun 17 '22

College Physics Project

Thumbnail
youtu.be
1 Upvotes

r/pyglet • • Nov 21 '21

Support Request How do you Scroll through a map?

4 Upvotes

I'm making a network simulator.( top down tower defense like)

I would like the playable space to be much larger than the players l screen.

What's the best way to be able to move the screen around the "scene"?


r/pyglet • • May 29 '23

Pyglet Projects A Solitaire Program (source code available for those who need)

Thumbnail
onuelito.itch.io
2 Upvotes

r/pyglet • • Aug 01 '23

Development News Pyglet Release v2.0.9

Thumbnail
github.com
4 Upvotes

r/pyglet • • Oct 27 '24

Discussion pyglet

4 Upvotes

so ive only been coding in pygame and been messing around with tkinter and pymunk. im just curious about pyglet. can you incorporate it in pygame like pymunk and tkinter? it says its multimedia. what can it do? can you make a whole game just using pyglet? sorry for all the questions. im just inquisitive and i thought about doing something with pyglet to test my skills.


r/pyglet • • Jul 24 '22

how can i flip(or mirror) the contents of the window (not inverting y)

3 Upvotes

r/pyglet • • Jul 22 '22

Support Request Warehouse simulation

2 Upvotes

I am trying to make a clone of this simulation. My code is almost a transliteration of the C# code save for the drawing part (pyglet instead of ScottPlot). I have also replaced the thread.Sleep(1) to yield in order to pause and allow pyglet to draw the new position. To be honest the code is not that pretty, and I am a little tired so I have some glaring mistakes.

Problem is both shuttles move together, the movement is disjoint, and generally it doesn't work as expected. Any hints?

ETA:

Pointers: after each move, Shuttle.move() yields. Line 255, Draw.on_update() is suspect.


r/pyglet • • Jul 05 '15

Super PySnake: Open-source 2D snake game made with Pyglet and Python 3.4.

Thumbnail
github.com
1 Upvotes

r/pyglet • • Jul 19 '17

How to structure game code with Pyglet?

2 Upvotes

I'm trying to learn Pyglet for game development and I'm struggling on how I should structure my code (for example how to divide code between files). Previously I have used Pygame and I used a Model-View-Controller design. Pyglet is often used with the help of decorators, which is a new tool for me. I've read that Pyglet is a "event-driven" whereas my stuff with Pygame was "procedural". I like my main.py small, but it seems a bit like the decorator code for drawing and input handling should go to there, and I am not a huge fan of the idea.

I also try to avoid inheritance (I'm allergic to it), and often use a composition/component style instead.

This is how I would structure my code with Pygame:

#main.py

import model
import view
import controller

model = model.GameModel()
view = view.GameView(model)
controller = controller.GameController(model)

while controller.running:
    view.render_all()
    controller.process_input()

#model.py
class GameModel:
    def __init__(self):
...

#view.py
class GameView:
    def __init__(self, model):
...

#controller.py
class GameController:
    def __init__(self, model):
...

Whereas Pyglet code that I have seen has been more like:

@window.event
def on_draw():
    ...
def update(dt):
    ...
if __name__ == '__main__':
    pyglet.clock.schedule_interval(update, 1/120.0)
    pyglet.app.run()
   ...