Sign in to follow this  
_Sigma

Rather silly Blting question

Recommended Posts

_Sigma    792
Right, I can blt a BMP to the backbuffer, and then flip. This works just fine, but when I add another surface, and try to blt one after another, it doesn't work. The blt fails. Now, I don't have colorkey. Is this going to be an issue? Here is my code:
#include "Unit1.h"
#include <ddraw.h>
#include "Mercury.h"

extern LPDIRECTDRAW7 lpdd;  //version 7.0 main
extern MercuryEngine GameEngine; //Main GameEngine

class BOB
{
public:
 int x,y; //x-y coords
 LPDIRECTDRAWSURFACE7 DDBOB; //DX BACK surface
 RECT src_rect;
 RECT dest_rect;
 BOB();
};

BOB::BOB()
{
//int bob!

           this->src_rect.left = 0;
           this->src_rect.top = 0;
           this->src_rect.right = 63;
           this->src_rect.left = 63;

           this->dest_rect.left = 100;
           this->dest_rect.top = 100;
           this->dest_rect.right = 100+63;
           this->dest_rect.left = 100+64;

           this->x = 100;
           this->y = 100;

}

...

BOB bob;

...

if(FAILED(DDback->Blt(&dest_rect,DDback_sprite,&src_rect,DDBLT_WAIT, NULL)))
{
 Application->MessageBoxA("Error","Boom",MB_OK);
 Application->Terminate();
}


if(FAILED(DDback->Blt(&bob.src_rect,bob.DDBOB,&bob.dest_rect ,DDBLT_WAIT,NULL)))
{
  Application->MessageBoxA("BOB don't like you!","Boom",MB_OK);
 Application->Terminate();
}
Its the second BLT that fails. Also, if I put the LoadBitmap for BOB into the constructor of BOB, it get what seems to be an adress error. Any ideas? Cheers Sigma

Share this post


Link to post
Share on other sites
dhanji    192
what is the error returned from the HRESULT?

you have omitted the code that sets up the dd surface, so it is difficult to say what exactly is wrong...

Share this post


Link to post
Share on other sites
_Sigma    792
Well I think that the DD surface set up is ok because my other bitmap is loaded, but here it is:


//Create Surface///////////////////////////////////////////////////////////
//Creats any size surface
//////////////////////////////////////////////////////////////////////////
bool MercuryEngine::CreateSurface(LPDIRECTDRAWSURFACE7 *lpSource, int xs, int ys)
{
DDSURFACEDESC2 ddsd;

ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN ;//| DDSCAPS_VIDEOMEMORY;
ddsd.dwWidth = xs;
ddsd.dwHeight = ys;
if(lpdd->CreateSurface(&ddsd, lpSource, NULL) != DD_OK)
{
return false;
}
else
{
return true;
}



}

//-----------------------------------------------------------------------------
// Name: DDLoadBitmap()
// Desc: Create a DirectDrawSurface from a bitmap resource.
//-----------------------------------------------------------------------------
/*extern "C"*/ IDirectDrawSurface7 *
MercuryEngine::DDLoadBitmap(IDirectDraw7 *pdd, LPCSTR szBitmap, int dx, int dy)
{
HBITMAP hbm;
BITMAP bm;
DDSURFACEDESC2 ddsd;
IDirectDrawSurface7 *pdds;


//
// Try to load the bitmap as a resource, if that fails, try it as a file
//
hbm = (HBITMAP) LoadImage(GetModuleHandle(NULL), szBitmap, IMAGE_BITMAP, dx,
dy, LR_CREATEDIBSECTION);
if (hbm == NULL)
hbm = (HBITMAP) LoadImage(NULL, szBitmap, IMAGE_BITMAP, dx, dy,
LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if (hbm == NULL)
return NULL;
//
// Get size of the bitmap
//
GetObject(hbm, sizeof(bm), &bm);
//
// Create a DirectDrawSurface for this bitmap
//
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = bm.bmWidth;
ddsd.dwHeight = bm.bmHeight;
if (pdd->CreateSurface(&ddsd, &pdds, NULL) != DD_OK)
return NULL;
DDCopyBitmap(pdds, hbm, 0, 0, 0, 0);
DeleteObject(hbm);
return pdds;
}
//-----------------------------------------------------------------------------
// Name: DDCopyBitmap()
// Desc: Draw a bitmap into a DirectDrawSurface
//-----------------------------------------------------------------------------
/*extern "C" */HRESULT
MercuryEngine::DDCopyBitmap(IDirectDrawSurface7 * pdds, HBITMAP hbm, int x, int y,
int dx, int dy)
{
HDC hdcImage;
HDC hdc;
BITMAP bm;
DDSURFACEDESC2 ddsd;
HRESULT hr;

if (hbm == NULL || pdds == NULL)
return E_FAIL;
//
// Make sure this surface is restored.
//
pdds->Restore();
//
// Select bitmap into a memoryDC so we can use it.
//
hdcImage = CreateCompatibleDC(NULL);
if (!hdcImage)
OutputDebugString("createcompatible dc failed\n");
SelectObject(hdcImage, hbm);
//
// Get size of the bitmap
//
GetObject(hbm, sizeof(bm), &bm);
dx = dx == 0 ? bm.bmWidth : dx; // Use the passed size, unless zero
dy = dy == 0 ? bm.bmHeight : dy;
//
// Get size of surface.
//
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
pdds->GetSurfaceDesc(&ddsd);

if ((hr = pdds->GetDC(&hdc)) == DD_OK)
{
StretchBlt(hdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, x, y,
dx, dy, SRCCOPY);
pdds->ReleaseDC(hdc);
}
DeleteDC(hdcImage);
return hr;
}





[Edited by - Coder on October 18, 2004 7:40:09 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this