Problems trying to fade in windowed mode - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Problems trying to fade in windowed mode (/thread-3116.html)
Problems trying to fade in windowed mode - Wowbagger - Aug 6, 2007 07:37 PM
A while back I asked about how to fade an OpenGL context when in windowed mode. I was told to adjust the alpha of a quad drawn over everything else. I assume this is similar to the method described here, which I found via a quick Google search. However, for some reason it doesn't seem to be working for me. It just draws a black quad at full opacity and then it just sticks there -- the sounds and music keep playing with no graphics being drawn.
Right now, when I want to fade, I call a function that fades the display, draw the next frame, swap buffers (although nothing appears because the screen is completely blacked out), and then call a function that fades the display back in. In order to do that in the same way for windowed mode, I thought it would be necessary to take a snapshot of the buffer using glReadPixels() and then draw the quad over that repeatedly. But I got crashes and such. I was also wondering if there was a way to read the back buffer (so I can fade out, draw to the screen, and fade back in by overlaying the quad over the contents of the back buffer) in OpenGL.
Am I going about this all wrong, or is there something I am missing?
Problems trying to fade in windowed mode - AnotherJake - Aug 6, 2007 08:02 PM
The quad thing should work just fine. It sounds like you're doing it wrong somehow. The only time you should swap buffers is by calling something like [[NSOpenGLContext currentContext] flushBuffer]; (or equivalent) at the end of every frame, only once per frame. That link that you put up does a for loop right in place, but that's not how it should be done on the Mac. You should be calling drawRect (or equivalent) every frame via a timer or through a loop callback in GLUT or whatever -- don't try to hold the machine up and swap buffers like that. Instead, keep track of the opacity value of your covering quad across frames, like fade = opacity * deltaTime, or something like that. It might be easier to offer more specific advice, if you need it, if you showed some code.
Problems trying to fade in windowed mode - Wowbagger - Aug 11, 2007 04:07 PM
Right now, I call my fading functions in the middle of a block of code, like this, for example (in my menu controlling class):
I do this because the fading functions set the display alpha in a while loop. Would the quad method work if I made the fade update in the main game loop instead of in a function like I am doing now? Actually, how come the way the link suggested doesn't work? I am using Carbon with AGL, if that makes a difference.
Also, if it helps, here is my current fading code, ripped from Apple's documentation. If possible, I would like to add an else block to the two functions so I don't have to modify the rest of my code.
Thanks for any help you can give.
Problems trying to fade in windowed mode - AnotherJake - Aug 11, 2007 06:32 PM
Sorry, I'm a little brain-fried at the moment, but two thoughts come to mind:
1) I'm confused as to whether you are trying to fade the display or fade the scene. Fading the scene should be done with a covering quad so that it works in windowed mode as well. Fading the display for fading into and out of full screen should be done with the CG routines.
2) In my experience, CGSetDisplayTransferByFormula isn't ideal because you have to loop through all displays if you are capturing all displays. And worse, the formula doesn't go through the gamma tables so the fading can be slightly off from what the users display calibration might be, possibly causing a slight shade flicker at the start and end of the fades. I use CGDisplayFade instead.
Problems trying to fade in windowed mode - Wowbagger - Aug 13, 2007 12:11 PM
I'm trying to fade the whole display when in full screen mode, but fade only the scene when in windowed mode (fading the whole display while the game is running in windowed mode seems like overkill). If possible, I would like to do this by modifying the two functions I already have (the FadeOut()/FadeIn() routines). Although I'm thinking that to do this with the covered quad, I'd have to re-engineer the fading system.
Actually, would it be better to just use a covered quad for fading in both full screen and windowed mode and save the CGDisplayFade() for just the resolution switching?