Skip to main content
gamedev.net
🔒 Locked

Loading bitmaps

Started by Sir_Spritely 10 replies 300+ views
Original Post
Sir_Spritely
Sir_Spritely
Hey, I am trying to load a bitmap image, I have the image in the same dir as the project code but for some reason the image still is not appearing? Loading code: - // load the 8-bit image if (!Load_Bitmap_File(&bitmap,"bitmap8.bmp")) return(0); I have tried using a path such as c:\windows\etc.. to point to the dir of the image. I have also tried adding the bitmap file to the resources but still nothing? This is an example from the TOTWGPG book and should work so I presume I am either doing something wrong with the path or doing something wrong with the compiler? Any help appreciated. Paul
Sir_Spritely
Sir_Spritely
Hey,

Forgive me if this is the wrong info but I am at the very very early stages of learning this:-

// container structure for bitmaps .BMP file
typedef struct BITMAP_FILE_TAG
{
BITMAPFILEHEADER bitmapfileheader; // this contains the bitmapfile header
BITMAPINFOHEADER bitmapinfoheader; // this is all the info including the palette
PALETTEENTRY palette[256]; // we will store the palette here
UCHAR *buffer; // this is a pointer to the data

} BITMAP_FILE, *BITMAP_FILE_PTR;

int Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename);

The code should be okay as it is from a very good book and I haven''t had probs with the code before. I presume I am doing something wrong with the compiler rather than the code is wrong.

Paul
Sir_Spritely
Sir_Spritely
Hi,

The executable examples of the CD for the Tricks of the windows games programming gurus don''t work eithier 7_10.cpp - 7_12.cpp.
They load and I get a brief glimpse of the bitmap before it flashes off quickly less than a second. Could this be my card or my system setup or has this happened to anyone else before?

Pk.
CaptainJester
CaptainJester
Yes, it is from a good book. However, the Load_Bitmap_File() alone does not create the bitmap. This is one point of his book that I found unnecessarily complicated. Anyway, here is what you have to do, if you haven''t already:

  
BITMAP_FILE myFile;
BITMAP_IMAGE myImage;
LPDDSURFACEDESC4 lpddsprimary; //defined earlier

LPDDSURFACEDESC2 ddsd;

//creates a blank bitmap for transferring in from a file

//800,600 is the width and height

Create_Bitmap(&myImage,0,0,800,600);
//loads the bitmap from disk, ready to be put into an image

Load_Bitmap_File(&myFile,"bitmap8.bmp");
//transfers the bitmap into the image

Load_Image_Bitmap(myImage,&myFile,0,0,BITMAP_EXTRACT_MODE_ABS);
//set up the surface description to get the pitch and a

//pointer to the drawing surface

ddsd.dwSize=sizeof(ddsd);
ddsd.dwFlags=DDSD_LPSURFACE|DDSD_PITCH;
//lock the surface for drawing

lpddsprimary->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
//draw the bitmap to the locked surface

Draw_Bitmap(&myImage,ddsd.lpSurface,ddsd.lPitch,0);
//unlock the surface

lpddsprimary->Unlock(NULL);


As you can see, it is a little complex. If you have the DirectX 7 SDK or higher, it comes with some utility code in DDUtil.cpp, which has a function called: DDLoadBitmap(). For your program, you can just declare a surface pointer and call the funciton, then Blt to the drawing surface.

LPDIRECTDRAW7 lpdd;
LPDDSURFACEDESC7 lpddsmysurface;

lpddsmysurface=DDLoadBitmap(lpdd,"bitmap8.bmp",0,0);
lpddsprimary->Blt(etc etc....

There''s a little setup missing, but it is easy enough to figure out.

---
Make it work.
Make it right.
Make it fast.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
CaptainJester
CaptainJester
quote:
Original post by Sir_Spritely
Hi,

The executable examples of the CD for the Tricks of the windows games programming gurus don''t work eithier 7_10.cpp - 7_12.cpp.
They load and I get a brief glimpse of the bitmap before it flashes off quickly less than a second. Could this be my card or my system setup or has this happened to anyone else before?

Pk.


No, it doesn''t work on mine either. Except, I just get a fuzzy sprite moving accross the screen. I think he hurried that part a little and didn''t test it out. I find the DDUtil in the SDK much easier to use.



---
Make it work.
Make it right.
Make it fast.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Sir_Spritely
Sir_Spritely
Cheers,

I think I kinda have it sorted in my head. I was struggling with it before this though . I''ll have a play with it.

Pk
KwamiMatrix
KwamiMatrix
Well, i wrote my own .bmp loading class, but could not get my bitmaps to load into a direct draw back buffer. I have basically ditched Direct Draw, and will only use OpenGL for both 2D and 3D graphics. I am not that interested in Direct 3D, because I want to be able to port my engine to other computer systems, especially UNIX(Sun Solaris 8) and Linux. I have to test my Bitmap class with OpenGl now. I have the Andre Lamothe book, and it is good. .bmp work is tricky for me, though. I will code .tga and .jpg loaders.

Edem Attiogbe

Edited by - KwamiMatrix on December 4, 2001 11:58:13 AM
Edem Attiogbe
Muzlack
Muzlack
I would suggest just using the DDLoadBitmap function in ddutil.h, it is included w/ the dx sdk.
--Muzlack
Sir_Spritely
Sir_Spritely
Hey,

I am using DirectX V6 which is included with the Game Gurus book, just to make life easier. I guess the problem I am having now is, where to change the code in the program, I am very very very new to this and it was hard enough with the book examples working let alone not working. It looks like it''ll take me twice as long now .

By the way, what is the DirectX SDK, LOL, I know this is a lame ? but, ohe well LOL.

Pk

Topic Locked

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

Sign in to reply to this topic.