Click to See Complete Forum and Search --> : Double Buffer
KingDavid
Jan 7th, 2001, 05:18 PM
how do you set up a double buffer?
HarryW
Jan 7th, 2001, 06:24 PM
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.
KingDavid
Jan 7th, 2001, 11:07 PM
What type of surface? back, front, or does it matter?
HarryW
Jan 8th, 2001, 09:02 AM
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:
// 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.
KingDavid
Jan 12th, 2001, 10:11 PM
Ok think I got it
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?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.