PDA

View Full Version : Blending when changing screens


Blake
2003.10.17, 02:03 AM
here is my code

if( ChangingAreas ) {
if( NextArea != NULL ) {
ChangingScreenAlphaChannel += 0.025f; }
else {
ChangingScreenAlphaChannel -= 0.025f; }
if( ChangingScreenAlphaChannel > 1.25f ) {
[ self SwitchMapArea:[ NextArea GetNewAreaName ] ];
[ ControlableObject SetX:[ NextArea GetNewX ] ];
[ ControlableObject SetY:[ NextArea GetNewY ] ];
[ ControlableObject SetZ:[ NextArea GetNewZ ] ];
NextArea = NULL; }
if( ChangingScreenAlphaChannel < 0.0f ) {
ChangingAreas= FALSE; }

glLoadIdentity();
glTranslatef( 0.0, 0.0, -0.5 );
if( ChangingScreenAlphaChannel < 1.0f ) {
glEnable( GL_BLEND );
glColor4d( 0.0, 0.0, 0.0, ChangingScreenAlphaChannel ); }
else {
glColor3d( 0.0, 0.0, 0.0 ); }
glBegin( GL_QUADS );
glVertex2d( -1.0f, -0.5f );
glVertex2d( 1.0, -0.5f );
glVertex2d( 1.0, 0.5f );
glVertex2d( -1.0f, 0.5f );
glEnd();
glDisable( GL_BLEND ); }

now my problem is that when the black is fading the screen looks normal, only when the alpha channel gets above 1 ( I only have it go to 1.5 to give the game some time to set everything up for the next area ) i dont use blend, any ideas why it doesnt blend the black before 1?

Fenris
2003.10.17, 06:33 AM
Yes, use glColor4f () instead of glColor4d(). 4f ranges from 0..1, 4d ranges from 0->something else, much larger. (I'm on a work PC, so I don't have the terminal nor the red book handy. Good luck!

DoG
2003.10.17, 06:42 AM
The range for color floats is 0.0 to 1.0 anything above or below will yield undefined results.

Where did you get the idea to go above 1.0 with the alpha channel (or any color value)?

Blake
2003.10.17, 11:51 AM
Originally posted by DoooG
The range for color floats is 0.0 to 1.0 anything above or below will yield undefined results.

Where did you get the idea to go above 1.0 with the alpha channel (or any color value)?

i dont use anything above 1.0, i just have it go above that so that i can give my game some time to change the areas its in

Mark Levin
2003.10.17, 11:56 AM
Originally posted by DoooG
The range for color floats is 0.0 to 1.0 anything above or below will yield undefined results.

Where did you get the idea to go above 1.0 with the alpha channel (or any color value)?

No, it will get clipped to [0..1] at some point in the render process. I don't remember exactly where this point is, but using a large or negative number won't trigger an error or undefined behavior.

Blake
2003.10.17, 11:57 AM
Originally posted by Fenris
Yes, use glColor4f () instead of glColor4d(). 4f ranges from 0..1, 4d ranges from 0->something else, much larger. (I'm on a work PC, so I don't have the terminal nor the red book handy. Good luck!

the 0-1 thing isnt my problem, its when im blending the black screen it not changing anything, ie its not making the screen fade black

Fenris
2003.10.17, 05:58 PM
Well, you're right. glColor4d does actually take double, not an integer as I thought. :blush: (If it had, though, that would've explained the problem.)

I checked your code thoroughly, and I couldn't find anything wrong. :-/ The only thing I can think of is that you might have not set the blending equation correctly - do you call glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); before doing this blending?

Also, make sure that ChangingScreenAlphaChannel is really a double, and not a float or anything else.

Blake
2003.10.18, 12:27 AM
Originally posted by Fenris
Well, you're right. glColor4d does actually take double, not an integer as I thought. :blush: (If it had, though, that would've explained the problem.)

I checked your code thoroughly, and I couldn't find anything wrong. :-/ The only thing I can think of is that you might have not set the blending equation correctly - do you call glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); before doing this blending?

Also, make sure that ChangingScreenAlphaChannel is really a double, and not a float or anything else.

well see the thing is that it works with every color but black

Blake
2003.10.18, 01:09 AM
Originally posted by Fenris
do you call glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); before doing this blending?

Thank You! i was calling glBlendFunc (GL_SRC_ALPHA, GL_ONE ); and thats why it wasnt working

Fenris
2003.10.18, 07:05 AM
No problem, glad to help! :D