Click to See Complete Forum and Search --> : Urgent Help!! Variable Changing
Hiyo
March 10th, 2005, 12:51 PM
Hi,all
pls help me in my coding i want to change the Variable from long int to unsigned char * in c++, i don't know. the coding as below:
typedef struct {
int width;
int height;
unsigned char *data;
} textureImage;
.......
int loadBMP(char *filename, textureImage *texture)
{
FILE *file;
unsigned short int bfType;
long int bfOffBits;
short int biPlanes;
short int biBitCount;
long int biSizeImage;
int i;
unsigned char temp;
........
biSizeImage = texture->width * texture->height * 3;
printf("Size of the image data: %ld\n", biSizeImage);
texture->data=&biSizeImage; ---->>>how to change here????
/* seek to the actual data */
fseek(file, bfOffBits, SEEK_SET);
if (!fread(texture->data, biSizeImage, 1, file))
{
printf("Error loading file!\n");
return 0;
}
i can't get proper value from 'texture->data=&biSizeImage;' pls tell me hw to change it!
Thank you!!!!
Elementer
March 10th, 2005, 02:40 PM
Hello,
are you loading a bitmap ? What are you doing ????
Bitmap structure si very simple, from top to bottom of the file you have:
Bitmap file header ---> Bitmap info ---> Palette (if palettized) ----> Bitmap data
If you need only to read the pixels data that are "unsigned char" type (I don't understand where came out the conversion you need) you do this:
move the pointer to file correct position where is the bitmap data, allocate the memory for pixel storage and read them. So, you must allocate the data before read it, with:
texture->data = malloc or new bitmap_info.biSizeImage;
read(texture->data)
Why you are pointing the data ptr to &biSizeImage ??
Cheers
Hiyo
March 10th, 2005, 09:07 PM
Hi,Elementer
Thanks for replying me.
Actually I m trying to texture mapping some bitmap files to a mesh, to make it looks like a Renju Chess board.
It works properly if i use texture->data = malloc(biSizeImage); under C. But now i need to change this coding to C++, cause C++ can support class (my AI part coding is write in C++). So this problem occured.
I just tried new bitmap_info.biSizeImage; instead of malloc(biSizeImage); just now, it seems not work. The error is 'error C2061: syntax error : identifier 'bitmap_info''
Sorry i m just a beginner for programming. Can you pls help me more?
Thanks.
MrViggy
March 11th, 2005, 12:45 PM
Well, C++ is just a superset of C, so if it works in C then it should work in C++.
Also, I don't see a 'bitmap_info' or a call to new in the code you posted, so it's hard to say (except that maybe you never declared 'bitmap_info').
Viggy
Elementer
March 11th, 2005, 02:39 PM
Hello,
"bitmap_info" is a string I use during my post, it's nothing... With it I refer to BITMAPINFOHEADER and BITMAPFILEHEADER structures that contains also the image width and height informations, that you can read if you want, they're at top of bitmap file.
I can't undestand why you're loading a simple bitmap byhand, you can use the auxiliary OGL function to load a bitmap file (ok, for learn it's right, you must load it byhand the first time), just including <gl/glaux.h> and link the "glaux.lib", you have to do:
AUX_RGBImageRec *ptr[1]; //ptr to store pixel data
memset(ptr, 0, sizeof(void*));
ptr[0] = auxDIBImageLoad("Data/textures/example.bmp");
Now you have ptr[0] that contain ->sizeX, ->sizeY and ->data, features of bitmap that you have loaded, and you can generate texture with your OGL routines.
Bye :)
Hiyo
March 11th, 2005, 10:22 PM
Thanks,
i think i found out the solution, one of my friend just taught me use
texture->data = (unsigned char*)malloc(biSizeImage);
Thanks for helping me.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.