It's been a while since I've posted this thread. For any other users that ended up here, I did end up getting this working with the pyglet and zsprite, but it's a process and will require some careful design decisions. Hopefully this helps people.
1) If you plan to use integer numbers as your Z, you need to modify the default -1, 1 near/far values in your matrix, this includes the default Window and overriding the on_resize functions. Otherwise you need to set the matrix manually yourself before you draw your scene or just use floats to represent your Z axis (and enable subpixel on sprites). If you don't do this, they will not appear at all. 2) If any geometry intersects each other (same position on x, y, and z; or shares the same texture) you can get unpredictable behavior (sprites appearing out of order, weird collisions). Pyglet does not draw textures in order of creation (so texture 10 can render before texture 5 and 1, for instance) nor does it matter if they have a shared regular Group parent. So you cannot rely on what will show up without using OrderedGroups. This will force them to render as separate draw calls. The other method which works, if you want them in the same layer without collisions, is to give each sprite or entity it's own tiny z offset (0.01, 0.011, etc). This will ensure they no longer intersect. The downside is you have to enable subpixel access and have to be careful with sprite positions so they aren't between integers which can lead to more unpredictable behavior. I'm also not sure if float precision could be an issue, depending on how big your floats are, but something to think about. 3) Transparency (or I should say translucency) is the bigger problem. Most of the normal cases (alpha is 1 or 0) be alleviated with the alpha test, the bigger issue is when alpha is between 0 or 1. So if you have an object that fades out/in or a texture that has pixels between 0 and 1 alpha, requires it's drawn last. By drawn last, in this context means, either in the highest OrderedGroup or create a separate batch for it (for instance, opaque batch, transparent batch). So the opaque batch needs to been drawn already before you draw transparency. If you don't, it will have nothing to blend into except the glClearColor (usually black) and your blending will come out incorrectly. So setting a sprite to the transparent batch or group when it's opacity changes between 0 and 1 is all you need to do. I ended up doing a separate batch as the better approach (which also seemed faster performance wise rather than adding another orderedgroup), because that will alleviate another issue with transparency. Sure your transparent objects and opaque objects are now drawn correctly, but what if you have two transparent objects in the same batch? Now those may appear out of order... great. This may or may not be something your application has to deal with. If it does, you need to sort your transparent objects from furthest to closest. I believe you can do this with a batch as draw_subset, but requires you to pass the vertex lists of them. You will have to maintain your own list of vertex lists added into the transparent batch, because Pyglet does not store these after it's been allocated. Draw_subset is also a lot slower, so this only really works if you aren't going to have a ton of "translucent" objects. On Friday, April 5, 2019 at 1:57:04 AM UTC-5, Marcin Skibiński wrote: > > Hi, that would be probably the best. > But to be honest i still have some unexpected resoults when i mix > batch_groups and z-depth. On the other hand if users will go with the basic > -1,1 range of depth they have to remeber to set subpixel=true for each > sprite at the creation stage. > Unfortunately it looks that it is quite tricky to use it right now > > Pt., 5.04.2019, 08:05 użytkownik Benjamin Moran <[email protected] > <javascript:>> napisał: > >> Hi Marcin, >> >> This is mostly because of how z coordinates are handled in OpenGL being >> opposite from what you might expect. >> At the moment, I don't plan to merge this in (because of the blending >> hurdles mentioned earlier in this thread). >> >> Maybe we could leave the ZSprite class in the examples folder in the >> repository? That way it's available for those >> who want it, and understand the tradeoffs. >> >> >> On Sunday, March 31, 2019 at 7:36:03 AM UTC+9, Marcin wrote: >>> >>> *when i have used the standard version it was opposite >>> >>> W dniu sobota, 30 marca 2019 23:35:05 UTC+1 użytkownik Marcin napisał: >>>> >>>> Good Afternoon, >>>> >>>> When i use the "new" sprite.py the Z ordering works nice. >>>> >>>> One change that i have noticed is that batch groups are drawn from >>>> bigger number to lower (when i have used . Do you plan to keep this that >>>> whey in the future versions? >>>> >>>> [image: Przechwytywanie.PNG] >>>> >>>> >>>> >>>> W dniu środa, 6 lutego 2019 02:46:19 UTC+1 użytkownik Benjamin Moran >>>> napisał: >>>>> >>>>> Sorry for the very late reply. I just realized I never got back to >>>>> this. >>>>> In case you're still interested, the line you're looking for is: >>>>> >>>>> gl.glOrtho(0, max(1, width), 0, max(1, height), -1, 1) >>>>> >>>>> At the end, the -1, 1 is responding to the z depth. You can change >>>>> these values to something higher, like 255. >>>>> >>>>> >>>>> On Saturday, December 8, 2018 at 9:46:29 PM UTC+9, Darth Dan wrote: >>>>>> >>>>>> Yeah, looks about right when I divide my Z with a large enough number. >>>>>> Except that it also seems to be functioning in reverse, but that's >>>>>> easy to fix. >>>>>> >>>>>> def on_resize(self, width, height): >>>>>> """A default resize event handler. >>>>>> >>>>>> This default handler updates the GL viewport to cover the >>>>>> entire >>>>>> window and sets the ``GL_PROJECTION`` matrix to be orthogonal >>>>>> in >>>>>> window space. The bottom-left corner is (0, 0) and the >>>>>> top-right >>>>>> corner is the width and height of the window in pixels. >>>>>> >>>>>> Override this event handler with your own to create another >>>>>> projection, for example in perspective. >>>>>> """ >>>>>> viewport = self.get_viewport_size() >>>>>> gl.glViewport(0, 0, max(1, viewport[0]), max(1, viewport[1])) >>>>>> gl.glMatrixMode(gl.GL_PROJECTION) >>>>>> gl.glLoadIdentity() >>>>>> gl.glOrtho(0, max(1, width), 0, max(1, height), -1, 1) >>>>>> gl.glMatrixMode(gl.GL_MODELVIEW) >>>>>> >>>>>> Unfortunately this gives me very little info as I never worked with >>>>>> OpenGL before in my life let's see if I can finc anything on it in the >>>>>> internet though. window._init_.draw() method only has X and Y >>>>>> coordinates >>>>>> as args, is that correct? >>>>>> >>>>> -- >> 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] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at https://groups.google.com/group/pyglet-users. >> For more options, visit https://groups.google.com/d/optout. >> > -- 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 https://groups.google.com/group/pyglet-users. For more options, visit https://groups.google.com/d/optout.
