Mysterious darkening on sprite draw

30 views
Skip to first unread message

Joseph Marlin

unread,
Jul 5, 2011, 11:49:21 PM7/5/11
to pyglet...@googlegroups.com
This seems like it would be a common problem for beginners, but I couldn't find anything on the topic. 

I start off drawing a nice background:
def on_draw():
    bg.blit_tiled(map_bottom_left[0], map_bottom_left[1], 0, map_width, map_height)

I can then add in kytten, which I finally convinced to work. That is drawn using a batch:
def on_draw():
    bg.blit_tiled(map_bottom_left[0], map_bottom_left[1], 0, map_width, map_height)
    batch.draw()
That also works nicely: http://i.imgur.com/4wUtl.png

However, as soon as I draw a sprite, the background image gets very dark. Strangely, the menu does not:
def on_draw():
    bg.blit_tiled(map_bottom_left[0], map_bottom_left[1], 0, map_width, map_height)
    sprite.draw()
    batch.draw()
In the image, the background might look like it is black, but it is actually just darkened quite a bit. I don't know why it is darkening. The sprites show up normally colored, as does the menu, as you can see.

Any ideas?
Thanks!

Bruce Smith

unread,
Jul 7, 2011, 6:38:12 PM7/7/11
to pyglet...@googlegroups.com
No specific ideas, but this sort of bug in OpenGL code often means that the newly-added call (in this case sprite.draw()) is changing some OpenGL state without saving it and restoring it. I don't know a shortcut to find out *which* state except reading its code and/or guessing.

- Bruce Smith

Michael Red

unread,
Jul 8, 2011, 5:52:02 AM7/8/11
to pyglet...@googlegroups.com

--
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.

I've looked into TileableTexture and Sprite, and the only thing that strikes me as odd is that Sprite activates GL_BLEND, then sets its own function, but doesn't return to what it was before-hand. Try adding 'from pyglet.gl import *' at the top of your code, then doing 'glDisable(GL_BLEND)' before the blit_tiled call.

Joseph Marlin

unread,
Jul 8, 2011, 7:34:22 PM7/8/11
to pyglet-users
> I've looked into TileableTexture and Sprite, and the only thing that strikes
> me as odd is that Sprite activates GL_BLEND, then sets its own function, but
> doesn't return to what it was before-hand. Try adding 'from pyglet.gl import
> *' at the top of your code, then doing 'glDisable(GL_BLEND)' before the
> blit_tiled call.

Thanks! This worked! Strange thing I also discovered is that this only
happens when the image needs to be tiled. If the image is large enough
to avoid the need to tile, no dimming occurs. Thanks again for help
Michael, Bruce, I really appreciate it!

Michael Red

unread,
Jul 9, 2011, 7:40:49 AM7/9/11
to pyglet...@googlegroups.com
--
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.


I'm actually not sure why this happens, but I'll look into it and submit a patch once I figure out what is going wrong.
Reply all
Reply to author
Forward
0 new messages