ddraw related problem

im trying to make a map editor with ddraw due to ive spent awhile learning it (ddraw) and im not so good with gdi. but i havent worked much with ddraw in the case of windowed apps, im normally full screened. the problem is the function ive been using to copy the bitmap data to a off screen surface isnt working as it normally does in windowed. i can tell there is a problem there because when i blit to the primary surface it comes out cooked. so heres the code for my modded function:

int Copy_Bitmap(LPDIRECTDRAWSURFACE7 lpdds, UCHAR * bitmap, int iX, int iY)
{
DDSURFACEDESC2 ddsd;
UCHAR *dest_addr, *source_addr;
int index;

memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);

lpdds->Lock(NULL,&ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL);

dest_addr = (UCHAR *)ddsd.lpSurface;
source_addr = bitmap;

for (index=0; index < iY; index++)
{
memcpy(dest_addr, source_addr, iX);

dest_addr += (ddsd.lPitch);
source_addr += iX;
}

if (FAILED(lpdds->Unlock(NULL)))
return(0);

return(1);
}

any ideas of a better way i could load the bitmaps/ then copy them to a surface would be great, if you cant figure out whats wrong with using my function in windowed apps. UCHAR * bitmap of course is a pointer to the bitmap data. lastly any comments on the idea of me building a windowed app such as a map editor with ddraw would be nice, am i crazy or just going the long way?
[1557 byte] By [master661] at [2007-11-19 10:50:49]
# 1 Re: ddraw related problem
You're saying that this code works for you in fullscreen mode, but does not when you switch to a windowed application? If that's the case, one thing to check would be to make sure that the surface you're copying the bitmap to has the same color depth as the source image. If I recall correctly, in a fullscreen app you can set the color depth explicitly when you set your desired resolution, but in a windowed app you'll be using whatever color depth the user has set in his Windows display settings. If this turns out to be the case then you'll just have to write some code that determines what color depth you're copying to, and alters the source image as necessary while copying. Unless there's some way to change the color format for your offscreen surfaces, but I don't recall.
lastly any comments on the idea of me building a windowed app such as a map editor with ddraw would be nice, am i crazy or just going the long way?
Well, given that DirectDraw is deprecated now, it would probably be worth your time to learn how to do 2D stuff in Direct3D sometime soon. But if you want to stick with DirectDraw, you should have no problems using it to develop a map editor. I've done it several times, though not for several years. ;)
Smasher/Devourer at 2007-11-10 3:50:28 >
# 2 Re: ddraw related problem
my program design is based off a windowed ddraw program i got. in that example it doesnt set the palette so its not the bit format problem due to i tried loading a 8/ 24/ 32 bit image too. i used a gdi method to load it onto a off screen surface and it worked. but its gdi! i didnt spend ages learning ddraw.

HDC hdcImage;
HDC hdc;
HRESULT hr;
HBITMAP hbmOld;
HBITMAP hbm = (HBITMAP)LoadImage(NULL, "alley8.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

hdcImage = CreateCompatibleDC(NULL);
hbmOld = (HBITMAP)SelectObject(hdcImage, hbm);

if((hr = lpDD_Back->GetDC(&hdc)) == DD_OK)
{

BitBlt(hdc,0,0,640,480,hdcImage,0,0,SRCCOPY);
lpDD_Back->ReleaseDC(hdc);
}

SelectObject(hdcImage, hbmOld);
DeleteDC(hdcImage);

Well, given that DirectDraw is deprecated now, it would probably be worth your time to learn how to do 2D stuff in Direct3D sometime soon. But if you want to stick with DirectDraw, you should have no problems using it to develop a map editor. I've done it several times, though not for several years.

i plan to learn d3d after ive made aload of things in ddraw first should be fun i cant wait ;). also is there any chance you could find me some of those old examples you may still have around some place? because it would be really helpful :) (the ddraw stuff like a map editor pls, if you can).
master661 at 2007-11-10 3:51:37 >
# 3 Re: ddraw related problem
As S/D states, you really should think about using Direct3D. However, if you must use DD, I've attached a sample program from an old cd I had on Direct7. It should give you some insight on how to accomplish this.

Note: The sample will look for a bitmap called "vista.bmp". I could not include this file because it made the zip too large to upload. You'll need to create your own 'vista.bmp' file.
Mike Harnad at 2007-11-10 3:52:35 >
# 4 Re: ddraw related problem
:| you really should look at what your attaching before you attach. this example is well old and just uses the same gdi method i posted. plus S/D said it would be probably be worth my while not a must and i do no the difference between the two (dd and d3d).
master661 at 2007-11-10 3:53:38 >
# 5 Re: ddraw related problem
Did you actually read my post? I indicated that it was from an old cd. Like S/D, I prefer Direct3D. In the future, I'll make sure to hesitate before offering any help to you.
Mike Harnad at 2007-11-10 3:54:37 >
# 6 Re: ddraw related problem
i didnt notice S/D peferred d3d but i guess you had to read between the lines there ;/.

also i did read your post, did you read mine again? because all youve done is send me an example using the same method i posted early on in this topic.

so i dont understand why you would do it unless: a) you didnt read the whole topic or b) you didnt look at the example you were sending. thats why i said you should look before attaching...
master661 at 2007-11-10 3:55:36 >