Welcome
Welcome to dinksoftware

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today!

PyGame Anaglyph

Holiverh's izHawt Python....

PyGame Anaglyph

Postby Holiverh » Sun Dec 19, 2010 3:23 pm

Here's a very simple function for "anaglyphing" PyGame surfaces. I heared somewhere that screen blending works best, but PyGame doesn't seem to support it. I tried to roll my own, but I couldn't fathom a way to do it. I also tried stripping out the colour channels in a more sohpisticated way, but it appears it would have been overkill (multiply-blending solid colour surfaces seems to work).

This isn't really appropriate for real-time "anaglyphing" as it runs quite slowly (tested with my paticle system). Although, your mileage may vary. :)

Code: Select all
import pygame

def anaglyph(source, xoffset):
   
   left = source.copy()
   right = source.copy()
   
   surface = pygame.surface.Surface(left.get_size())
   
   left_filter = pygame.surface.Surface(left.get_size())
   left_filter.fill((255, 0, 0))
   
   right_filter = pygame.surface.Surface(right.get_size())
   right_filter.fill((0, 255, 255))
   
   left.blit(left_filter, (0, 0), None, pygame.BLEND_MULT)
   right.blit(right_filter, (0, 0), None, pygame.BLEND_MULT)
   
   surface.blit(left, (0-xoffset, 0), None, pygame.BLEND_ADD)
   surface.blit(right, (0+xoffset, 0), None, pygame.BLEND_ADD)
   
   return surface

I tried to make a little utility out of it, but I can't seem to get it to work at the moment.

Original source image
Image
Download link

Resulting anaglyhped image
Image
User avatar
Holiverh
 
Posts: 243
Joined: Sun Jul 12, 2009 10:37 am
Location: East Anglia, UK

 

Re: PyGame Anaglyph

Postby Dink » Mon Dec 20, 2010 5:23 pm

That's cool! I had to loop up Wikipedia to see what analglyphs were lol, then I realized its the 3d effect.

Do these anaglyphs actually look 3d through 3d glasses (as in 3d movie cheap glasses not the $200 3d television glasses you can buy)?

Your image looks pretty good to me and there's not a whole lot of code either. I am working on one of the components for TBS and the code is growing rather large and intricate lol.
User avatar
Dink
 
Posts: 531
Joined: Sat Jul 11, 2009 9:59 am
Location: Australia


Return to Python

Who is online

Users browsing this forum: No registered users and 0 guests

cron
suspicion-preferred