Re: [pygame] font alpha
Rendering the semi-transparent text with the appropriate background 'seems' to make it work again. #- # Mike's Code modified to use non-black screen import pygame import time pygame.init() screen = pygame.display.set_mode((640,480), pygame.SRCALPHA) screen.fill((255,0,255)) myFont = pygame.font.Font(None, 30) nonTransparent = myFont.render(This text should be fully opaque, 1, (255,255,255)) screen.blit(nonTransparent, (0,0)) myText = 'This text should be somewhat transparent' semiTransparent = myFont.render(myText, 1, (255,255,255), (255,0,255)) newSurf = pygame.Surface(myFont.size(myText)) newSurf.blit(semiTransparent,(0,0)) newSurf.set_alpha(100) screen.blit(newSurf, (0,100)) pygame.display.flip() time.sleep(5) -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less. - Piet Hein
Re: [pygame] font alpha
haha... I assumed you wanted something font letters with alpha - so you had something that could be drawn over something other than a solid color - but I guess you could always grab the background behind where you want the text in a surface, blit the text over the piece of the background you grabbed in the surface, then set alpha on the background surface and blit that, and it would work for the effect you want no matter the background. On 9/6/07, Mike Lawrence [EMAIL PROTECTED] wrote: Rendering the semi-transparent text with the appropriate background 'seems' to make it work again. #- # Mike's Code modified to use non-black screen import pygame import time pygame.init() screen = pygame.display.set_mode((640,480), pygame.SRCALPHA) screen.fill((255,0,255)) myFont = pygame.font.Font(None, 30) nonTransparent = myFont.render(This text should be fully opaque, 1, (255,255,255)) screen.blit(nonTransparent, (0,0)) myText = 'This text should be somewhat transparent' semiTransparent = myFont.render(myText, 1, (255,255,255), (255,0,255)) newSurf = pygame.Surface(myFont.size(myText)) newSurf.blit(semiTransparent,(0,0)) newSurf.set_alpha(100) screen.blit(newSurf, (0,100)) pygame.display.flip() time.sleep(5) -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less. - Piet Hein
Re: [pygame] font alpha
Ah, well eventually I'll be overlaying different font layers over top of one another so maybe you're right in that my solution is still unsatisfactory. On 6-Sep-07, at 2:00 PM, Brian Fisher wrote: haha... I assumed you wanted something font letters with alpha - so you had something that could be drawn over something other than a solid color - but I guess you could always grab the background behind where you want the text in a surface, blit the text over the piece of the background you grabbed in the surface, then set alpha on the background surface and blit that, and it would work for the effect you want no matter the background. On 9/6/07, Mike Lawrence [EMAIL PROTECTED] wrote: Rendering the semi-transparent text with the appropriate background 'seems' to make it work again. #- # Mike's Code modified to use non-black screen import pygame import time pygame.init() screen = pygame.display.set_mode((640,480), pygame.SRCALPHA) screen.fill((255,0,255)) myFont = pygame.font.Font(None, 30) nonTransparent = myFont.render(This text should be fully opaque, 1, (255,255,255)) screen.blit(nonTransparent, (0,0)) myText = 'This text should be somewhat transparent' semiTransparent = myFont.render(myText, 1, (255,255,255), (255,0,255)) newSurf = pygame.Surface(myFont.size(myText)) newSurf.blit(semiTransparent,(0,0)) newSurf.set_alpha(100) screen.blit(newSurf, (0,100)) pygame.display.flip() time.sleep(5) -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less. - Piet Hein -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less. - Piet Hein
Re: [pygame] font alpha
I found Numeric indispensable for shadow effects. import pygame import Numeric pygame.init() screen = pygame.display.set_mode((640,480), pygame.SRCALPHA, 32) screen.fill((0,0,255)) myFont = pygame.font.Font(None, 30) nonTransparent = myFont.render(This text should be fully opaque, 1, (255,255,255)) screen.blit(nonTransparent, (0,0)) semiTransparent = myFont.render(This text should be somewhat transparent, 1, (255,255,255)) # Get access to the alpha band of the image. pixels_alpha = pygame.surfarray.pixels_alpha(semiTransparent) # Do a floating point multiply, by alpha 100, on each alpha value. # Then truncate the values (convert to integer) and copy back into the surface. pixels_alpha[...] = (pixels_alpha * (100 / 255.0)).astype(Numeric.UInt8) # Unlock the surface. del pixels_alpha screen.blit(semiTransparent, (0,100)) pygame.display.flip() Hope it helps. Lenard Lindstrom Mike Lawrence wrote: Ah, well eventually I'll be overlaying different font layers over top of one another so maybe you're right in that my solution is still unsatisfactory. On 6-Sep-07, at 2:00 PM, Brian Fisher wrote: haha... I assumed you wanted something font letters with alpha - so you had something that could be drawn over something other than a solid color - but I guess you could always grab the background behind where you want the text in a surface, blit the text over the piece of the background you grabbed in the surface, then set alpha on the background surface and blit that, and it would work for the effect you want no matter the background. On 9/6/07, Mike Lawrence [EMAIL PROTECTED] wrote: Rendering the semi-transparent text with the appropriate background 'seems' to make it work again. #- # Mike's Code modified to use non-black screen import pygame import time pygame.init() screen = pygame.display.set_mode((640,480), pygame.SRCALPHA) screen.fill((255,0,255)) myFont = pygame.font.Font(None, 30) nonTransparent = myFont.render(This text should be fully opaque, 1, (255,255,255)) screen.blit(nonTransparent, (0,0)) myText = 'This text should be somewhat transparent' semiTransparent = myFont.render(myText, 1, (255,255,255), (255,0,255)) newSurf = pygame.Surface(myFont.size(myText)) newSurf.blit(semiTransparent,(0,0)) newSurf.set_alpha(100) screen.blit(newSurf, (0,100)) pygame.display.flip() time.sleep(5) -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less. - Piet Hein -
[pygame] font alpha
Hi all, Apologies for the seemingly newb help request but I can't seem to figure out how to vary the alpha value of rendered font surfaces. Here are my attempts thusfar: import pygame pygame.init() screen = pygame.display.set_mode((640,480), pygame.SRCALPHA) screen.fill((0,0,0)) myFont = pygame.font.Font(None, 30) nonTransparent = myFont.render(This text should be fully opaque, 1, (255,255,255)) screen.blit(nonTransparent, (0,0)) semiTransparent = myFont.render(This text should be somewhat transparent, 1, (255,255,255)) semiTransparent.set_alpha(100) screen.blit(semiTransparent, (0,100)) pygame.display.flip() #When I flip, both messages are the same color, indicating that the transparency on the second failed -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less. - Piet Hein
Re: [pygame] font alpha
Mike Lawrence wrote: Hi all, Apologies for the seemingly newb help request but I can't seem to figure out how to vary the alpha value of rendered font surfaces. Here are my attempts thusfar: import pygame pygame.init() screen = pygame.display.set_mode((640,480), pygame.SRCALPHA) screen.fill((0,0,0)) myFont = pygame.font.Font(None, 30) nonTransparent = myFont.render(This text should be fully opaque, 1, (255,255,255)) screen.blit(nonTransparent, (0,0)) semiTransparent = myFont.render(This text should be somewhat transparent, 1, (255,255,255)) semiTransparent.set_alpha(100) screen.blit(semiTransparent, (0,100)) pygame.display.flip() #When I flip, both messages are the same color, indicating that the transparency on the second failed I don't think that fonts are rendered with surface alpha to start. does set_alpha apply surface alpha if they don't have it already? Maybe try convert_alpha first? It's possible that since you're aliasing the fonts they might be using per-pixel alpha which might conflict with surface alpha. Just some suggestions, I've never tried this. -Luke -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less. - Piet Hein
Re: [pygame] font alpha
Good call Luke. Removing antialiasing did indeed result in a surface with a usable set_alpha component. However, I'd really like to have antialiased text. Inserting 'semiTransparent.convert_alpha()' between lines 9 and 10 didn't seem to help either. On 5-Sep-07, at 9:18 PM, Luke Paireepinart wrote: Mike Lawrence wrote: Hi all, Apologies for the seemingly newb help request but I can't seem to figure out how to vary the alpha value of rendered font surfaces. Here are my attempts thusfar: import pygame pygame.init() screen = pygame.display.set_mode((640,480), pygame.SRCALPHA) screen.fill((0,0,0)) myFont = pygame.font.Font(None, 30) nonTransparent = myFont.render(This text should be fully opaque, 1, (255,255,255)) screen.blit(nonTransparent, (0,0)) semiTransparent = myFont.render(This text should be somewhat transparent, 1, (255,255,255)) semiTransparent.set_alpha(100) screen.blit(semiTransparent, (0,100)) pygame.display.flip() #When I flip, both messages are the same color, indicating that the transparency on the second failed I don't think that fonts are rendered with surface alpha to start. does set_alpha apply surface alpha if they don't have it already? Maybe try convert_alpha first? It's possible that since you're aliasing the fonts they might be using per-pixel alpha which might conflict with surface alpha. Just some suggestions, I've never tried this. -Luke -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less. - Piet Hein -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less. - Piet Hein
Re: [pygame] font alpha
Got it. You need to blit the rendered text to a new surface then change the alpha value of that new surface before blitting it to screen. import pygame pygame.init() screen = pygame.display.set_mode((640,480), pygame.SRCALPHA) screen.fill((0,0,0)) myFont = pygame.font.Font(None, 30) nonTransparent = myFont.render(This text should be fully opaque, 1, (255,255,255)) screen.blit(nonTransparent, (0,0)) myText = 'This text should be somewhat transparent' semiTransparent = myFont.render(myText, 1, (255,255,255)) newSurf = pygame.Surface(myFont.size(myText)) newSurf.blit(semiTransparent,(0,0)) newSurf.set_alpha(100) screen.blit(newSurf, (0,100)) pygame.display.flip() On 5-Sep-07, at 9:47 PM, Mike Lawrence wrote: Good call Luke. Removing antialiasing did indeed result in a surface with a usable set_alpha component. However, I'd really like to have antialiased text. Inserting 'semiTransparent.convert_alpha()' between lines 9 and 10 didn't seem to help either. On 5-Sep-07, at 9:18 PM, Luke Paireepinart wrote: Mike Lawrence wrote: Hi all, Apologies for the seemingly newb help request but I can't seem to figure out how to vary the alpha value of rendered font surfaces. Here are my attempts thusfar: import pygame pygame.init() screen = pygame.display.set_mode((640,480), pygame.SRCALPHA) screen.fill((0,0,0)) myFont = pygame.font.Font(None, 30) nonTransparent = myFont.render(This text should be fully opaque, 1, (255,255,255)) screen.blit(nonTransparent, (0,0)) semiTransparent = myFont.render(This text should be somewhat transparent, 1, (255,255,255)) semiTransparent.set_alpha(100) screen.blit(semiTransparent, (0,100)) pygame.display.flip() #When I flip, both messages are the same color, indicating that the transparency on the second failed I don't think that fonts are rendered with surface alpha to start. does set_alpha apply surface alpha if they don't have it already? Maybe try convert_alpha first? It's possible that since you're aliasing the fonts they might be using per-pixel alpha which might conflict with surface alpha. Just some suggestions, I've never tried this. -Luke -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less. - Piet Hein -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less. - Piet Hein -- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less. - Piet Hein
Re: [pygame] font alpha
Mike, I don't think the blit to another surface is doing what you think it's doing. Run your code again, but this time filling the screen to something other than black, and you'll see what I mean. List, I think this is the 3rd time I've seen someone emailing this list trying to figure out how to blit a per-pixel alpha surface with a surface alpha. Since pygame does it's own SW alpha blending (apart from SDL I mean) anyways, seems like supporting this case is something pygame could do... would there be anything wrong or particularly hard to do with making it so if you call set_alpha with alpha 0 or 255 on a per-pixel alpha surface, then blits with it use both surface alpha and per-pixel? #- # Mike's Code modified to use non-black screen import pygame import time pygame.init() screen = pygame.display.set_mode((640,480), pygame.SRCALPHA) screen.fill((255,0,255)) myFont = pygame.font.Font(None, 30) nonTransparent = myFont.render(This text should be fully opaque, 1, (255,255,255)) screen.blit(nonTransparent, (0,0)) myText = 'This text should be somewhat transparent' semiTransparent = myFont.render(myText, 1, (255,255,255)) newSurf = pygame.Surface(myFont.size(myText)) newSurf.blit(semiTransparent,(0,0)) newSurf.set_alpha(100) screen.blit(newSurf, (0,100)) pygame.display.flip() time.sleep(5)