opengl alpha fading

Started by
6 comments, last by Julio 23 years, 9 months ago
howdy, for my title screen sequence I want it to fade for the effect. I thought I could use the alpha channel to get the fading effect, but for some reason it''s not working. here''s some source:
    
float alevel; //alpha level

ts_time=GetTickCount();
glEnable(GL_TEXTURE_2D);
while(GetTickCount()-ts_time<2000)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	glLoadIdentity();						glPushMatrix();
	glTranslatef(0.0f,0.0f,-4.0f);
	glBindTexture(GL_TEXTURE_2D, t_texture[0]);
	glColor4f(1.0f,1.0f,1.0f,alevel);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f,1.0f); 
		glVertex3f(-2.0f,1.0f,0.0f);
		glTexCoord2f(0.0f,0.0f); 
		glVertex3f(-2.0f,0.0f,0.0f);
		glTexCoord2f(1.0f,0.0f); 
		glVertex3f(2.0f,0.0f,0.0f);
		glTexCoord2f(1.0f,1.0f); 
		glVertex3f(2.0f,1.0f,0.0f);
	glEnd();
		
	alevel+=0.001f;
	SwapBuffers(hDC);
}
    
basically, after every frame it increments the alpha level by .001. it doesn''t appear to fade at all. what am I missing? JoeMont001@aol.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Advertisement
I see two things wrong.
1) You don''t initialize the alpha to zero!
2) It''s a local variable. It will always be the same. If you want to keep the variable local to this function, declare it as static.
the alpha level 1.0f by default? that makes sense. I''m not sure I understand the second statement. why would it not increment?
thanks again,
Joe

JoeMont001@aol.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
it would increment but only local to that function. so when that
function exits, you lose your incremented value. so, that''s why you declare it as static (or a global variable).

Secondly, i don''t know if this is incorrect but it seems like your while loop is not right. you might need extra brackets between the gettickcount and the other variable, coz < has higher priority than -.

So, is that how you get the fading effect? I have been trying to do the same but so far i have been unsuccessful

sig u say?
Yes! There are kangaroos in Australia but I haven't seen them...yet
Here is a simple pseudo-code class to create an fade effect.

class fadeEffect
{
fadeEffect(screenWidth, screenHeight, fadeincrement);



Here is a simple pseudo-code class to create an fade effect.

class fadeEffect
{
fadeEffect(screenWidth, screenHeight, fadeincrement, color)

fade()
//draw a quad screenwidth, screenheight of color with alpha value(internal to the class)
inc() // increment the fade

done() //alpha == 0
}

here is how you use it :

if (fade) then
fader = new fadeEffect(640,480, 0.01, red);
end if

while not(fader.done())
//draw stuff
fader.fade();
fader.incr();
wend

delete fader;

the while loop works fine. it waits 2 seconds (2000 miliseconds) then proceeds. I changed the float alevel variable to global. it didn''t change anything. I changed it to static, that didn''t work either. so I think I have it narrowed down to it not changing the alpha level. I''ll figure it out.

JoeMont001@aol.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
duh, I figured it out. I wasn''t enabling blending. that might help. it works now. I hate stupid mistakes like that.

JoeMont001@aol.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911

This topic is closed to new replies.

Advertisement