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
opengl alpha fading
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:
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.
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
thanks again,
Joe
JoeMont001@aol.com www.polarisoft.n3.net
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?
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?
Here is a simple pseudo-code class to create an fade effect.
class fadeEffect
{
fadeEffect(screenWidth, screenHeight, fadeincrement);
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;
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
JoeMont001@aol.com www.polarisoft.n3.net
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
JoeMont001@aol.com www.polarisoft.n3.net
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement