Hm, nothing? Well I guess I should give people more to go on.
Anyway, I made a multi-texture grid, but whenever I tried to access or
change the tex_coords it would crash with an error: "_get_tex_coords:
attribute = domain.attribute_names['tex_coords']"
Digging into pyglet-1.2.2 VertexDomain.py, Multi-texture arrays are stored
as "multi_tex_coords" in domain.atribute_names, and the functions have no
way of interacting with them.
So I made a few modifications:
def _get_tex_coords(self):
if 'multi_tex_coords' not in self.domain.attribute_names:
if (self._tex_coords_cache_version != self.domain._version):
domain = self.domain
attribute = domain.attribute_names['tex_coords']
self._tex_coords_cache = attribute.get_region(
attribute.buffer, self.start, self.count)
self._tex_coords_cache_version = domain._version
region = self._tex_coords_cache
region.invalidate()
return region.array
else:
return None
def _set_tex_coords(self, data):
self._get_tex_coords()[:] = data
tex_coords = property(_get_tex_coords, _set_tex_coords,
doc='''Array of texture coordinate data.''')
# ---
def _get_multi_tex_coords(self):
if 'tex_coords' not in self.domain.attribute_names:
if (self._tex_coords_cache_version != self.domain._version):
domain = self.domain
attribute = domain.attribute_names['multi_tex_coords']
self._tex_coords_cache = []
for a in attribute.keys():
self._tex_coords_cache.append(attribute[a].get_region(
attribute[a].buffer, self.start, self.count))
self._tex_coords_cache_version = domain._version
region = self._tex_coords_cache
array = []
for a in region:
a.invalidate()
array.append(a.array)
return array
else:
return None
def _set_multi_tex_coords(self, data):
if self._get_multi_tex_coords() != None:
for a in xrange(0, len(self._tex_coords_cache),1):
if data[a] != None:
self._tex_coords_cache[a].array[:] = data[a]
multi_tex_coords = property(_get_multi_tex_coords,
_set_multi_tex_coords,
doc='''Multi-array texture coordinate
data.''')
I'm sure it could use some improvement, but it seems to get the job done.
When you call tex_coords it will return None if its a multi_tex_coord
object, and vice versa if its a regular
tex_coord. _get_multi_tex_coords returns a list with the tex_coord array's,
and you can set them by writing: array.multi_tex_coord = [(0,0,0...),etc].
Optionally you can update specific
arrays by returning None: array.multi_tex_coord = [(0,0,0...), None,
(0,0,0...)]. I've written a small example program i'll attach.
Some of the problems i've run into involve the clock and blitted images
messing up, though i'm beginning to think its how I handle the multi-tex
rendering rather than something in pyglet,
again don't know enough to narrow it down, yet anyway. Also, the example
script was written with the above modifications to VertexDomain.py.
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
import pyglet
pyglet.options['shadow_window'] = False
from pyglet.window import key
from pyglet.gl import *
pyglet.options['debug_gl'] = False
class test(pyglet.window.Window):
def __init__(self):
super(test, self).__init__(640, 480, resizable=False, fullscreen=False, caption="Test")
self.clear()
#window aspect ratio for resizing fullscreen
self.aspect = [0,0]
#Enable blending
gl.glEnable(GL_BLEND)
gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
#Enable transparency
glEnable(GL_ALPHA_TEST)
glAlphaFunc(GL_GREATER, .1)
self.render = pyglet.graphics.Batch()
self.texture0 = pyglet.image.TextureGrid(pyglet.image.ImageGrid(pyglet.image.load("sample7.png"),1,4))
self.image = pyglet.image.load("sample6.png").get_texture()
#texture swap counter for test
self.count = [2,1,3]
self.layer = []
#initialize 32x32-tile grid
for b in range(0,15+1,1):
self.layer.append([])
for a in range(0,20+1,1):
self.layer[b].append(self.render.add(4, pyglet.gl.GL_QUADS, group(1),
('v2f',((a*32),(b*32), 32+(a*32),(b*32), 32+(a*32),32+(b*32), (a*32),32+(b*32))),
('0t3f',self.texture0[2].tex_coords),
('1t3f',self.texture0[1].tex_coords),
('2t3f',self.texture0[3].tex_coords)))
print self.layer[3][0].tex_coords
print self.layer[3][0].multi_tex_coords
pyglet.clock.get_fps()
self.fps_display = pyglet.clock.ClockDisplay()
## self.fps_display = pyglet.window.FPSDisplay(self)
pyglet.clock.schedule_interval(self.update, .01)
def update(self,dt):
self.draw()
def draw(self):
self.clear()
glEnable(GL_TEXTURE_2D)
self.render.draw()
glDisable(GL_TEXTURE_2D)
self.image.blit(256,256)
self.fps_display.draw()
def on_key_press(self,symbol,modifiers):
#exit
if symbol == key.ESCAPE:
self.close()
#fullscreen toggle
if symbol == key.ENTER:
if modifiers & key.MOD_ALT:
#if fullscreen off, turn on and scale the screen
if self.fullscreen == False:
window.set_fullscreen(True)
glScalef(window.width/640.0,window.height/480.0,1.0)#2.25x, 1.875y
self.aspect[0] = window.width/640.0
self.aspect[1] = window.height/480.0
#if its on, turn it off and un-scale the screen
else:
window.set_fullscreen(False)
glScalef((window.width/640.0)/self.aspect[0],(window.height/480.0)/self.aspect[1],1.0)
#swap first layer
if symbol == key._1:
self.count[0] += 1
if self.count[0] > 3:
self.count[0] = 0
self.layer[3][0].multi_tex_coords = [self.texture0[self.count[0]].tex_coords,None,None]
#swap second layer
if symbol == key._2:
self.count[1] += 1
if self.count[1] > 3:
self.count[1] = 0
self.layer[3][0].multi_tex_coords = [None,self.texture0[self.count[1]].tex_coords,None]
#swap third layer
if symbol == key._3:
self.count[2] += 1
if self.count[2] > 3:
self.count[2] = 0
self.layer[3][0].multi_tex_coords = [None,None,self.texture0[self.count[2]].tex_coords]
class group(pyglet.graphics.OrderedGroup):
def set_state(self):
glActiveTexture(GL_TEXTURE0)
glEnable(window.texture0[0].target)
glBindTexture(GL_TEXTURE_2D, window.texture0[0].id)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glActiveTexture(GL_TEXTURE1)
glEnable(window.texture0[1].target)
glBindTexture(GL_TEXTURE_2D, window.texture0[1].id)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glActiveTexture(GL_TEXTURE2)
glEnable(window.texture0[2].target)
glBindTexture(GL_TEXTURE_2D, window.texture0[2].id)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
if __name__ == '__main__':
window = test()
pyglet.app.run()