• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

King

Blitting to and from a Back Buffer

5 posts in this topic

Hey you!
To make a couple of back buffers, you have to make the primary surface with the "two back buffers" flag:

// 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 ) ) )
return FALSE;

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 ) ) )
return FALSE;

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...

------------------
- mallen22@concentric.net
- http://members.tripod.com/mxf_entertainment/

0

Share this post


Link to post
Share on other sites
Here's some code to grind on:

int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
// This stores the messages that Windows sends the program.
MSG message;

// Init the system stuff.
if ( sys_Init( hInstance, nCmdShow ) == FALSE )
return 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 );
}
else
return TRUE;
}

// 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 ) ) )
return FALSE;

// Flip the surface. This makes the back buffer the primary surface and vice versa.
if ( FAILED( lpDDSPrimary->Flip( NULL, DDFLIP_WAIT ) ) )
return FALSE;
}

return message.wParam;
}

------------------
- mallen22@concentric.net
- http://members.tripod.com/mxf_entertainment/

0

Share this post


Link to post
Share on other sites
YOUR SO COOL MAN, YOU GO TO THE SAME SCHOOL AS ME, too bad nobody else likes my post, i'm beginning to cry. oh well ... thanks matthew, i'll definitly grind on some of that beautiful code. Hey if you read this again, go to the MXF Site and read the tutorial on fire, its pretty swell i think.

-King
MXF ENTERTAINMENT

0

Share this post


Link to post
Share on other sites
And a fine fire it is!
Hey, if anyone else besides King and me are reading this, go to http://members.tripod.com/mxf_entertainment/tutorials/buildingfire.htm !!!

Ya know, you're right; it is cool that we go to the same school...

------------------
- mallen22@concentric.net
- http://members.tripod.com/mxf_entertainment/

[This message has been edited by Matthew Allen (edited November 08, 1999).]

0

Share this post


Link to post
Share on other sites
OK, i'm really new to programming in DirectX and i'm wondering how I could go about creating a Back Buffer, then Blit a bitmap to it, then from the Buffer on to the Primary suface. I've been trying to figure this out for hours, any help would be appretiated. thanks

-King
MXF ENTERTAINMENT

0

Share this post


Link to post
Share on other sites