• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Screen fade, blanking instead of fading.

5 posts in this topic

Hello, i have looked at the other subforms of this forum and feel this is the best place.

I shall first off explain my issue and my own observations, before showing the relivent code.


The goal is to create a fade out effect.

At first i suspected multithreading, i have seen weird stuff happen in the past with it.


But this has prooved not to be the case, the float being past appears to be incrementing at the correct rate, but where the fault occurs is that instead of a fade, i get a flick of the screen then blankness as if the fade is at 100% when it is not(the printf in fade drawing showed that).


Additional infomation, the platform i am using is windows but i use SDL to handle all the initalising and stuff, as i do plan to port the code later to other platforms.


I shall now quote my code, starting with relivent render code(Cut down for cleaness):



				_GL_Color ClearColor = RGBtoFloat({0,0,0,255});
				glClear( GL_COLOR_BUFFER_BIT );
				glEnable( GL_CULL_FACE );

				//Enable alpha masking here for non background element drawing.

				glEnable( GL_BLEND );
				glEnable( GL_ALPHA_TEST );

				//Set to no texture
				glBindTexture(GL_TEXTURE_2D, 0);
				if (pFade != NULL) { pFade->Draw(); }
				glDisable( GL_ALPHA_TEST );
				glDisable( GL_BLEND );
				glDisable( GL_CULL_FACE );


Fade draw function(inside fade class)

	if (Colors[4] <= 0.0f) { return; }

	printf("Colors[4] = %f\n", Colors[4]);
	glBegin( GL_QUADS );
	//Bottom left
	glColor4f( Colors[1], Colors[2], Colors[3], Colors[4] );
	glVertex3f( 0, ScreenY, 0.0f );

	//Bottom right
	glColor4f( Colors[1], Colors[2], Colors[3], Colors[4] );
	glVertex3f( ScreenX, ScreenY, 0.0f );
	//Top right
	glColor4f( Colors[1], Colors[2], Colors[3], Colors[4] );
	glVertex3f( ScreenX, 0, 0.0f );

	//Top left
	glColor4f( Colors[1], Colors[2], Colors[3], Colors[4] );
	glVertex3f( 0, 0, 0.0f );


In advance, thank you for any help you can provide.


Share this post

Link to post
Share on other sites
As always, complete code samples would be better:
  • What do you put into Colors[]? How is it animated?
  • What's the point of GL_ALPHA_TEST? Don't you want to draw arbitrary stuff first, and an increasingly opaque rectangle over whatever you are fading out last, unconditionally? Every fragment should be a*fade colour + (1-a)*stuff colour, with a (Colors[4] for you) increasing from 0 to 1 and ignoring the alpha value of the fading stuff.
  • When do you draw the stuff you are fading out, and in which OpenGL state? I only see pFade->Draw(), which I suppose contains only the rectangle in the second snippet.
Edited by LorenzoGatti

Share this post

Link to post
Share on other sites

It looks like you're only clearing the color buffer, never the depthbuffer and from what i can see depth writes or depth tests are never disabled, so once the fade quad is rendered at z=0.0 everything else should fail the depth test until you clear the depthbuffer.


If that isn't the problem it will help a lot if you post a minimal, compiling example demonstrating the problem.


Share this post

Link to post
Share on other sites
Gonna get on with decuppleing the code to produce a minimal build example.
But first i will clarify some more on my code.

Colors[] defined as
float Colors[4];
it is initalised in CEffectFade's constructor.

pAppState is a pointer from the main thread, passed as an argument.

It is incremented from a saperate thread, like so(excuse the mess, the project is still prealpha and i have been tinkering around with stuff).
	const int TICKS_PER_SECOND = 950;
	const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
	const int MAX_FRAMESKIP = 5;
	DWORD NextFrame = timeGetTime();	//Get our current timeing.	
	DWORD LastFrame = timeGetTime();	//
	int loops=0;
	float interpolation=0.0f;
	while (pAppState->status & STATUS_ACTIVE)	{
		CPlayerEntity *pPlayer = (CPlayerEntity *)pAppState->SharedTable[ID_PLAYER];
		CEffectFade *pFade = (CEffectFade *)pAppState->SharedTable[ID_OVERLAY];
		CLoadAnimation *pLoadAnim = (CLoadAnimation *)pAppState->SharedTable[ID_LOADANIMATION];
		if (timeGetTime() > NextFrame && loops < MAX_FRAMESKIP)	{
			if (pAppState->status & STATUS_LOADING)	{
				if (pLoadAnim != NULL)	{
				if (pPlayer != NULL) { pPlayer->Think(); }
					NextFrame += SKIP_TICKS;
			if (abs(LastFrame-NextFrame) > 1) {
				printf("Warning : delta is %i, game might be lagging.\n", abs(LastFrame-NextFrame));
			LastFrame = NextFrame;
			//Give our time to something else.
		interpolation = (float) timeGetTime() + SKIP_TICKS - NextFrame / (float)SKIP_TICKS;
		pAppState->Interp = interpolation;
		//printf("Interpolation : %i\n", interpolation);
		// Old approach(Replaced with a high resolution timer)
Two two refrenced functions here SetRate and TransitionIn are as so(raterate is a float).
void CEffectFade::TransitionIn(){
	//printf("Fade : %f\n", Colors[4]);
	Colors[4]+= RateRate;
	if (Colors[4] > 1.0) { Colors[4] = 1.0; }
	if (Colors[4] < 0.0) { Colors[4] = 0.0; }
void CEffectFade::SetRate(float Rate){	RateRate = Rate;}
I removed GL_ALPHA_TEST while cleaning code up.

I draw the screen and map prior to the call to pfade->draw(); inbetween the glEnable block and the glBindTexture(GL_TEXTURE_2D, 0) call. Edited by mathew_653

Share this post

Link to post
Share on other sites

Okay, first, like SimonForsman said, add the GL_DEPTH_BUFFER_BIT flag to the glClear() function.


Then, instead of trying the fade out effect, try to render the quad at half alpha (like the line you commented on the last snippet), and see if it renders correctly.

If it does, then the problem is in your rate update. If it does not, then maybe transparency is not being applied correctly, so when the quad as an alpha > 0.0, then if renders full opaque (not sure, just an idea).


Also, i'm not sure, but don't you have to enable alpha blending & depth testing for transparency to work?


See if it helps.


Share this post

Link to post
Share on other sites

An update, i have found a solution to the issue, i was having altough, it is a issue i had not encountered for ages, relating to transparancy and glColor4f using 0,0,0 for color.

I have tested my code with clolor 1.0,1.0,1.0 and found it worked fine, so that isolated my fault downto an old thing that i have seen with glColor4f(0,0,0,A); and alpha blending.



Altough i did try all the ones, prior, i thank you kind people for your assistance, i hope mentioning this, prevents anyone else being cought out.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0