Jump to content
  • Advertisement
Sign in to follow this  
neo187

OpenGL FadeOut effect/semi transparency

This topic is 2587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello

I am trying to obtain a simple fadeout effect by having a big textured quad cover the screen with the alpha that gradually increases until being full black... I don't quite understand in what part of the drawing code I should alter the alpha...... I have a wrapper class for textures, this is how I load a texture:



void GLTexture::LoadBMP(char *name)
{
// Create a place to store the texture
AUX_RGBImageRec *TextureImage[1];

// Set the pointer to NULL
memset(TextureImage,0,sizeof(void *)*1);

// Load the bitmap and assign our pointer to it
TextureImage[0] = auxDIBImageLoad(name);

// Just in case we want to use the width and height later
width = TextureImage[0]->sizeX;
height = TextureImage[0]->sizeY;

// Generate the OpenGL texture id
glGenTextures(1, &texture[0]);

// Bind this texture to its id
glBindTexture(GL_TEXTURE_2D, texture[0]);

// Use mipmapping filter
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

// Generate the mipmaps
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

// Cleanup
if (TextureImage[0])
{
if (TextureImage[0]->data)
free(TextureImage[0]->data);

free(TextureImage[0]);
}
}


Then in the drawing section I enable glBlend and activate the texture:


gluOrtho2D(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT);

glMatrixMode (GL_MODELVIEW);
glLoadIdentity();

glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );


glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
tex.Use();

//Draw the textured quad here



void GLTexture::Use()
{
glEnable(GL_TEXTURE_2D); // Enable texture mapping
glBindTexture(GL_TEXTURE_2D, texture[0]); // Bind the texture as the current one

}




Is there somewhere in this structure that I can implement said effect?

Thanks for your help

Share this post


Link to post
Share on other sites
Advertisement

glColor4f(...,....,...,alphavariable)


thanks, I have tried that but I don't really notice any transparency, even when setting it to 0!

Share this post


Link to post
Share on other sites
Have you done anything with glTexEn()? glColor4f() called before drawing will work. Does glColor4f(1,0,0,1) turn your texture red?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!