OpenGL fade effect
Moderator: Coders of Rage
OpenGL fade effect
How would you do an opengl fade effect? I've seen methods that suggest creating a huge rectangle but I don't know how to do the fade. Any help is appreciated.
Thanks
Thanks
Re: OpenGL fade effect
Fade to black? Fade to another level/scene?
If its fade to black then you could make a rectangle that covers the screen then decrease the transparency.
Sorry ahead of time, I can't really help with code since I don't know OpenGL too well.
If its fade to black then you could make a rectangle that covers the screen then decrease the transparency.
Sorry ahead of time, I can't really help with code since I don't know OpenGL too well.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: OpenGL fade effect
Details, please.ajtgarber wrote:Fade to black? Fade to another level/scene?
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
Re: OpenGL fade effect
Yes a fade to black effect in OpenGL.
- WSPSNIPER
- Chaos Rift Regular
- Posts: 145
- Joined: Sun Jan 03, 2010 6:19 pm
- Current Project: top down shooter
- Favorite Gaming Platforms: ps3
- Programming Language of Choice: c++
Re: OpenGL fade effect
im unaware of exactly what you mean but if its what i think you could create a transparent quad over the window and make it less transparent until it was fully black
Code: Select all
// NOT exact syntax
float alpha = 0.f; // i think 0 is full transparent but it may be 1 lol my dyslexia
glPushMatrix();
glColor4f(0.f, 0.f, 0.f, alpha)
alpha += 0.1f // or -= if it is 1 for full transparent
// DRAW QUAD HERE
- davidthefat
- Chaos Rift Maniac
- Posts: 529
- Joined: Mon Nov 10, 2008 3:51 pm
- Current Project: Fully Autonomous Robot
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: California
- Contact:
Re: OpenGL fade effect
http://www.opengl.org/resources/faq/tec ... arency.htm
http://nehe.gamedev.net/data/lessons/le ... ?lesson=32
look at the alpha blending part
http://nehe.gamedev.net/data/lessons/le ... ?lesson=32
look at the alpha blending part
Re: OpenGL fade effect
Well I have implemented it but some stuff isn't working like when you have the fade it will just be pure black but when you press any of the keys it will actually do the fade. Any tips. I am using SDL and OpenGL with C++ with Xcode on a Mac.
- WSPSNIPER
- Chaos Rift Regular
- Posts: 145
- Joined: Sun Jan 03, 2010 6:19 pm
- Current Project: top down shooter
- Favorite Gaming Platforms: ps3
- Programming Language of Choice: c++
Re: OpenGL fade effect
can you restate that in different words lol i dont understand you're problem 100%jjackdev wrote:Well I have implemented it but some stuff isn't working like when you have the fade it will just be pure black but when you press any of the keys it will actually do the fade. Any tips. I am using SDL and OpenGL with C++ with Xcode on a Mac.
here is how i think i understand it so it dosent fade it just turns black? why would it fade when you press a key? did you make it that way?
so here is a halfways function for it
Code: Select all
void init()
{
glEnable(GL_BLEND);
glBlendFunc(GL_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // the alpha stuff
// if in 2d, disable GL_DEPTH so the images behind will still show but if its 3d enable it
/// OTHER INITS
}
void fade(float alpha)
{
/// EDIT: ok it may look like this SDL_Delay(200); so it dosent faid so fast
if(alpha < 1.f)
{
glPushMatrix();
glColor4f(0.f, 0.f, 0.f, alpha);
// DRAW QUAD
glPopMatrix();
fade(alpha + 0.1f);
}
// recursive method to fade the screen
}
Last edited by WSPSNIPER on Mon Sep 13, 2010 9:27 pm, edited 1 time in total.
Re: OpenGL fade effect
I tried your method WSPSNIPER but my computer froze. But here is the problem so I am testing a warp like thing like this.
Now for some reason I cannot get it to work when it collides then the fading happens it just is a continous black with no fade.
Thank you guys for all your help.
Code: Select all
for (int i = 0; i < TILE_SOLID_COUNT; i++) {
if (IsCollision(tileRect[i], playerRect) == true) {
collision = true;
if (i == 33) {
x = 303;
y = 223;
alpha = 0.0f;
fading = true;
fade();
}
...
}
//In the main loop
if (fading == true) {
if (alpha < 1.0f) {
alpha += 0.1f/350.0f;
fade();
}
if (alpha > 1.0f)
fading = false;
}
//Here is my fade function the alpha and fading variables are global
void fade()
{
glBegin(GL_QUADS);
glColor4f(0.0f, 0.0f, 0.0f, alpha);
glVertex2f(0.0f, 0.0f);
glVertex2f(640.0f, 0.0f);
glVertex2f(640.0f, 480.0f);
glVertex2f(0.0f, 480.0f);
glEnd();
}
//Here is the wierd part when I do a keypress it works perfectly
if (event.key.keysym.sym == SDLK_d) {
fading = true;
alpha = 0.0f;
}
Thank you guys for all your help.
- WSPSNIPER
- Chaos Rift Regular
- Posts: 145
- Joined: Sun Jan 03, 2010 6:19 pm
- Current Project: top down shooter
- Favorite Gaming Platforms: ps3
- Programming Language of Choice: c++
Re: OpenGL fade effect
jjackdev wrote:I tried your method WSPSNIPER but my computer froze. But here is the problem so I am testing a warp like thing like this.Now for some reason I cannot get it to work when it collides then the fading happens it just is a continous black with no fade.Code: Select all
for (int i = 0; i < TILE_SOLID_COUNT; i++) { if (IsCollision(tileRect[i], playerRect) == true) { collision = true; if (i == 33) { x = 303; y = 223; alpha = 0.0f; fading = true; fade(); } ... } //In the main loop if (fading == true) { if (alpha < 1.0f) { alpha += 0.1f/350.0f; fade(); } if (alpha > 1.0f) fading = false; } //Here is my fade function the alpha and fading variables are global void fade() { glBegin(GL_QUADS); glColor4f(0.0f, 0.0f, 0.0f, alpha); glVertex2f(0.0f, 0.0f); glVertex2f(640.0f, 0.0f); glVertex2f(640.0f, 480.0f); glVertex2f(0.0f, 480.0f); glEnd(); } //Here is the wierd part when I do a keypress it works perfectly if (event.key.keysym.sym == SDLK_d) { fading = true; alpha = 0.0f; }
Thank you guys for all your help.
CRAP im so sorry, i ment to put fade(alpha + 0.1f) not - !!! infinite iteration!!!! im so SORRY
funny that + turned to - can mess somthing up so much :P im going to edit my post to fix it
- WSPSNIPER
- Chaos Rift Regular
- Posts: 145
- Joined: Sun Jan 03, 2010 6:19 pm
- Current Project: top down shooter
- Favorite Gaming Platforms: ps3
- Programming Language of Choice: c++
Re: OpenGL fade effect
jjackdev wrote:I tried your method WSPSNIPER but my computer froze. But here is the problem so I am testing a warp like thing like this.Now for some reason I cannot get it to work when it collides then the fading happens it just is a continous black with no fade.Code: Select all
for (int i = 0; i < TILE_SOLID_COUNT; i++) { if (IsCollision(tileRect[i], playerRect) == true) { collision = true; if (i == 33) { x = 303; y = 223; alpha = 0.0f; fading = true; fade(); } ... } //In the main loop if (fading == true) { if (alpha < 1.0f) { alpha += 0.1f/350.0f; fade(); } if (alpha > 1.0f) fading = false; } //Here is my fade function the alpha and fading variables are global void fade() { glBegin(GL_QUADS); glColor4f(0.0f, 0.0f, 0.0f, alpha); glVertex2f(0.0f, 0.0f); glVertex2f(640.0f, 0.0f); glVertex2f(640.0f, 480.0f); glVertex2f(0.0f, 480.0f); glEnd(); } //Here is the wierd part when I do a keypress it works perfectly if (event.key.keysym.sym == SDLK_d) { fading = true; alpha = 0.0f; }
Thank you guys for all your help.
ok now that i fixed my infinate iteration ( i edited my post my - should have been a + ) i was looking at your code and was wondering if you enable GL_BLEND and call the glBlendFunc ... its important!!!
Re: OpenGL fade effect
I fixed it in my code but it did not work? I just need a solution for my current solution.
- WSPSNIPER
- Chaos Rift Regular
- Posts: 145
- Joined: Sun Jan 03, 2010 6:19 pm
- Current Project: top down shooter
- Favorite Gaming Platforms: ps3
- Programming Language of Choice: c++
Re: OpenGL fade effect
jjackdev wrote:I fixed it in my code but it did not work? I just need a solution for my current solution.
ok what is the problem? is it just a black screen. it the contents in the background are on the same z plane as the rect you are drawing and you enable GL_DEPTH it will not render so try glDisable(GL_DEPTH); or make sure that the contents under the rect are on a > z coord then the rect you are rendering
Re: OpenGL fade effect
Let me tell you the whole problem.
1. I check to see if there are any collisions (that works)
2. I see if the collision is a certain collider (that works)
3. I then fade it while warping the character (the warp works not the fade)
The problem with the fade is it just stays completely black but when I press a key it goes to the current alpha like if triggering a key turns on the alpha blending.
The fading works because when I just trigger the fading using a key that I set then it works flawlessly.
1. I check to see if there are any collisions (that works)
2. I see if the collision is a certain collider (that works)
3. I then fade it while warping the character (the warp works not the fade)
The problem with the fade is it just stays completely black but when I press a key it goes to the current alpha like if triggering a key turns on the alpha blending.
The fading works because when I just trigger the fading using a key that I set then it works flawlessly.
- WSPSNIPER
- Chaos Rift Regular
- Posts: 145
- Joined: Sun Jan 03, 2010 6:19 pm
- Current Project: top down shooter
- Favorite Gaming Platforms: ps3
- Programming Language of Choice: c++
Re: OpenGL fade effect
alright so lets think for a sec, if the fade and the warp work apart it must be something when they are being called together, so can you post the code where you call the warp and the fade.