Blitting all but one color in OpenGL
Hi.
I am relatively new to OpenGL, my previous games have all used good ol' CopyBits, but I decided to take the plunge and use OpenGL for my current project. Its a simple 2D side-scroller, basically just textured quads. I have it going nicely, but I can't figure out quite how to duplicate the CopyBits functionality that lets you blit all but pixels of a certain color.
Essentially I just want to not copy the black (or any other specified color) pixels, while blitting everything else at its normal color.
I have been messing around with blend modes for the past couple hours, but I can't seem to get one that will do what I want. Either everything is blitted, or it becomes translucent.
Whats the simplest and fastest way to do this? (I would prefer not having to resort to masks)
Thanks!
I am relatively new to OpenGL, my previous games have all used good ol' CopyBits, but I decided to take the plunge and use OpenGL for my current project. Its a simple 2D side-scroller, basically just textured quads. I have it going nicely, but I can't figure out quite how to duplicate the CopyBits functionality that lets you blit all but pixels of a certain color.
Essentially I just want to not copy the black (or any other specified color) pixels, while blitting everything else at its normal color.
I have been messing around with blend modes for the past couple hours, but I can't seem to get one that will do what I want. Either everything is blitted, or it becomes translucent.
Whats the simplest and fastest way to do this? (I would prefer not having to resort to masks)
Thanks!
The best way is to use a proper alpha channel. That way you can get the edges of the sprite looking right even in the face of texture filtering.
I don't know how to do what you're asking without a texture shader. I guess NV_register_combiners might be enough, but then you exclude all ATI cards...
I don't know how to do what you're asking without a texture shader. I guess NV_register_combiners might be enough, but then you exclude all ATI cards...
Have a look at the Color Keying demo at http://nate.scuzzy.net/gltut/
I think all he does is generate an alpha channel (mask) on the fly though.
I think all he does is generate an alpha channel (mask) on the fly though.
You can use
glAlphaFunc( GL_GREATER, 0.3 );
glEnable( GL_ALPHA_TEST );
and have an alpha channel in your sprite textures. In the above example everything greater than 0.3 in the alpha channel is drawn on screen. Usually the alpha channel pixels are either 0 or 1 (0 or 255 with an 8 bit channel) so the value is not critical.
KenD
glAlphaFunc( GL_GREATER, 0.3 );
glEnable( GL_ALPHA_TEST );
and have an alpha channel in your sprite textures. In the above example everything greater than 0.3 in the alpha channel is drawn on screen. Usually the alpha channel pixels are either 0 or 1 (0 or 255 with an 8 bit channel) so the value is not critical.
KenD
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
iPhone OpenGL color bug | agreendev | 8 | 11,064 |
Aug 12, 2010 08:20 PM Last Post: AnotherJake |
|
? Find color value of 'pixel' in color buffer? | Elphaba | 1 | 6,164 |
Jul 22, 2009 01:23 PM Last Post: Bachus |
|
OpenGL Color Buffer Overwrite | Talyn | 8 | 8,945 |
Jan 4, 2009 02:44 AM Last Post: papillon68 |
|
SDL Blitting | KidTsunami | 5 | 9,557 |
May 8, 2008 08:17 AM Last Post: leRiCl |
|
OpenGL Color map | nkpkd | 4 | 6,132 |
Mar 30, 2007 10:47 AM Last Post: nkpkd |