1 import random
2 import pygame
3 from gfx import gl, array, ext
6 def main():
8 flags = pygame.OPENGL|pygame.DOUBLEBUF|pygame.HWSURFACE
9 pygame.display.set_mode((800,600), flags)
11 #setup the opengl window
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)
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)
27 clock = pygame.time.Clock()
28 running = True
29 while running:
30 #clear the display
32 #draw the image batch
36 if pygame.QUIT in (i.type for i in pygame.event.get()):
37 running = False
38 print 'FPS:', clock.get_fps()
41 if __name__ == "__main__":
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.
So, you've created a car prefab using WheelCollider components, and now you can apply a motorTorque to make the whole thing move along. ...
This script takes a screenshot and saves it to the user desktop. It has options to use an alpha background, and also upscale the image. Usef...
Step 1. Tell you team that everything must fit within 1920x1080 or 1024x768 or whatever resolution you like! Step 2. Surround all OnGUI met...
Summary: NodeJS wins. Test Program ab -n 10000 -c 5 http://localhost/ Gevent Code from gevent import wsgi class WebServer(object): ...
When you start working with threads in your Unity3D project, you will discover that many things need to be done in the main loop. For exampl...
Often, when building a game, you need to test if objects are colliding. The objects could be spaceships, rocks, mouse pointers, laser beams....
I think ER diagrams are very handy tools for designing data requirements for a game. I don't see them given away or even talked about (i...
Just 514 lines of code. Uses sockets only, no other dependencies. https://github.com/simonwittber/uniwebserver Example Component: [Req...
Working with multiple threads is often a necessary evil. This is how I do it safely inside a Unity3D component. There are only certain time...
Most Python coders know that the Global Interpreter Lock (GIL) in CPython effectively serializes execution of threaded programs, even on sys...