Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Fadein, Fadeout?

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2003
    Location
    Siera-Lionne, Diamond Field Town
    Posts
    24

    Fadein, Fadeout?

    Hello. I am trying to make a fadein effect, but unfortunately the screen becomes black too fast...

    Code :
     	enable2D();
     
    	float alpha = 1.0f;
     
    	//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);			
    		// Enable Blending       (disable alpha testing)
    	//glEnable(GL_BLEND);							
     
     
    	while (alpha>0) {
     
    		glBegin(GL_QUADS);
     
    		glColor4f(1.0f, 1.0f, 1.0f, alpha);
     
    		alpha -= 0.005f;
     
    		//glTexCoord2f(0,1);
    		glVertex2d(0,0);
     
    		//glTexCoord2f(0,0);
    		glVertex2d(1024,0);
     
    		//glTexCoord2f(1,0);
    		glVertex2d(1024,768);
     
    		//glTexCoord2f(1,1);
    		glVertex2d(0,768);
     
     
    	glEnd();
    	glfwSwapBuffers();
     
    	}
    	//glDisable(GL_BLEND);		
    	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    	disable2D();

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2001
    Posts
    354

    Re: Fadein, Fadeout?

    Just insert some Sleep() call in your loop.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2004
    Posts
    13

    Re: Fadein, Fadeout?

    I'd rather recommend syncing to system clock. Include time.h, and you can access the function called clock(). It returns the system time. (On most platforms it gives you time in milliseconds)

    Then you sync the alpha value to clock. Like this:

    Code :
    #define DURATION 3000    // in milliseconds
     
    int t = clock();
    for (int t2=0; t2<DURATION; t2=clock()-t);
    {
    float alpha = ((float)t2) / DURATION;
    [rendering code goes here]
    }
    And you can advance it by checkig whether clock()has changed between two frames, and not render if it hasn't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •