Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Julio

OpenGL opengl alpha fading

This topic is 6548 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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Here is a simple pseudo-code class to create an fade effect.

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



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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;

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!