Results 1 to 5 of 5

Thread: Double Buffer

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151

    Question

    how do you set up a double buffer?

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Depends on how you're doing your graphics. If you're using picture boxes and BitBlt, then you can either add another picture box (and make it invisible) and use the DC of that box to blit from, or create a memory DC using the Windows API, maybe a bit more complicated but more efficient on the resources.

    If you're using DirectDraw, then you can create a secondary surface and add it to the flipping chain of the primary surface. It's easy enough. I know how to do it in C, not sure about VB though.
    Harry.

    "From one thing, know ten thousand things."

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151

    Question

    What type of surface? back, front, or does it matter?

  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    You can only have one primary surface in DirectDraw, since that is the surface that represents the image which gets rendered to the screen. You would have to use a secondary surface. Is that what you meant by back/front?

    As an alternative, you could make your own double buffer using an array of RGB values (or palette entries if you're using 8-bit colour) the same size as the screen. You don't get the benefit of hardware acceleration this way though. It's probably best to use a secondary surface.

    In C/C++ you would create a secondary surface like this, if it helps:

    Code:
    // assuming directdraw object etc set up...
    
    DDSURFACEDESC ddsd;      // surface description structure
    LPDIRECTDRAWSURFACE4 lpddsprimary = NULL; // primary surface
    LPDIRECTDRAWSURFACE4 lpddsback = NULL; // back buffer (secondary surface)
    
    memset(&ddsd, 0, sizeof(ddsd); // clear out the description
    ddsd.dwSize = sizeof(ddsd); // initialise it so it can be used
    
    // now set up the description for primary surface
    ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; 
    ddsd.dwBackBufferCount = 1   // 1 back buffer
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | // set up the
                          DDSCAPS_COMPLEX |        // properties
                          DDSCAPS_FLIP;        // of the surface
    
    // now create the primary surface
    if (FAILED(lpdd4->CreateSurface(&ddsd, &lpddsprimary, NULL)))
        return(0)  // if failure return error, otherwise...
    
    // now edit the surface description for the next function call...
    ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
    
    // and add a back buffer to the primary surface's flipping chain
    if (FAILED(lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsback)))
        return(0)  // if failure return error, otherwise...
    
    // now you are ready to use the back buffer.
    Harry.

    "From one thing, know ten thousand things."

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151

    Talking

    Ok think I got it
    Code:
    Option Explicit
    Rem DirectX  Objects
    Dim DirectX         As New DirectX7 'Direct X
    Dim DDraw           As DirectDraw7 ' DirectDraw
    Dim DDCliper        As DirectDrawClipper
    
    Rem Surfaces
    Dim SurfDesc        As DDSURFACEDESC2
    
    Dim PrimarySurf     As DirectDrawSurface7
    Dim BackSurf        As DirectDrawSurface7
    
    Dim Caps As DDSCAPS2
    
    Private Sub Form_Load()
        
    
        Rem Set up Direct Draw
        Set DDraw = DirectX.DirectDrawCreate("")
        Call DDraw.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL Or DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN)
        
        SurfDesc.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
        SurfDesc.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_COMPLEX Or DDSCAPS_FLIP
        SurfDesc.lBackBufferCount = 1
        
        Set PrimarySurf = DDraw.CreateSurface(SurfDesc)
        
        Caps.lCaps = DDSCAPS_BACKBUFFER
        Set BackSurf = PrimarySurf.GetAttachedSurface(Caps)
        
        Set DDCliper = DDraw.CreateClipper(0)
    
    End Sub
    What do I do next?

Posting Permissions

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



Click Here to Expand Forum to Full Width