[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Saving Alpha Channels
- To: "pygame-users@xxxxxxxx" <pygame-users@xxxxxxxx>
- Subject: [pygame] Saving Alpha Channels
- From: "Ian Mallett" <geometrian@xxxxxxxxx>
- Date: Sat, 4 Oct 2008 20:34:56 -0700
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Sat, 04 Oct 2008 23:35:00 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type; bh=0OWt9kVC49IL8muLuvcKPuf7tthVQP4eroVcIli7p2A=; b=MbtJEj/x++cUAcD1aBQyJoATUkU0+gmkz8mRYwF7i2701x0RkHPy84Ufy409kG0BYT g41CMKnKQ4lPd/CyoILlV/60QhAJnTHjOHlV08toIldmaxIOdpwMWHoDBOTgXo1N878f 5n0cBPv0kbvLt1oJrm4vbMsoLsTYO1Du6cMwo=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=xb2KUHty+WsMp9dYbE2OM+9d4vaS+S0Kon5lChTZ8UzGnQPmS/o/AVFkR84frCL1QN WlLQyKPzgumvJIMB6d2LCuFggpil5Ws3dUb1oAZ1zr/BReZgukCWQKOxXOraz/r65ZTG T0AeAqEV7pMekC3YdbO+3v49iIm/dHi6+kQAk=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Hi,
I'm running into random troubles with PyOpenGL transparency again, and the simplest solution is just to make the textures have transparency. Normally, I would just add the transparency in an image editor, but unfortunately I have ~250 images. My solution is programming! I wrote a script which should convert all the images to be ~50% transparent:
import pygame
from pygame.locals import *
import sys, os
pygame.init()
Surface = pygame.display.set_mode((256,256))
Images = []
for x in xrange(1,250,1):
numstr = str(x)
while len(numstr) < 4:
numstr = "0"+numstr
img = pygame.Surface((256,256))
img.blit(pygame.image.load(str(x)+".jpg").convert(),(0,0))
img.set_alpha(128)
Images.append(img)
pygame.image.save(img,str(x)+".png")
frame = 0
Clock = pygame.time.Clock()
while True:
Surface.fill((0,0,0))
Surface.blit(Images[frame],(0,0))
frame = (frame+1)%len(Images)
pygame.display.flip()
Clock.tick(50)
Now, what I see here is a window open and then a nice animation of the images playing across it. The images are darker, because I am seeing the black (Surface.fill((0,0,0))) through the images. Changing the alpha value changes the brightness. Unfortunately, the saved images do not have the alpha channel, which means that they don't have transparency which means that the textures don't work.
Ideas?
Ian