BMP PROBLEMS!
ARGHGH i am having many a problem with BMP''s and accessing the data in them. I can load them using LoadImage but then i don''t know how to access the info in it. I can blit it all i want, but i want to read it like a heightmap. I have tried to use ddutil.cpp and ddutil.h to get the info onto a dd surface, but they won''t compile, no matter what i do. i get this error
d:\program files\microsoft visual studio\myprojects\terrain\ddutil.cpp(320) : fatal error C1010: unexpected end of file while looking for precompiled header directive
i don''t know that error
if you can help me, please, i am at a standstill, i have been trying to fix this for about 7 hours now...
Razial
Hopefully this will help. After you call LoadImage(), try this:
I don''t exactly what kind of info you want, but if you want like pixel values, you can just read in each pixel from the surface you want. If there''s something specific you want, post it.
Make games, it''s fun
HBITMAP bit = LoadImage(...);BITMAP bitmap;GetObject(bit, sizeof(BITMAP), &bitmap);// now you can access info about the bitmap using members// of the BITMAP structure// i.e.int width = bitmap.bmWidth;// check out the BITMAP members to see if it has what you want
I don''t exactly what kind of info you want, but if you want like pixel values, you can just read in each pixel from the surface you want. If there''s something specific you want, post it.
Make games, it''s fun
You are using a pre-compiled header, so you have to include it at the top of evry cpp file. at the top of ddutil.cpp add #include "stdafx.h"
PaladinGLT
PaladinGLT
Yeah, thanks for the responses. Um, well, i can''t find the precompiled header or anything, i dunno. I am implementing a RAW data loader. The problem with accessing the data in the BITMAP file is this:
BITMAP bm
bm.bmBits <- I believe this to be the surface, which is what i want to access, but it is a void*, so i (in my lack of knowledge) do not know how to access this... it says void* is zero if i try to index it
Oh well, thanks for the help
Razail
BITMAP bm
bm.bmBits <- I believe this to be the surface, which is what i want to access, but it is a void*, so i (in my lack of knowledge) do not know how to access this... it says void* is zero if i try to index it
Oh well, thanks for the help
Razail
Just go to the file (the .cpp) click with the right button mouse, select settings, choose the c/c++ tab and from category choose precompiled headers. Select "Not using precompiled headers" and you are ok. So thus the problem with not knowing what a precompiled header is (as it seems you don''t know and i wonder how you have started writing games, but everyone learns, just learning something before using it saves you time) no more exitst. Though you have to include the common files ddutil needs such as ddraw.h, windows.h etc.
Hope this helps you.
Rusenec
Hope this helps you.
Rusenec
I use something similar to this:
Now, you can simply load an 8-bit/24-bit height map like so...
CBitmap HeightMap("hMap.bmp";
And it will be stored as HeightMap.data, HeightMap.Width, HeightMap.Height.. and HeightMap.BitDepth... of course you can change the class around to leave out the pallete (for heightmaps, you don''t need/want this), and only do 8-bit instead of 8/24.
Billy - BillyB@mrsnj.com if you need help with this.
Disclaimer: I did not test this code, and wrote it within this window, but I''m pretty sure it will work. If not, lemme know and I can fix it up for you. This loads the bitmap directly from the file and saves it to an array of unsigned chars, so no need for creating/deleting surfaces, etc, etc.
#include <stdio.h> //Our Standard I/O (C Standard).class CBitmap{public: unsigned short Width, Height; unsigned char BitDepth; unsigned char *data; unsigned char *pallete; unsigned char Loaded;public: CBitmap(){Loaded=0; data=0; pallete=0;}; CBitmap(char *FileName); void LoadBitmap(char *FileName); void KillBitmap(); ~CBitmap(){KillBitmap();};};void CBitmap::KillBitmap(){ if (Loaded) { if (data) delete data; if (pallete) delete pallete; Loaded=0; data=0; pallete=0; }}void CBitmap::LoadBitmap(char *FileName){ FILE *in = fopen(FileName,"rb"); short tx,ty; unsigned long tSize, Offset; KillBitmap(); //Incase somethings loaded already! if (!in) return; //File not found! if (getc(in)!=''B'' || getc(in)!=''M'') //Valid bitmap? { fclose(in); return; } fseek(in,18,0); Width=getw(in); //Read in Width fseek(in,22,0); Height=getw(in); //Read in height fseek(in,28,0); BitDepth=getc(in); //Read in bitdetph! tSize = Width; tSize*=Height; tSize*=BitDepth>>3; // bitdepth/8 = bitsperpixel! data = new unsigned char[tSize]; if (!data) { fclose(in); return; //Not enough memory! } fseek(in,54,0); if (BitDepth==8) //Need our pallete { pallete = new unsigned char[256*3]; if (!pallete) { delete data; fclose(in); return; //Not enough memory! } Offset=0; for (tx=0;tx!=256;++tx) { pallete[Offset+2]=getc(in); //Blue pallete[Offset+1]=getc(in); //Green pallete[Offset+0]=getc(in); //Red getc(in); //Intensity... don''t need to store this! Offset+=3; } } for (ty=Height-1;ty!=-1;--ty) //Bitmaps are stored upside down! { Offset=ty*Width*(BitDepth>>3); for (tx=0;tx!=Width;++tx) { if (BitDepth==8) data[Offset++]=getc(in); else if (BitDepth==24) { data[Offset+2]=getc(in); //Blue data[Offset+1]=getc(in); //Green data[Offset+0]=getc(in); //Red Offset+=3; } } } fclose(in);}CBitmap::CBitmap(char *FileName){ Loaded=0; data=0; pallete=0; LoadBitmap(FileName); //call loadbitmap!}
Now, you can simply load an 8-bit/24-bit height map like so...
CBitmap HeightMap("hMap.bmp";
And it will be stored as HeightMap.data, HeightMap.Width, HeightMap.Height.. and HeightMap.BitDepth... of course you can change the class around to leave out the pallete (for heightmaps, you don''t need/want this), and only do 8-bit instead of 8/24.
Billy - BillyB@mrsnj.com if you need help with this.
Disclaimer: I did not test this code, and wrote it within this window, but I''m pretty sure it will work. If not, lemme know and I can fix it up for you. This loads the bitmap directly from the file and saves it to an array of unsigned chars, so no need for creating/deleting surfaces, etc, etc.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement