Thursday, January 8

Multi-texture support for pyglet vertex lists

I wrote this little hack to allow easy expression of multiple sets of texture coordinates in pyglet vertex lists. I wrote it so I could use the texture splatting technique to draw a terrain map for a game. For that purpose it works very well. It does a small bit of monkey-patching to pyglet itself, so it may break if things are refactored, but it works good for 1.1.x.

To use it, you instantiate your vertex list the normal way except you can specify multiple sets of texture coordinates. Then you call multitexture.enable() passing it your new vertex list. Here's a simple example:

vl = pyglet.graphics.vertex_list(4,
('v2f', (100, 100, 200, 100, 200, 200, 100, 200)),
('t2f', (0, 0, 1, 0, 1, 1, 0, 1)),
('t2f', (0, 0, 0.25, 0, 0.25, 0.25, 0, 0.25)),
)
multitexture.enable(vl)

You can get the module here.

Labels:

2 Comments:

Blogger Unknown said...

You may be interested to know that pyglet 1.2 (in trunk) has support for multi-texture coordinates. e.g., use ``3t2f` for a 2-float texture coordinate for texture unit 3.

6:56 AM  
Blogger casey said...

Good to know. I should definitely take a look at what's cooking in 1.2

9:30 AM  

Post a Comment

<< Home