Page flipping

This is a discussion on Page flipping within the Game Programming forums, part of the General Programming Boards category; I understand how drawing to a back page and then making it the front page reduces flicker, but when you ...

  1. #1
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326

    Page flipping

    I understand how drawing to a back page and then making it the front page reduces flicker, but when you do that, do you change the video adress to the backpage, or do you copy the backpage to the front page? If you copied it, I don't see how it would make it faster. And would three pages be any smoother? I don't see how.

  2. #2
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    >>do you change the video adress to the backpage, or do you copy the backpage to the front page?

    You merely switch the 'front page' pointer to point to the 'back page'.

    >>And would three pages be any smoother?

    No. You cant get any faster than instant.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  3. #3
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Thank you, one more question, could you show me an example of using two pages, with pseudo code? This is how I figure it.

    Code:
    while(!quit)
    {
      FlipPage();
      ParseInput(); // Which draws the stuff to the back buffer
    }
    I just don't understand how to set it up, I guess it would be different depending on the type of game, and the library used.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    ere am not sure about this,


    Draw on the backpage...
    When the time comes to present your drawing....,
    Point to the backpage,
    Repeat

  5. #5
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Hmm, if you use two pages, I guess you would need a pointer to the back buffer too. How else would you know which one is the back buffer at the time...

  6. #6
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    Yes, you will need a pointer to both the frint and back buffer. Otherwise you wouldnt be able to keep track of them.

    A typical DirectX application using two pages would go something like this (pseodocode):
    Code:
    while(TRUE)
    {
       //do stuff
       DrawImagesToBackBuffer();
       //do stuff
       Flip();
    }

    Flip() would merely make your back buffer your front (or 'main' buffer) and make your front buffer your back buffer. Then, on the next screen refresh, the contents of your ex-back buffer (the one you drew to last) would be displayed instead of your last front buffer (which is now the back one, all nice and ready to be drawn on for the next loop). Repeat.

    (Hope that wasnt too confusing.)
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  7. #7
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Not to confusing, I got it, thanks.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    2 pointers??

    isn't it just one pointer, and ddraw just points back and forth between these two buffers,

  9. #9
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Originally posted by mickey
    isn't it just one pointer, and ddraw just points back and forth between these two buffers,
    Nope. Where do you think it keeps the info about the 2 buffers? At the addresses of their respective pointers.

    Code:
    //long pointer to an IDirectDrawSurface object for the primary surf
    LPDIRECTDRAWSURFACE7 sfPrimary=NULL; 
    //long pointer to an IDirectDrawSurface object for the backbuffer
    LPDIRECTDRAWSURFACE7 sfBackBuffer=NULL;
    
    sfBack->BltFast(20,20,sfYourBmpSurf,&ItsRect,DDBLTFAST_WAIT);
    sfPrimary->Flip(NULL,DDFLIP_WAIT);
    Read the DirectX docs that come with the SDK.

    from DX SDK documentation

    HRESULT Flip(
    LPDIRECTDRAWSURFACE7 lpDDSurfaceTargetOverride,
    DWORD dwFlags
    );

    Parameters
    lpDDSurfaceTargetOverride
    Address of the IDirectDrawSurface7 interface for an arbitrary surface in the flipping chain. The default for this parameter is NULL, in which case DirectDraw cycles through the buffers in the order that they are attached to each other

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. why page based I/O can improve performance?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 06-12-2006, 07:42 AM
  2. virtual memory
    By sweets in forum C Programming
    Replies: 6
    Last Post: 11-06-2004, 05:55 AM
  3. allegro help - page flipping?
    By MadHatter in forum Game Programming
    Replies: 2
    Last Post: 11-30-2002, 02:32 AM
  4. C Graphics - Page Flipping
    By z0diac in forum C Programming
    Replies: 1
    Last Post: 10-29-2002, 12:21 AM
  5. double buffering and page flipping question
    By stupid_mutt in forum C Programming
    Replies: 2
    Last Post: 01-30-2002, 12:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21