1 import random
2 import pygame
3 from gfx import gl, array, ext
4
5
6 def main():
7 pygame.init()
8 flags = pygame.OPENGL|pygame.DOUBLEBUF|pygame.HWSURFACE
9 pygame.display.set_mode((800,600), flags)
10
11 #setup the opengl window
12 gl.init((1280,800))
13
14 #create an image batch of 10000 images, which uses the texture 'sprite.png'
15 image_count = 10000
16 texture = ext.GLSurface(pygame.image.load('sprite.png'))
17 image_batch = ext.ImageBatch(image_count, texture)
18
19 #create 10000 random images, and use the whole texture for each image
20 for i in xrange(image_count):
21 x,y = random.randint(0,795), random.randint(0,595)
22 w,h = 5,5
23 vertices = (x,y),(x,y+h),(x+w,y+h),(x+w,y)
24 texture_coords = (0,0),(0,1),(1,1),(1,0)
25 image_batch.set_quad(i, vertices, texture_coords=texture_coords)
26
27 clock = pygame.time.Clock()
28 running = True
29 while running:
30 #clear the display
31 gl.clear((0.0,0.0,0.0,1.0))
32 #draw the image batch
33 image_batch.draw()
34 clock.tick()
35 pygame.display.flip()
36 if pygame.QUIT in (i.type for i in pygame.event.get()):
37 running = False
38 print 'FPS:', clock.get_fps()
39
40
41 if __name__ == "__main__":
42 main()
43
Wednesday, August 01, 2007
GFX Demo Code
This little piece of code draws random sprites all over an 800x600 window using GFX. The GFX specific stuff has been commented, all the rest is standard Python/Pygame stuff.
Subscribe to:
Post Comments (Atom)
Popular Posts
-
These are the robots I've been working on for the last 12 months. They each weigh about 11 tonnes and have a 17 meter reach. The control...
-
So, you've created a car prefab using WheelCollider components, and now you can apply a motorTorque to make the whole thing move along. ...
-
I have just spent an hour trying to track down a weird bug in some Javascript interpolation code. The offending code looks like this: var n ...
-
The procedural planet package has been updated to version 1.4, and you can see the new demo here . It features better city light control, be...
-
Dear Lazyweb. Imagine a nice RESTful interface for working with Tags. The URL: /tags/ will return a list of all the tags. The URL: /tags/fo...
-
Why would I ask that question? Python 3 has been available for some time now, yet uptake is slow. There aren't a whole lot of packages i...
-
I've just finished refactoring an awful C# class. I had been delaying the job for a while because I didn't want to do it. Then, whil...
-
I've built sites with Django, TurboGears and Pylons. I've come to prefer Pylons. Why? Pylons gets out of the way, and stays out of t...
-
After my last post, I decided to benchmark the scaling properties of Stackless, Kamaelia, Fibra using the same hackysack algorithm. Left axi...
-
I've just uploaded Fibra 2 to the cheeseshop. Fibra 2 includes the promised non-blocking plugin, which allows a generator based task to...
7 comments:
Curses! I don't have pygame installed . I modified the example to use pyglet to set up the window etc. but GFX uses pygame internally :(
OK, I've patched GFX to use pyglet :)
Mostly that involved removing code ;)
I get 136 FPS on my powerbook G4
Oh, I nearly forgot. pyglet has a "lots of sprites" benchmarking program for both itself and pygame. They're in the pyglet svn under contrib/scene2d/examples/los.py and tools/los_pygame.py
Very cool. I can do 100,000 64x64 pixel-sized sprites at 7 fps. That's on an Intel Core Duo @ 2.13 GHz and a Nvdia 7900GS.
--Mike
coolness.
Not sure what you're using for rendering... Looks like a display list? That seems like the quickest way to do non moving images.
Did you know about the point sprite extensions?
eg.
http://oss.sgi.com/projects/ogl-sample/registry/ARB/point_sprite.txt
I can't remember the earliest extension which was used in quake 1... but it's accelerated by most hw opengls.
There's a bunch of examples if you search the web for point sprites.
illume: I'm using vertex arrays, so these sprites are completely dynamic, as compared to static display lists.
I played with point sprites in pyglet back when I started the new job.
Through ctypes (just about the slowest way you can do anything ;) using point sprites and vertex arrays I can happily animate a sparker with 1000 sparkles at ~150fps on my crappy G4 powerbook.
And it's sooo easy.
Post a Comment