C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old May 9th, 2008, 12:03 PM
beloxx beloxx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 6 beloxx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 28 sec
Reputation Power: 0
Transparency c++/opengl/sdl

Hi, Im working with sld and opengl but I cant figure out how can I make the background of an image transparent. I imported a gif library for sdl but it still does not work.

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, XSize, YSize, 0, 0, 1);
glMatrixMode (GL_MODELVIEW);

glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);

SDL_PixelFormat RGBAFormat;
RGBAFormat.palette = 0; RGBAFormat.colorkey = 0; RGBAFormat.alpha = 0;
RGBAFormat.BitsPerPixel = 32; RGBAFormat.BytesPerPixel = 4;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
RGBAFormat.Rmask = 0xFF000000; RGBAFormat.Rshift = 0; RGBAFormat.Rloss = 0;
RGBAFormat.Gmask = 0x00FF0000; RGBAFormat.Gshift = 8; RGBAFormat.Gloss = 0;
RGBAFormat.Bmask = 0x0000FF00; RGBAFormat.Bshift = 16; RGBAFormat.Bloss = 0;
RGBAFormat.Amask = 0x000000FF; RGBAFormat.Ashift = 24; RGBAFormat.Aloss = 0;
#else
RGBAFormat.Rmask = 0x000000FF; RGBAFormat.Rshift = 24; RGBAFormat.Rloss = 0;
RGBAFormat.Gmask = 0x0000FF00; RGBAFormat.Gshift = 16; RGBAFormat.Gloss = 0;
RGBAFormat.Bmask = 0x00FF0000; RGBAFormat.Bshift = 8; RGBAFormat.Bloss = 0;
RGBAFormat.Amask = 0xFF000000; RGBAFormat.Ashift = 0; RGBAFormat.Aloss = 0;
#endif


SDL_Surface * orig = NULL;

orig = SDL_LoadBMP("image.bmp");
if(orig == NULL){
....
...

Does anyone know what may be the problem?

PS I also tried png. Could anyone help me with that please? Ive been trying to figure it out for over 5 hours

Reply With Quote
  #2  
Old May 9th, 2008, 12:44 PM
ComputerPhreak's Avatar
ComputerPhreak ComputerPhreak is offline
Super User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 644 ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level)ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level)ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level)ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level)ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level)ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level)ComputerPhreak User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 6 Days 20 h 12 m 53 sec
Reputation Power: 69
First, please use code tags next time you post.

Did you set the OpenGL blend mode to one that supports a alpha blending? Usually you'll want something like:

Code:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Reply With Quote
  #3  
Old May 9th, 2008, 05:20 PM
beloxx beloxx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 6 beloxx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 28 sec
Reputation Power: 0
Thanks for you rreply but i just now found what was wrong.

glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);

draw non transparent textures
...
..



glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;

glEnable( GL_BLEND ) ;
glBlendFunc(GL_DST_COLOR,GL_ZERO); // <-- this is the key to transparency !!!!!!!

draw trasnparent textures
..
..

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Transparency c++/opengl/sdl


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway