Rotation

37 views
Skip to first unread message

doh...@gmail.com

unread,
Aug 20, 2011, 1:07:45 PM8/20/11
to pyglet-users
Every time I rotate a sprite by 45 degrees, it looses quality. Click here for a screenshot. 

Adam Bark

unread,
Aug 20, 2011, 1:18:07 PM8/20/11
to pyglet...@googlegroups.com
On 20/08/11 18:07, doh...@gmail.com wrote:
> Every time I rotate a sprite by 45 degrees, it looses quality. Click
> here <http://img607.imageshack.us/img607/5111/comparethem.png> for a
> screenshot.

Ok.

Brian Fisher

unread,
Aug 20, 2011, 1:47:34 PM8/20/11
to pyglet...@googlegroups.com
Having quality drop with rotation is perfectly normal - it's expected
it would get a little blurry.

Maybe you are referring to the white halo you are getting around the
character (which perceptually makes the character appear darker)?

I think you're getting that because the "transparent" pixels around
the outside of the character are colored white. You should get the
same problem if you did sub-pixel positioning or scaling. White halos
on transforms is an artifact of bilinear filtering with RGBA as color
& opacity and white transparent pixels with a blend mode of:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Basically it needs to resample pixels in order to rotate, and when it
resamples the values at the edge:

(YourRGB, 1 alpha)
(White, 0 alpha)

for a 50% split, the bilinear filter math produces a color value of:

((YourRGB + White)/2, .5 alpha)

and then when that is rendered, it renders it as your color averaged
with white at 50% opacity, which is why you see a white halo.


The artist hack fix for the problem is to bleed out the color channel
over the transparent area - so like if the players shirt is red,
they'd paint a bunch of red transparent pixels out from the shirt. If
you have an editor that lets you edit RGB seperate from alpha, then go
into RGB mode with the art for this sprite, and you should see all the
surrounding white. If you then paint out the player color around it,
and use that image, you should see the halo disappear.


The correct programmer fix for this however is to switch to having
textures use premultiplied alpha (basically RGB is replaced with
RGB*Alpha), and also changing blend mode to:

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

that is the correct way to render textures using bilinear filtering,
and it's immune to this effect. But your textures and blend mode need
to match, and I don't know how to do this with pyglet.

On Sat, Aug 20, 2011 at 10:07 AM, doh...@gmail.com <doh...@gmail.com> wrote:
> Every time I rotate a sprite by 45 degrees, it looses quality. Click here
> for a screenshot.
>

> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To post to this group, send email to pyglet...@googlegroups.com.
> To unsubscribe from this group, send email to
> pyglet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.
>

Brian Fisher

unread,
Aug 20, 2011, 2:17:47 PM8/20/11
to pyglet...@googlegroups.com
Oh, and if you send the original source image for the sprite, it would
help in confirming the source of the problem and I could give you an
example of the workaround

doh...@gmail.com

unread,
Aug 20, 2011, 6:05:32 PM8/20/11
to pyglet...@googlegroups.com
I used the "artist hack" using the GIMP and it worked. Thank you, Brian!

Jonathan Hartley

unread,
Aug 21, 2011, 6:50:33 AM8/21/11
to pyglet...@googlegroups.com
I once made a blog post describing this 'pre-multiplied alpha' fix, ostensibly so that I understood what was going on.

http://tartley.com/?p=945

However I have never since used the described fix, so there may be errors in my description.

DR0ID

unread,
Aug 21, 2011, 2:17:30 PM8/21/11
to pyglet...@googlegroups.com
> --
> You received this message because you are subscribed to the Google
> Groups "pyglet-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pyglet-users/-/h7TJ-OClED0J.

> To post to this group, send email to pyglet...@googlegroups.com.
> To unsubscribe from this group, send email to
> pyglet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.


Hi

ATTENTION: I got a trojan warning on your page:

Object: http://www.tartley.com/?p=945|>{gzip}
Infection: HTML:IFrame-PE [Trj]


~DR0ID

Jonathan Hartley

unread,
Aug 23, 2011, 2:08:46 AM8/23/11
to pyglet...@googlegroups.com
Dammit. Thanks for the heads-up. I have no idea how to fix that. I guess I'll start by googling it.
Reply all
Reply to author
Forward
0 new messages