Skip to main content
gamedev.net
🔒 Locked

Run-time resources

Started by Goodlife 4 replies 550+ views
Original Post
Goodlife
Goodlife
Hi all, Some of you might know me from my posts below, "Initializing directx in three easy-to-read lines" and "rendering 2,000,000 polygons in .2 ms: here''s how." Well, I''ve put into the system, an'' now I wanna get some back. I''ve been wrestling with this bitmap problem-- I have a big wadfile with bitmaps stuck willy-nilly into them. I want to simulate the LoadBitmap command to pull information from the wadfile instead of from a resource file. The wadfile IS my resource file, and it needs to be flexible enough for the end-user to add bitmaps to it. All 64 avenues I have taken to solve this have lead me to dead ends, although I know more about the winapi bitmap functions that I ever wanted to know. I would scrap them completely if they didn''t do such good dithering. So, my question is: Can I make a resource at run-time? Or something similar? The LoadImage command lets me pull in a bitmap from a file or a resource, but God bless ''em, they don''t let you do it from a memory pointer. What I''d like to do is make a run-time resource from my wadfile bitmap, load it in, BitBlt it onto my directdraw surface (<-- how I justify posting this under directx/opengl/genesis3D) and then scrap the run-time resource. Has anyone played with this sort of madness before? Thanks in advance! -- Goodlife ----------------------------- Think of your mind as a door on a house. Leave the door always closed, and it's not a house, it's a prison. Leave the door always open, and it's not a house, it's a wilderness-- all the vermin creep in.
-- Goodlife-----------------------------Those whom the gods would destroy, they first drive mad.--DirectX design team official motto
[MG]Kaewan
[MG]Kaewan
I once asked the very same question that you asked.
What I have done to get the bitmaps onto the surface is quite simple- If you stored the bitmaps in your ''wadfile'' (hehe) just as they are in .bmp format (byte for byte).

I assume your ''wadfile'' has a ''table of contents'' entry for each file in your wadfile (so you just jump to the address of the byte for the stored file, and start reading).
Since you know the file is a BMP file, you can get the width and height of it directly from your wadfile. You will have to find the BMP file specification to know at what offset the width and height are stored.
Once you have the width and height, create an offscreen directdraw surface with those dimensions.
Now comes the hard part. You have to read in the data part of the BMP byte for byte and write it directly on the offscreen surface. Writing is tricky however, and varies with the bit depth of the BMP file in the wadfile. If its a 24-bit BMP file, you know there are 3 bytes for each pixel, 16-bit has 2 bytes/pixel and 8-bit has 1 byte (but can also have a palette).

If this is the type of information you require, ICQ me @ 1888925.
[MG]Kaewan

The Mage Guild
The Mage Guild
DerekSaw
DerekSaw
You can do like this:


void LoadBMP24 (int width, int height, void *data)
{
/* 'data' points to the actual bits/byte of the image */
BITMAPINFO bi;
memset (&bi, 0, sizeof(bi));
bi.bmiHeader.biSize = sizeof (bi.bmiHeader);
bi.bmiHeader.biWidth = width;
bi.bmiHeader.biHeight = height;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;

HDC dc;
ddsurface1->GetDC (&dc);
::StretchDIBits (dc,
0, 0, width, height,
0, 0, width, height,
data, &bi, DIB_RGB_COLORS, SRCCOPY);
ddsurface1->ReleaseDC (dc);
}


Correct me if i'm wrong. This works with only 24bit BMP. Need to modify for loading in other bit depth.

Edited by - DerekSaw on 4/26/00 10:04:48 AM
"after many years of singularity, i'm still searching n the event horizon" o
Goodlife
Goodlife
Hi, thanks Derek. I looked at your post, and I started thinking. Then I looked in the Windows API files in a way that I was apparently unable to do a few hours ago.

And I found it-- CreateDIBitmap. You send it a BITMAPINFOHEADER, a BITMAPINFO, and a pointer to the bitmap''s bits, and you''re in business.

Thanks for your help, though-- while it wasn''t the answer I was looking for, it somehow put me into the right frame of mind. Three Cheers!


-- Goodlife

-----------------------------
Think of your mind as a door on a house. Leave the door always closed, and it's not a house, it's a prison. Leave the door always open, and it's not a house, it's a wilderness-- all the vermin creep in.
-- Goodlife-----------------------------Those whom the gods would destroy, they first drive mad.--DirectX design team official motto
Buster
Buster
I think you are missing one variable for that function. Don''t you need an index or some offset to the start of the data for that one bitmap?

Something like:
LoadBitmap(int bmID, char *data, int w, int h);

Of course, w and h MAY be in the data itself, I can''t remember.
DerekSaw
DerekSaw
Goodlife: Three Cheers!

Buster: Hmm... maybe I add one more paramter as accepting an IDirectDrawSurface*. Here''s a sample I call the function:


// ... some code here ...
FILE *fp_in = fopen ("TEST.BMP", "rb");
long size = filelength (fileno (fp_in));
unsigned char *buf = new unsigned char[size + 1];
fread (buf, 1, size, fp_in);
BITMAPINFOHEADER *bih = buf;
LoadBMP24 (lpddsBackground, bih->biWidth, bih->biHeight, buf + bih->dwOffset);
// ... do some cleanup ...


The code might be wrong... but it is something like this (I just simply type this without looking my code).
"after many years of singularity, i'm still searching n the event horizon" o

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.