My transparent .png's work great with pyglet.image.load() and img.blit()
I did have to include the following two lines for the transparency to
start working (I noticed them in one of the pyglet tutorial code
snippets):
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
Then, after that, all my .png images showed their transparency properly.
~ Nathan
I am currently working on a sprite library for pyglet in contrib/spryte. It's
in early stages yet (the API may change.) The intention is that it is capable
of blended blitting, rotation, animation, scaling, tile mapping, picking and
collision detection. It can actually most of that right now, but as I said
the code is quite young. It also depends on the experimental buffer
interface, and i can't vouch for the status of that (except that it's in
the "experimental" folder :)
> I have seen a number of other posts in pyglet-users asking about alpha
> transparency and rotation, and I think it's not really enough to tell
> them to use the OpenGL functions to get the effects. These basic
> effects should be built into the high-level API. I strongly feel that
> it should not be necessary to "drop down" to OpenGL for these two very
> common use cases. The mental context switch from nice pythonic Pyglet
> to C-based OpenGL is jarring and unnecessary.
Alex and I happen to share your view, which is a happy coincidence ;)
... and code is always welcome in an Open Source project written by
volunteers :)
> I think one convenient and non-disruptive (to the current API) way of
> supporting alpha transparency is to give PNG images alpha transparency
> by default (if there is an alpha layer present).
The alpha (transparency) channel from a PNG (or any other RGBA image) is
handled appropriately by pyglet.image. The key is to then instruct OpenGL how
to use that channel. There's dozens of operations that could potentially use
it -- which one is correct for all users of pyglet? It's because of this that
pyglet does not make any assumptions and does not enable any sort of
alpha-channel processing by default.
> And rotation should be in degrees.
The sprite library currently uses radians for rotation. I am on the fence
regarding using degrees, as the code underneath will always be working with
radians, and thus there's a fixed cost of conversion for each rotation API
operation.
Richard
Heh, well for a beta, I don't mind much at all. I've gotten more help
from the pyglet docs and this mailing list in the last two weeks than
I have from the pygame and its documentation in two years. Not to
mention that no one on pygame cared whether I could get it working or
not on OS X AND there hasn't been a release of any kind for 2.5 years.
I respect Phil Hassey, but so far my pyglet experience has been like
heaven in comparison to pygame. Fixes in SVN in a matter of hours or
minutes? Cool! No external dependencies that I have to install?
Cool! It uses OpenGL instead of SDL? Cool! It works on OS X
Leopard? Cool!
It appears (now maybe I'm reading this wrong -- no offense intended)
that you are arguing from a position that the pyglet mainainers have
finalized everything and they're never going to change anything. I
doubt that's the case. You'd probably get more traction if you posed
your feature requests as suggestions instead of rants. (Or maybe I'm
just misreading your tone. It's notoriously difficult to pinpoint the
tone someone is using when you are not used to their writing style)
Richard already stated that he and Alex agree with you. (I'm assuming
Richard is one of the pyglet devs?) With that in mind, good
implementation suggestions or patches will get you what you want
quicker than trying to convince the rest of us on the list. By the
way, I made the 2-line suggestion thinking to help you get your
program working, not because I'm advocating it as the best way to do
things. I happen to agree with the point you're trying to make (easy
access to common features without directly touching OpenGL).
> > ... and code is always welcome in an Open Source project written by volunteers :)
>
> I absolutely agree. But only a chosen few volunteers have SVN commit
> access.
So "svn diff" and submit the patch! The turnaround times on this list
have been amazing! If it's commit access you're looking for, you'll
be more likely to get it by systematically submitting useful
contributions.
I've been very pleased with my pyglet experience so far and plan to
convert my pygame projects to use pyglet ASAP. Thanks all!!! Two of
my friends and my brother have all started using pyglet because they
liked it so much when I showed it to them. If pyglet were a public
company, I'd buy stock. :-)
~ Nathan
> If pyglet were a public
> company, I'd buy stock. :-)
>
Me too!!!
André
> ~ Nathan
>
> >
>
Ok, you guys know that there isn't a business case in pyglet, right? :-)
On the image.blit suggestions: the alpha blend mode is a global OpenGL
state, not a texture parameter, so it doesn't make a lot of sense to
specify it during loading. It could easily be added as a parameter to
the blit method, however. Rotation could also be added as a parameter
to blit.
One problem with adding alpha/rotation to blit is that they would only
be applicable when blitting images to a framebuffer; however the same
blit method can currently be used between (almost) any two images
(framebuffer, texture, image data).
I should also point out that the blit method isn't really a high level
interface, so much as a convenient method to use while the "real" high
level interfaces are developed (see for example Richard's sprite
work). Besides being limited in its use, it's also extremely
inefficient compared to what's possible with a more game-oriented
design.
The goals of this 1.0 release are to abstract away the platform and
ctypes issues -- most of the higher-level ideas that require only
straight Python code were pushed back for future versions. Some of
these ideas exist in the experimental and contrib folders of the SVN
repository; others are just design outlines in mine and Richard's
heads :-)
Cheers
Alex.
> I think I'm also a little confused about where the appropriate place
> is to send feature adding patches or "experimental" code. I think the
> issue tracker is reserved for bug fixing. So where or who should I
> send more experimental ideas to? Taking up a page on the group space
> for a small new library feature seems silly. If you guys have a
> suggestion for that, I'm listening.
For small things like this, you can add a comment to the wishlist page
at http://code.google.com/p/pyglet/wiki/ReleaseSchedule -- this
ensures it doesn't get missed when making future design decisions.
Anything bigger, especially if you have a patch or working code, can
rightly deserve its own page in the group, I don't see any reason why
we should save space on Google's servers :-)
Cheers
Alex.
There is a bit of a gotcha here: if the pyglet Texture object gets
garbage collected the corresponding OpenGL texture will be deleted.
This can happen if you're only keeping track of the texture.id,
instead of the whole texture object -- so make sure you're careful to
retain the texture objects you'll be using within rabbyt; or go with
Matthew's other suggestion of replacing the load function.
Alex.
hehe. By 'slowly' I mean that everything new that I write is using pyglet.
But other things that have been in development for a while that still use
pygame for display and events. (My plan is to move them to pyglet; it just
hasn't happened yet.)
> > And I think that rabbyt.init_display() sends a wrong impression. I should
> > have named it 'init_pygame_display' or left it out entirely.
>
> It does because it calls to mind the Pygame way of doing things. I'm
> not that familiar with the internals of Rabbyt, but is there a
> particularly important reason why you have that function in the first
> place? It seems sort of redundant, or unnecessary.
I wanted it to be possible to use rabbyt without an opengl wrapper. (I was a
little frustrated with PyOpenGL at the time.) Originally it handled setting
the viewport and default opengl attributes, but now it just saves four lines
of boilerplate :P Yeah, it needs to be deprecated.
> Same goes for the fonts module you included. Are you writing a sprite
> library or a font/text rendering library? Focus!
That was due to needing... uh... font sprites... Yeah, I don't have much of
an excuse here. It should have been an example for the vertexarray module.
(Which I'll be removing as well...)
> > I just added support for using pyglet textures. Anything else you would
> > like?
>
> I'll get back to you with a little more detail on that, but for now,
> my big time nitpick with Rabbyt is that creating a Sprite object
> should be just as convenient with Pyglet as it is with Pygame. I
> should be able to pass in the name string of a PNG, and get a fully
> functional Sprite with nothing else to worry about, just like you can
> with Pygame right now.
Wish granted :) It'll automatically use pyglet if pyglet is importable and
pyglet.gl.get_current_context() does not return None.
MWM