Archived

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

remi

Blt problem

Recommended Posts

Hi all, i''m having a curious problem with the IDirectDrawSurface7::Blt() function. When the Destination and Source rectangles have the same widths and heights everything goes fine, but when the Destination and the Source are differents a line appears in the most right part of the sprite, uhmm.....i try to find the reasons of this myself but...NADA. Anyhelp?

Share this post


Link to post
Share on other sites
i don''t think the StretchBlt() function is a DirectX''s function, i may be wrong!

The Dx''s Blt() has the capability to perform Stretch blits, but i have a line that appears in the right most part of my sprite: that''s the problem.

Anyhelp?

Share this post


Link to post
Share on other sites
When you make your sprites do you have like a border around them?
Like in Game Prog for Dummies or TWGPG? If not ignore this, if you do then you may be accidently picking up your border when you extract the sprite from the bmp. Maybe

Share this post


Link to post
Share on other sites
If you have a source rect larger than the surface of the actual source that is probably the reason why you have that line on a sprite. When you blit you are just copying the memory from one area to another, with a larger source rectangle, you will start to grab and copy stuff that''s not a part of the surface...but I would also think that you would get an access violation error - like an illegal operation or something if that was the case.

If you want to strech, make the source rect normal, the destination should be what''s larger.

"Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.

Share this post


Link to post
Share on other sites
Thanx all for answering

But i''m not sure if my problem has been got clearly.

1.I have some sprites in a black picture with no borders!

2.The function IDirectDrawSurface7::Blt() can perfom stretch blitting when the Source and Destination rectangles have differents sizes.

But what is curious is that when those rectangles have the same size it''s works well, when they''re differents it stretch blits greatly but adding another line!

That''s the problem!

Share this post


Link to post
Share on other sites
Look at how are you loading the bitmaps, maybe the source surface is getting corrupt in some way, or when you set the rects for the sprite. the problem has to be between those.

[edited by - xaxa on August 12, 2002 2:35:40 AM]

Share this post


Link to post
Share on other sites
I didn't want to do this but i'm force to.
Ok these are ny codes

    
//---------------------------------------------------------------------------------------

//LPRECT GDEVICE::LoadBitmapToSurface(LPDIRECTDRAWSURFACE7 *lplpddsSurface,char* filename,WORD dwFlag)

//

//---------------------------------------------------------------------------------------

LPRECT GDEVICE::LoadBitmapToSurface(LPDIRECTDRAWSURFACE7 *lplpddsSurface,char* filename,WORD dwFlag)

{
if(*lplpddsSurface)
{
(*lplpddsSurface)->Release();
*lplpddsSurface=NULL;
}

HBITMAP hBitmap;
BITMAP bBitmap;
LPRECT lpRect=new(RECT);
DDSURFACEDESC2 desc;
HDC hDest,hSrc;
hBitmap=(HBITMAP)LoadImage(NULL,filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_DEFAULTSIZE);

GetObject(hBitmap,sizeof(bBitmap),(void *)&bBitmap);
ZeroMemory(&desc,sizeof(desc));
desc.dwSize=sizeof(desc);
desc.dwFlags=DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
lpRect->right=desc.dwWidth=bBitmap.bmWidth;
lpRect->bottom=desc.dwHeight=bBitmap.bmHeight;
lpRect->left=lpRect->top=0;
desc.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN | dwFlag;
if((lpDD->CreateSurface(&desc,lplpddsSurface,NULL))==DDERR_OUTOFVIDEOMEMORY)
{
OutputDebugString("Not enough Video memory");
MessageBox(NULL,"Not enough Video memory","Error",MB_OK);
desc.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
if((lpDD->CreateSurface(&desc,lplpddsSurface,NULL))==DDERR_OUTOFMEMORY )
{
OutputDebugString("Not enough system memory");
return NULL;
}
}
(*lplpddsSurface)->GetDC(&hDest);
hSrc=CreateCompatibleDC(hDest);
SelectObject(hSrc,hBitmap);
BitBlt(hDest,0,0,bBitmap.bmWidth,bBitmap.bmHeight,hSrc,0,0,SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(hSrc);
(*lplpddsSurface)->ReleaseDC(hDest);
return lpRect;
}

And here the codes for drawing

//--------------------------------------------------------------------------------------

//int SPRITE::Draw(LPDIRECTDRAWSURFACE7 lpddsDest)

//

//--------------------------------------------------------------------------------------

int SPRITE::Draw(LPDIRECTDRAWSURFACE7 lpddsDest)
{
int i=spImage->Animation[iCurrAnim][iCurrFrame];

RECT Rect;
SetRect(&Rect,x,y,x+Width,y+Height);

DDBLTFX ddBltfx;
ZeroMemory(&ddBltfx,sizeof(ddBltfx));
ddBltfx.dwSize=sizeof(ddBltfx);
ddBltfx.ddckSrcColorkey=spImage->ddcTransparent;

HRESULT hr;
if(FAILED(hr=lpddsDest->Blt(&Rect,spImage->lplpddsImage[i],NULL,DDBLT_WAIT |
DDBLT_KEYSRCOVERRIDE,&ddBltfx)))
ErrorMessage(hr);

return 0;
}


Everything is here, i really need your help DX Guys!!

[edited by - remi on August 12, 2002 2:48:12 AM]

Share this post


Link to post
Share on other sites
hi,

Try using:

StretchBlt( hDest, 0, 0,
bBitmap.bmWidth, bBitmap.bmHeight,
hSrc, {dwBMPOriginX}, {dwBMPOriginY},
{dwBMPWidth}, {dwBMPHeight}, SRCCOPY );

instead of:
BitBlt(hDest,0,0,
bBitmap.bmWidth,bBitmap.bmHeight,hSrc,0,0,SRCCOPY);

Just to see what happend. Microsuckft does it this way.
---
int SPRITE::Draw(LPDIRECTDRAWSURFACE7 lpddsDest){
...SetRect(&Rect,x,y,x+Width,y+Height);...
Are you setting the right values for Width and Height? Are you doing it inside a case or if statement?

I hope this can help you. Good luck there

Share this post


Link to post
Share on other sites
I try it "xaxa", but it still not working, and personally i don''t find the need to do that modification at that place.

The width and Height are not set in an if statement but by overloaded functions. I mean that if u send a width or height value it''s considered in the other case the default width and height are taken; in which case they are the width and height of the sprite(grapgic).

I''m going crazy.

Share this post


Link to post
Share on other sites
Whatta bich of bug, try debugin watching what you do with the rects and the surface before blitting. If you give up, try using functions that comes with ddraw samples, and adapt them to your needs, they work.
ELSE
Google: +"blitting" +"adds a line" +why

Share this post


Link to post
Share on other sites
Great idea!
i''ll try to check inside the ddraw sample codes, and see the differences between their codes and mine.

If i find something i''ll let u know, promise

Share this post


Link to post
Share on other sites