On 15 July 2011 17:21, Zombie Mariachis <[email protected]> wrote:
> Thanks a ton for all the info! To better explain what I've gotten the > code to do so far, and what I'm trying to do, I've uploaded some game > play from the project to youtube. > http://www.youtube.com/watch?v=zbX9Nj0P1ks > > As seen in the video, the background layers shift via the > glTranslatef draw instructions. Right now each layer is just a sprite > with it's own draw being called in the on_draw window event. I'd like > to batch all the draws for the background but when I do the > glTranslatef seems to be ignored. One thought was that each sprite's > 'def update' was being ignored, but I don't know, I'm new to all > this. > > -- > You received this message because you are subscribed to the Google Groups > "pyglet-users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/pyglet-users?hl=en. > > Wow, that looks really good, actually. Do you have an online page for the project? Now everything makes a bit more sense, especially after I had a few hours of sleep. Okay, it should be able to be done, but not in the way you expect it to be. I'll need to explain some things first, about how Pyglet does its things. First off, a Sprite contains an image that it uses for its texture. This is actually converted into a Texture object, and stored as sprite_name.texture. When you ask a Sprite to draw itself, it'll do this: self._vertex_list.draw(GL_QUADS) This vertex list is actually a graphics.vertex_list. This means that it contains a whole list of vertices, in various forms. For example, a vertex list can contain simultaneously, v3f (position in 3 dimensions stored as floats), t3f (texture coordinates in 3 dimensions as floats), c4i (vertex color information in RGBA as integers). This means that when you draw a vertex list, it already has ALL the info it needs to draw the vertices, textured, colored, whatever. Now THIS vertex list, actually contains a vertex DOMAIN, which is another object for management. This domain can contain a lot of different vertex lists. If you only have a single vertex list, it'll have its own domain it's actually calling for to draw itself. This seems complicated, but it's just a way of putting everything into its own thing. A vertex list contains all the properties needed to draw one 'shape' (or multiple, I suppose), and a vertex domain contains any number of vertex lists. In this case, the vertex list is just one and it's calling its single domain to draw it in GL_QUADS mode. Looking at the vertex domain draw code, we find out that it's pretty 1:1. It'll draw the vertex list immediately, with the properties it's told to. Like the position, texture coordinates and color specified above. So you want the background to scroll, this can be done in a number of ways. The Pyglet way, to me, would be to modify this vertex list's texture coordinates, instead of actually GL_Translate-ing the texture matrix. This means that every time you want the texture to move a bit, you go and reassign the 4 vertices' texture coordinates as being a bit 'higher'. This is actually pretty complicated to do properly, and I believe is prone to bugs. Possibly not, but it just seems like scratching your right ear with your left arm over your head. Now, the way you're doing it, it might work. I'm not completely sure and, again, I'm not in a position to test right now. My solution for it would be blitting the texture yourself manually. This means looking at Texture's blit code, and doing it yourself. This might work, but it might not. def draw(self): #first we set everything up like the texture does, but with modifying references t = self.texture.tex_coords x1 = x - self.texture.anchor_x y1 = y - self.texture.anchor_y x2 = x1 + (width is None and self.width or width) y2 = y1 + (height is None and self.height or height) array = (GLfloat * 32)( t[0], t[1], t[2], 1., x1, y1, z, 1., t[3], t[4], t[5], 1., x2, y1, z, 1., t[6], t[7], t[8], 1., x2, y2, z, 1., t[9], t[10], t[11], 1., x1, y2, z, 1.) #this is the initialising of data as in Texture.blit(), now we actually draw everything glPushAttrib(GL_ENABLE_BIT) glEnable(self.texture.target) glBindTexture(self.texture.target, self.texture.id) #keep in mind this is an EXPENSIVE operation in terms of time, each differing use glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) glInterleavedArrays(GL_T4F_V4F, 0, array) glDrawArrays(GL_QUADS, 0, 4) glPopClientAttrib() glPopAttrib() -- You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en.
