It's already implemented for pyglet 1.1 ;-) In the meantime:
from pyglet import image
face_left = image.load('person.png').texture
face_right = face_left.get_region(0, 0, face_left.width, face_left.height)
t = face_right.tex_coords
face_right.tex_coords = t[3:6] + t[:3] + t[9:] + t[6:9]
Alex.
There's no telling ;-)
Alex.
The get_region method doesn't know that you've messed with the texture
coordinates. Either do your cropping before flipping, or create your
own get_region method.
The way this is working (flipping and cropping) is just by changing
the texture coordinates assigned to the texture. An image covering
the whole of an OpenGL texture has .tex_coords =
(0, 0, 0, # bottom left
1, 0, 0, # bottom right
1, 1, 0, # top right
0, 1, 0) # top left
For example, to crop off the left side of the image (leaving only the
right half), you'd use:
(.5, 0, 0, # bottom left
1, 0, 0, # bottom right
1, 1, 0, # top right
.5, 1, 0) # top left
The trick of flipping the image is to rearrange these numbers so the
left and right coordinates are swapped.
Alex.
Sure that is easier, I should not tell you about transformations. Do it with
textures.
I didn't think it. Big mouth. But, as I did throw the snowball, I will give
you a clue.
If you want to play with opengl transformations, note that you are not
transforming the image at all, you are transforming the entire view. Each
time you want to see a flipped image, you have to modify the view. You can
have a different view for each image. Endless possibilities, more
complexity.
First thing is that when you rotate or scale the view, you have to know
where the origin is (0,0). If you did not move it (or after calling
glLoadIdentity()), it is at bottom left corner. If you scale the view -1 at
x, now when you blit the image at (x,y) it will be flipped but blitted
outside your monitor, mirrored at -x.
If now you are doing:
img.blit (x,y,0)
You could do this to see the same results:
glLoadIdentity() # to ensure initial view
glTranslatef(x,y,0) # put the origin here (view in modified)
img.blit(0,0,0)
The same thing, more elegant:
glPushMatrix() # get a new copy of the view
glTranslatef(x,y,0)
img.blit(0,0,0)
glPopMatrix() # restore the original view
and this to see the flipped image:
glPushMatrix()
glTranslatef(x,y,0)
glScalef(-1,1,1) # or glRotate(180,0,1,0)
img.blit(0,0,0) # or img.blit(img.width,0,0), to get the
same position.
glPopMatrix()
The origin is the key here, and you better translate it to the center or the
image (play with half image sizes, translate to x+width/2, y+height/2, then
scale or rotate and finally blit at (-width/2, -height/2,0)).
You can survive knowing only about glLoadIdentity, glTranslatef, glScalef
and glRotatef.
Lots of tutorials out there. Good luck.