Jump to content
Posted 08 November 1999 - 09:50 AM
Posted 08 November 1999 - 08:44 AM
// You have to zero the memory so random bits that were in the memory where the variable was created won't mess up the things up.
ZeroMemory( &ddsd, sizeof( ddsd ) );
// This is so the fuunctions know how big the ddsd variable is.
ddsd.dwSize = sizeof( ddsd );
// The DDSD_CAPS flag lets DirectDraw know that the ddsd.ddsCaps.dwCaps variable is being used. DDSD_BACKBUFFERCOUNT lets the program know that the ddsd.dwBackBufferCount variable is valid (and that there will be back buffers to this surface).
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
// DDSCAPS_PRIMARYSURFACE: lets DirectDraw know that this is the primary surface. DDSCAPS_FLIP: it can be flipped (back buffers can be used). DDSCAPS_COMPLEX: the surface has backbuffers, so it's complex.
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 2;
// Create the primary surface.
if ( FAILED( lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL ) ) )
Now the primary surface has been created with two back buffers, but you need to call GetAttachedSurface() to actually be able to access the back buffer:
// Again, make sure the memory is cleared.
ZeroMemory( &ddscaps, sizeof( ddscaps ) );
// The surface being created is a back buffer.
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
// Get the back buffer!
if ( FAILED( lpDDSPrimary->GetAttachedSurface( &ddscaps, &lpDDSBack ) ) )
You have to call GetAttachedSurface instead of CreatSurface because the back buffer has to be "a part of" another surface. DirectDraw needs to know which surface each backbuffer belongs to.
You really ahve two back buffers (dwBackBufferCount) but you only need to draw onto one of them. The other one is kindof a "middlebuffer". This is how it works: you write to the back buffer, call "flip", the back buffer goes to the middlebuffer, call flip again and the middle buffer goes to the primary surface. This may seem slower, but it really speeds things up. Read the part in Inside DirectX about back buffers.
Now that you have a back buffer and a primary surface, what you need to do is:
1. create another surface
2. load a bitmap into it
3. blit that onto the back buffer
4. flip the surfaces
I could send you a file that came with the directx SDK, ddutil.cpp, that create a surface and loads a bitmap into it. So, you call that and then blit that onto the back buffer with BltFast(), a DirectDraw function (look at the help file). After that, call Flip() (also, look at the help file).
You should have it call BltFast() and Flip() in a loop, say in WinMain() after it processes a message.
I really hope that is what you wanted because it took a damn long time to write
If it doesn't help, post back here. Or I suppose you could get on ICQ...
Posted 08 November 1999 - 08:51 AM
int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
// This stores the messages that Windows sends the program.
// Init the system stuff.
if ( sys_Init( hInstance, nCmdShow ) == FALSE )
// Get, Translate, and Dispatch the messages that Windows give the program..
while ( TRUE )
// Process All Pending Window Messages
while ( PeekMessage( &message, NULL, 0, 0, PM_NOREMOVE ) == TRUE )
if ( GetMessage( &message, NULL, 0, 0 ) )
TranslateMessage( &message );
DispatchMessage( &message );
// Blit to the back buffer. xTo and yTo are where it's blitted to. It blits the whole lpDDSBitmap surface.
int xTo = 0, yTo = 0;
if ( FAILED( lpDDSBack->BltFast( xTo, yTo, lpDDSBitmap, NULL, DDBLTFAST_WAIT ) ) )
// Flip the surface. This makes the back buffer the primary surface and vice versa.
if ( FAILED( lpDDSPrimary->Flip( NULL, DDFLIP_WAIT ) ) )
Posted 08 November 1999 - 09:28 AM
Posted 08 November 1999 - 09:50 AM
Ya know, you're right; it is cool that we go to the same school...
[This message has been edited by Matthew Allen (edited November 08, 1999).]