Archived

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

This topic is 6210 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Share on other sites
Ok, here you go:

LPDIRECTDRAWSURFACE7 LoadBmp(LPDIRECTDRAW7 lpDD, TCHAR *file){	HDC		hdc;	HBITMAP bit;	LPDIRECTDRAWSURFACE7 surf;	// See of it''s a resource or an actual file	bit = (HBITMAP)LoadImage(GetModuleHandle(NULL), file, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);	if (!bit)		bit = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);	if (!bit)		return NULL;	BITMAP bitmap;	GetObject(bit, sizeof(BITMAP), &bitmap);	int surf_width = bitmap.bmWidth;	int surf_height = bitmap.bmHeight;	// Create Surface	HRESULT hRet;	DDSURFACEDESC2 ddsd;	ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));	ddsd.dwSize			= sizeof(DDSURFACEDESC2);	ddsd.dwFlags		= DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;	ddsd.ddsCaps.dwCaps	= DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;	ddsd.dwWidth		= surf_width;	ddsd.dwHeight		= surf_height;	// Attempt to Create Surface	hRet = lpDD->CreateSurface(&ddsd, &surf, NULL);	if (hRet != DD_OK)	{		DeleteObject(bit);		return NULL;	}	else	{		surf->GetDC(&hdc);		HDC bit_dc = CreateCompatibleDC(hdc);		SelectObject(bit_dc, bit);		BitBlt(hdc, 0, 0, surf_width, surf_height, bit_dc, 0, 0, SRCCOPY);		surf->ReleaseDC(hdc);		DeleteDC(bit_dc);	}	DeleteObject(bit);	return surf;}

There you go, pretty straightfoward.

"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka

Share on other sites
thanx a lot BitBlt. I''ll study your code and compare it to mine. The thing is that I was engineering my .bmp loader to be direct draw independent. anyway, thankx. I will now look at you code.

Edem Attiogbe

Share on other sites
Hi,

Did you write own bitmap loading program, if so it would be best you scrutinize it well enough, because many a times you want the data and everyone ends up putting & before reading in the data, a silly but non-noticeable mistake and this can cause a lot of problems elsewhere in the program.

I can put in my code but it would be too big so I wouldn''t put it here. But if you do want to see it, just ask and I''ll put it in here.

Share on other sites
I wrote a BMP loader that was DDraw intependant. I then had a char * to DDSurface function that did the specific changes. The only problems that I ever had were when the bitmaps width where not to the base 2 (ie were not 16,32,64,128 etc). When that happened there where some impossibly strange Skewing problems that seemed to defy logic.

Has somebody had this problem, because no amount of hacking code has ever gotten me closer to figuring out why this happens.

-Chris Bennett of Dwarfsoft - The future of RPGs Thanks to all the goblins in the GDCorner niche

Share on other sites
Oh, my bad. I didn''t realize that you were trying to load the bitmap in manually. I use my own custom graphics format, so I don''t have any .bmp reading code, well, I may, I''ll check on my hard drive.

"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka

Share on other sites
Here''s some code I wrote to load RGB bitmaps with OpenGL. Just rip out all of the engine specific stuff, class variables, and OpenGL stuff, and it should work. Saving bitmaps is a whole lot harder than loading them. I''m still having problems with that .
 ` riBool riTexture::LoadBitmap(FILE *File) { struct { riUShort Type; riInt Size; riShort Res1, Res2; riInt OffBits; } BitmapFileHeader; struct { riInt Size; riInt Width; riInt Height; riShort Planes; riShort BitCount; riInt Compression; riInt SizeImage; riInt XPelsPerMeter; riInt YPelsPerMeter; riInt ClrUsed; riInt ClrImportant; } BitmapInfoHeader; riUInt BitCheck = 0x00000001; BitCheck &= fread(&BitmapFileHeader,14,1,File); BitCheck &= fread(&BitmapInfoHeader,40,1,File); if(BitCheck != 0x00000001) return RI_FALSE; if(BitmapFileHeader.Type != 0x4D42 || BitmapInfoHeader.BitCount != 24) return RI_FALSE; if(BitmapFileHeader.OffBits != 0) fseek(File,14+BitmapFileHeader.OffBits,SEEK_SET); riUInt Width = BitmapInfoHeader.Width * 3; riByte *Data = new riByte[Width * BitmapInfoHeader.Height]; riInt Shift = Width % 4; riAssert(Data); if(Shift != 0) { // Load with (evil) padding considered riByte *At = Data; for(riInt a=0; a

[Resist Windows XP''s Invasive Production Activation Technology!]

Share on other sites
If you plan on using Windows, you really don''t need to write a bitmap loader per say. The LoadImage function in the Win32 API will create a valid HBITMAP handle for any .bmp image. Once you have this handle, you now have a DIB (Device Independant Bitmap) and this can be used to draw onto a DirectDraw Surface, output back to a JPEG (using Intel''s JPEG Library) and so on. Just a suggestion.

Kevin

-----------------------------
kevin@mayday-anime.com
http://dainteractive.mayday-anime.com

Share on other sites
The funny thing about my bitmap loader was that I reverted it back to being 100% copied off Andre LaMothe (to see if it would still work) and it worked fine in his programs but it didn''t in mine. Stupid! Something strange to ponder on, but it should work for all and not just the image width of a base 2...

-Chris Bennett of Dwarfsoft - The future of RPGs Thanks to all the goblins in the GDCorner niche

Share on other sites
how would you use the handle of the bitmap to attach the bitmap to a surface then copy it to the back buffer then flip??

X4J

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 37
• 12
• 12
• 11
• Forum Statistics

• Total Topics
631414
• Total Posts
2999950
×