In experimeting with creating simple colored shapes with pyglet.image
(rather than drawing with pyglet.graphics or in GL directly) I've run
into a problem I can't figure out, dealing with blitting an image,
that has been blitted into, into another texture. That probably sounds
a little confusing so I'll try my best to explain.

I make a dictionary of some colors and a size constant like this:

colors = {
            'playfield' : (255, 255, 255, 255),
            'red' :       (255, 0, 0, 255),
            'sub_red' :   (255, 50, 20, 255),
            'green' :     (0, 255, 0, 255),
            'sub_green' : (20, 255, 50, 255),
            'blue' :      (0, 0, 255, 255),
            'sub_blue' :  (20, 50, 255, 255)}

size = 32


Then I have a class like this:

class Block(pyglet.image.SolidColorImagePattern):
    def __init__(self, color, size):
        x, y = size
        super(Block, self).__init__(colors[color])
        self.image = self.create_image(x, y)
        self.texture = self.image.get_texture()


This makes a block of size by size with color (in this example size is
32) and creates a texture of it.

Then in the same class's constructor I have this:

        sub_color = 'sub_%s' % color
        super(Block, self).__init__(colors[sub_color])
        center = self.create_image(12, 12)
        top = self.create_image(32, 1)
        bottom = self.create_image(32, 1)
        left = self.create_image(1, 32)
        right = self.create_image(1, 32)

        self.texture.blit_into(center, 10, 10, 0)
        self.texture.blit_into(top, 0, 31, 0)
        self.texture.blit_into(bottom, 0, 0, 0)
        self.texture.blit_into(left, 0, 0, 0)
        self.texture.blit_into(right, 31, 0, 0)


This creates a new color of sub_color, and five new shapes -- a
smaller square which I blit into the texture, and four rectangles I
blit onto the texture's edges. This works as expected, so if I blit
the image onto the screen I get a pseudo-shaded Block.

Next I have a class like this:

class Shape(pyglet.sprite.Sprite):
    def __init__(self, color, size, shape):
        image = pyglet.image.Texture.create(size*4, size*2)
        super(Shape, self).__init__(image)


This creates a sprite with an empty texture for an image. Then in the
constructor of Shape I create some images using the Block class:

        self.block1 = Block(color, (size, size)).image
        block2 = Block(color, (size, size)).image
        block3 = Block(color, (size, size)).image
        block4 = Block(color, (size, size)).image

        self.image.blit_into(self.block1, 0, 0, 0)
        self.image.blit_into(block2, size, size, 0)
        self.image.blit_into(block3, size*2, 0, 0)
        self.image.blit_into(block4, size*3, size, 0)


Then make a shape:

shape = Shape('red', size, 'I')

(note the third argument 'I', the shape parameter, doesn't do anything
yet)


Then draw:

@window.event
def on_draw():
    window.clear()
    shape.draw()
    shape.block1.blit(96,100)


As you can see if you run this, the block1 image blits separately as
expected, but when I blit the same block1 image into the Shape
texture, I lose the pseudo-shading. I've read all the threads I could
find here on blit_into but this is still a mystery -- does anyone know
what's happening here? Thanks for any help.

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

Reply via email to