Advertisement

BLT Problem in DirectX

Started by February 03, 2000 07:16 AM
4 comments, last by Goodlife 25 years, 1 month ago
Hi-ho, all... Anyone had this trouble? I have a program that loads a bitmap onto a surface like this: LPDIRECTDRAWSURFACE BitmapToSurface(char *bitmap) { LPDIRECTDRAWSURFACE ddsurface; DDSURFACEDESC ddsd; HRESULT hRes; DDCOLORKEY ddcolorkey; HBITMAP hBM; BITMAP BM; HDC hDCImage; HDC hDC; hBM=(HBITMAP)LoadImage(NULL,bitmap,IMAGE_BITMAP,0,0,LR_LOADFROMFILE/LR_CREATEDIBSECTION); GetObject(hBM,sizeof(BM),&BM); hDCImage=CreateCompatibleDC(NULL); SelectObject(hDCImage,hBM); ZeroMemory(&ddsd,sizeof(ddsd)); ddsd.dwSize=sizeof(ddsd); ddsd.dwFlags=DDSD_CAPS / DDSD_WIDTH / DDSD_HEIGHT; ddsd.dwWidth=BM.bmWidth; ddsd.dwHeight=BM.bmHeight; ddsd.ddsCaps.dwCaps=DDSCAPS_TEXTURE; hRes=lpdd->lpVtbl->CreateSurface(lpdd,&ddsd,&ddsurface,NULL); ddcolorkey.dwColorSpaceLowValue=0; ddcolorkey.dwColorSpaceHighValue=0; hRes=ddsurface->lpVtbl->SetColorKey(ddsurface,DDCKEY_SRCBLT,&ddcolorkey); hRes=ddsurface->lpVtbl->GetDC(newsprite->surface,&hDC); BitBlt(hDC,0,0,BM.bmWidth,BM.bmHeight,hDCImage,0,0,SRCCOPY); ddsurface->lpVtbl->ReleaseDC(newsprite->surface,hDC); DeleteDC(hDCImage); DeleteObject(hBM); return ddsurface; } This has worked PERFECTLY for blitting on three of four computers I tried it on. But on the fourth computer, some of the surfaces are messed up-- they look like they have a bad width, with the whole sprite being diagonally skewed across it-- or, possibly, it''s just garbage. I can''t tell for sure, because if it''s a skew, it''s very wide. Anyone see what I''m doing wrong hee? It''s not EVERY surface, which I would just assume is something I''m doing wrong. Only some of them.
-- Goodlife-----------------------------Those whom the gods would destroy, they first drive mad.--DirectX design team official motto
sorry i can''t help with your problem but why dont you use the ddutil function DDReLoadBitmap, it loads a bitmap straight into a surface.
"I have realised that maths can explain everything. How it can is unimportant, I want to know why." -Me
Advertisement
I don''t think the Win32 API BitBlt takes into consideration the pitch of a surface, so that may be causing your problem.
Also, if you are not going to use the surface as a texture for some 3d object you should do this:

ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
Play free Java games at: www.infinitepixels.com
Maybe I am wrong but try this. Instead of using

hDCImage=CreateCompatibleDC(NULL);

try to use at the end the following code:

hRes=ddsurface->lpVtbl->GetDC(newsprite->surface,&hDC);

// Now insert this line
hDCImage=CreateCompatibleDC(hdc);

BitBlt(hDC,0,0,BM.bmWidth,BM.bmHeight,hDCImage,0,0,SRCCOPY);
ddsurface->lpVtbl->ReleaseDC(newsprite->surface,hDC);
DeleteDC(hDCImage);
DeleteObject(hBM);

and the BitBlt() function takes into consideration the pitch of a surface. Good luck.



Edited by - QWERTY on 2/3/00 5:43:17 PM
Sounds to me like what you want to do is make your surfaces multiples of 8 pixels, eg: 8x8, 16x16, 32x32, 64x64 etc etc, this should solve your problem. I had exactly the same problem a short time ago, whereby my game worked fine on 9 out of 10 pc''s but then on some, random blt''s seemed screwed up. I corrected the problem as above and it now works fine :o)
...Just wanted to thank everyone. Changing them to OFFSCREENPLAIN did the trick. They weren''t supposed to be textures, but when I imported the code from my texture load function, I overlooked that.

Thanks fer all yer help!
-- Goodlife-----------------------------Those whom the gods would destroy, they first drive mad.--DirectX design team official motto

This topic is closed to new replies.

Advertisement