|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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 ![]() |
|
#2
|
||||
|
||||
|
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); |
|
#3
|
|||
|
|||
|
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 .. .. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Transparency c++/opengl/sdl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|