Skip to main content
gamedev.net
🔒 Locked

Image fading

Started by KeeperMustDie 1 reply 600+ views
Original Post
KeeperMustDie
KeeperMustDie
Hi, I know how to make simple image to fade, but I dont understend how to make fade image with mask. Here is my image drawing function: void DrawImage(Image_t Img, float pos_x, float pos_y, float width, float height){ glDisable(GL_LIGHTING); glTranslatef(pos_x,pos_y,-90.0); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_DST_COLOR, GL_ZERO); glBindTexture(GL_TEXTURE_2D, Img.mask); glBegin(GL_QUADS); glTexCoord2f(1.0 , 1.0); glVertex2f(width, height); glTexCoord2f(0.0 , 1.0); glVertex2f(-width, height); glTexCoord2f(0.0, 0.0); glVertex2f(-width, -height); glTexCoord2f(1.0, 0.0); glVertex2f(width, -height); glEnd(); glBlendFunc(GL_ONE, GL_ONE); glBindTexture(GL_TEXTURE_2D, Img.data); glBegin(GL_QUADS); glTexCoord2f(1.0 , 1.0); glVertex2f(width, height); glTexCoord2f(0.0 , 1.0); glVertex2f(-width, height); glTexCoord2f(0.0, 0.0); glVertex2f(-width, -height); glTexCoord2f(1.0, 0.0); glVertex2f(width, -height); glEnd(); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); glEnable(GL_LIGHTING); glLoadIdentity(); } and image loading function fragment: for (i=0; i<infoheader.biWidth*infoheader.biHeight; i++) { fread(&rgb,sizeof(rgb),1,l_file); // Here I delete background with color 32,32,32 if (rgb.rgbtRed==32 && rgb.rgbtGreen==32 && rgb.rgbtBlue==32){ l_texture[j+0]=rgb.rgbtRed; l_texture[j+1]=rgb.rgbtGreen; l_texture[j+2]=rgb.rgbtBlue; l_texture[j+3]=0; } else { l_texture[j+0]=rgb.rgbtRed; l_texture[j+1]=rgb.rgbtGreen; l_texture[j+2]=rgb.rgbtBlue; l_texture[j+3]=255; } j+=4; } Can anybody plz tell me how to make my image fade?
Lord_Evil
Lord_Evil
What do you consider "image fading"? Is it having an image appear/disappear by smoothly fading in/out?

If so, why don't you use a 4-component image that has the mask in its alpha channel (or you build the alpha channel from a key color). Then you render the quad whose vertices have color r=1, g=1, b=1, a=fade_factor and modulate color and texture. This means that the color of the texture is used (color_t * 1 = color_t) but the mask is modulated by the alpha value of the vertices. With this just render ONE quad with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
KeeperMustDie
KeeperMustDie
Sorry I'm to stupid to understend :(. Can You write functions example plz?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.