pyglet

Can't draw() sprites in pyglet

。_饼干妹妹 提交于 2019-12-05 12:57:36
For some reason, I can't get pyglet to draw sprites. Here's my code: import pyglet game = pyglet.window.Window(640, 480, "I'm a window") batch = pyglet.graphics.Batch() pyglet.resource.path = ["."] pyglet.resource.reindex() image = pyglet.resource.image("hextile.png") pyglet.sprite.Sprite(image, x=200, y=300, batch=batch) pyglet.text.Label('DING', font_name='Arial', font_size=24, x=100, y=100, batch=batch) @game.event def on_draw(): game.clear() batch.draw() #image.blit(0, 0) pyglet.app.run() Now, when I draw the batch, the text label is shown correctly. I see "DING" on the window. However,

Python Video Framework

℡╲_俬逩灬. 提交于 2019-12-05 11:56:19
I'm looking for a Python framework that will enable me to play video as well as draw on that video (for labeling purposes). I've tried Pyglet, but this doesn't seem to work particularly well - when drawing on an existing video, there is flicker (even with double buffering and all of that good stuff), and there doesn't seem to be a way to get the frame index in the video during the per-frame callback (only elapsed time since the last frame). Try a Python wrapper for OpenCV such as ctypes-opencv . The C API reference is here , and the wrapper is very close (see docstrings for any changes). I

numpy array is shown incorrect with pyglet

∥☆過路亽.° 提交于 2019-12-05 01:53:23
问题 I have problems with displaying a numpy array with pyglet. I have found a very similar topic (how to display a numpy array with pyglet?) that I used. I want to display the array in greyscale, but pyglet displays it with colours see the image: http://i.stack.imgur.com/pL6Yr.jpg def create(self, X,Y): IMG = random((X,Y)) * 255 self.IMG = dstack((IMG,IMG,IMG)) return self.IMG def image(self): self.img_data = self.create(X,Y).data.__str__() self.image = pyglet.image.ImageData(X,Y, 'RGB', self.img

Resource Not Found Exception in pyglet

我怕爱的太早我们不能终老 提交于 2019-12-04 03:54:26
I'm using Python 2.6.6 and pyglet 1.1.4. In my "Erosion" folder, I have "Erosion.py" and a folder named "Images." Inside images, there are .png images. One image is named "Guard.png." In "Erosion.py" there is a segment that goes like so: pyglet.resource.path = ['Images'] pyglet.resource.reindex() self.image = pyglet.resource.image('%s%s' % (character, '.png')) When I run this, I am given File "C:\Python26\lib\site-packages\pyglet\resource.py", line 394, in file raise ResourceNotFoundException(name) ResourceNotFoundException: Resource "Guard.png" was not found on the path. Ensure that the

How to play music continuously in pyglet

杀马特。学长 韩版系。学妹 提交于 2019-12-03 22:59:35
问题 me and my friend are working on a game and we want our music to loop as long as the game is running. Help please there seems to be no function to put music on repeat 回答1: In current versions of pyglet, you should use a SourceGroup , setting the loop attribute to True . You can then queue it into a Player to play it: snd = pyglet.media.load('sound.wav') looper = pyglet.media.SourceGroup(snd.audio_format, None) looper.loop = True looper.queue(snd) p = pyglet.media.Player() p.queue(looper) p

numpy array is shown incorrect with pyglet

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 16:42:56
I have problems with displaying a numpy array with pyglet. I have found a very similar topic ( how to display a numpy array with pyglet? ) that I used. I want to display the array in greyscale, but pyglet displays it with colours see the image: http://i.stack.imgur.com/pL6Yr.jpg def create(self, X,Y): IMG = random((X,Y)) * 255 self.IMG = dstack((IMG,IMG,IMG)) return self.IMG def image(self): self.img_data = self.create(X,Y).data.__str__() self.image = pyglet.image.ImageData(X,Y, 'RGB', self.img_data, pitch = -X*3) return self.image If I save and load the array instead it works (but it is

How to pan and zoom properly in 2D?

删除回忆录丶 提交于 2019-12-03 14:27:37
问题 All I want to do is create a really simple pan and zoom feature in 2D with OpenGL through pyglet. As you can see, the zooming is working perfectly after the first jump:( Then again, the dragging (panning) is also working, but it also jumps (and it jumps a pretty big one).. Here is my simplified code and a video (pyglet_test.mp4) that shows how it behaves: import pyglet from pyglet.gl import * # Zooming constants ZOOM_IN_FACTOR = 1.2 ZOOM_OUT_FACTOR = 1/ZOOM_IN_FACTOR class App(pyglet.window

Why is pyglet so slow compared to pygame?

ⅰ亾dé卋堺 提交于 2019-12-03 08:10:59
Here is the code. 5000 bouncing spinning red squares. (16x16 png) On the pygame version I get 30 fps but 10 fps with pyglet. Isnt OpenGl supposed to be faster for this kind of thing? pygame version: import pygame, sys, random from pygame.locals import * import cProfile # Set FPS FPS = 60.0 clock = pygame.time.Clock() # Set window WINDOWWIDTH= 800 WINDOWHEIGHT = 600 pygame.init() screen = pygame.display.set_mode((WINDOWWIDTH,WINDOWHEIGHT)) screen.fill((0,0,0)) background = screen.copy().convert() image = pygame.image.load("square.png").convert() class Square(object): def __init__(self,x,y):

How to pan and zoom properly in 2D?

你。 提交于 2019-12-03 04:33:32
All I want to do is create a really simple pan and zoom feature in 2D with OpenGL through pyglet. As you can see, the zooming is working perfectly after the first jump:( Then again, the dragging (panning) is also working, but it also jumps (and it jumps a pretty big one).. Here is my simplified code and a video ( pyglet_test.mp4 ) that shows how it behaves: import pyglet from pyglet.gl import * # Zooming constants ZOOM_IN_FACTOR = 1.2 ZOOM_OUT_FACTOR = 1/ZOOM_IN_FACTOR class App(pyglet.window.Window): def __init__(self, width, height, *args, **kwargs): # Create GL configuration conf = Config(

How to do a non-blocking URL fetch in Python

北慕城南 提交于 2019-12-03 00:51:00
I am writing a GUI app in Pyglet that has to display tens to hundreds of thumbnails from the Internet. Right now, I am using urllib.urlretrieve to grab them, but this blocks each time until they are finished, and only grabs one at a time. I would prefer to download them in parallel and have each one display as soon as it's finished, without blocking the GUI at any point. What is the best way to do this? I don't know much about threads, but it looks like the threading module might help? Or perhaps there is some easy way I've overlooked. You'll probably benefit from threading or multiprocessing