Windowed App - How to blit bitmaps?!  
Author Message
ABS_BEG





PostPosted: Game Technologies: DirectX 101, Windowed App - How to blit bitmaps?! Top

Hello,

I simply want to blit some random pixels (evetually bitmap images) to a WINDOWED app (using DirectX 9 NOT DirectDraw 7 or otherwise).  I have tried the following approach in my Render function but it fails when calling LockRect()..   This approach works in FULLSCREEN mode though - why   What am I not doing correctly / overlooked

Thank you.

 

void Render()
{

...

g_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, m_pBackSurf);
m_pBackSurf->LockRect( &LockedRect, &rect, NULL );    // **** THIS FAILS IN WINDOWED MODE ***

// Get a pointer to the back buffer
DWORD* pData = (DWORD*)LockedRect.pBits;

// Convert the pitch to work with 32 bit (4 byte) surfaces
int Pitch32 = LockedRect.Pitch / 4;

DWORD Color;    // Holds the color of the pixels and rectangles

for( int i = 0 ; i < 1000 ; i++ )
{
      // Get a random color for the pixel
      Color = D3DCOLOR_XRGB( rand()%255, rand()%255, rand()%255 );

      // Set the pixel at x,y to the color
      pData[ Pitch32 * y + x ] = Color;
}

 

 



Game Technologies: DirectX, XNA, XACT, etc.15  
 
 
Ross Ridge





PostPosted: Game Technologies: DirectX 101, Windowed App - How to blit bitmaps?! Top

Have you tried running your program using the debug runtime That should tell you the reason why the lock failed. Did you create the device using D3DPRESENTFLAG_LOCKABLE_BACKBUFFER

If all your going to do is copy a bitmap to a window, you might want to consider using GDI instead. I don't think using Direct3D is going to give you any advantage here.


 
 
ABS_BEG





PostPosted: Game Technologies: DirectX 101, Windowed App - How to blit bitmaps?! Top

Hi Ross,

Thanks for the reply.

Basically I'm trying to develop a 2D terrain/ board and have counters (bitmaps/sprites) running over it.

I'm wondering if the best way to do this is to mingle DirectX with GDI or something else

Any ideas Any web links to similar implementations !

Thanks.


 
 
ABS_BEG





PostPosted: Game Technologies: DirectX 101, Windowed App - How to blit bitmaps?! Top

Ross,

YES - THAT WORKS! I could have spent *ages* looking for this parameter. Thank you.

In reference to my other reply - what is the general consensus for creating 2D "game boards" using DirectX What structures are normally used to create such entities

Any help/ideas/pointers would be massively apprecaited.

Cheers.

ABS_BEG


 
 
David Weller





PostPosted: Game Technologies: DirectX 101, Windowed App - How to blit bitmaps?! Top

Consider looking at the Simple2D sample to see an example of what you're looking for. It's in the SDK.

 
 
Ross Ridge





PostPosted: Game Technologies: DirectX 101, Windowed App - How to blit bitmaps?! Top

In reference to my other reply - what is the general consensus for creating 2D "game boards" using DirectX What structures are normally used to create such entities

The old way would be to use DirectDraw and create a system memory surface and render your "game board" in software on that surface and then blit it to the back buffer. The new way would be to use Direct3D and render your game using the 3D hardware directly on the back buffer. The Simple2D sample David Weller recommended is an example of this. It may be a bit of an overkill for your application, but it does allow you do thing like scaling and alpha-blending sprites in hardware which can be slow and hard to do in software.

If you want to do it the old way, but using Direct3D instead of DirectDraw then instead locking the back buffer and writing to it directly, create an offscreen plain surface in system memory and render to that and the use UpdateSurface() to copy to the back buffer.

Using GDI may still be the best bet you're making a game inteaded to be played by "casual gamers". In that case you'd render to a memory DIB (the in-memory version of a BMP file) and then use SetDIBitsToDevice() to draw to your window. On modern machines I think performance should be acceptable, especially if your DIB matches the display format. You could also consider using Flash to create your game, if your game doesn't need a lot of CPU horsepower.

Ross Ridge


 
 
ABS_BEG





PostPosted: Game Technologies: DirectX 101, Windowed App - How to blit bitmaps?! Top

Thanks David, I appreciate your response.
 
 
ABS_BEG





PostPosted: Game Technologies: DirectX 101, Windowed App - How to blit bitmaps?! Top

Ross, that's fantastic - you've been a great help - thanks for your time and effort.