Ok, I don’t know if I’m doing things right… But I’m trying to put some textures in my project. I made it with some GLubyte bitmap:
GLubyte bitmap[32] = {
// Hexadecimals here
};
And then putted with glBitmap();
Ok. But now I’m trying to get from a BMP file ( test.bmp ) ( after that I’ll try with JPG and PNG. ).
But I’m gettin some trouble, and I don’t know if its really supouse to be this hard: I’m writing a program that opens the BMP image, make sure its BMP ( with the “Magic Words” BM ), get the sizes of it and get the Image-Array.
I’ve done that ! Here’s the code ( kinda lame, but whatever ):
DEV-C++ 4.9.9.2
#include <stdio.h>
#include <iostream>
int main(){
FILE *fp;
int i, j;
char* arquivo;
int MAGIC_NUMBER[2];
int tmp[4];
int H;
int W;
arquivo = "teset.bmp";
fp = fopen(arquivo, "r");
fseek(fp, 0, SEEK_SET);
for(i=0; i<2; i++)
MAGIC_NUMBER[i] = getc(fp);
fseek(fp, 18, SEEK_SET);
for(i=0; i<4; i++)
tmp[i] = getc(fp);
W = tmp[0] | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24);
fseek(fp, 22, SEEK_SET);
for(i=0; i<4; i++)
tmp[i] = getc(fp);
H = tmp[0] | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24);
printf("MAGIC_WORD: %c%c
", MAGIC_NUMBER[0], MAGIC_NUMBER[1]);
printf("WIDTH : %d
", W);
printf("HEIGHT : %d
", H);
fseek(fp, 54, SEEK_SET);
for(i=0; i<H; i++){
for(j=0; j<W; j++){
printf("%2X . ", getc(fp));
}
printf("
");
getc(fp);getc(fp);
}
fclose(fp);
system("pause");
return 0;
}
I’ve learned BMP stuff from wikipedia, then I made that by myself.
Ok, but now what ? What do I do with these information? I mean, how do I put the Array that I get with this code ( actually in here I’m printing on the screen, but you get my point ) and make openGL read it ?
I think I’m in the wrong path I’ts really necessary to do all the things I’m doing ? … openGL starts to be complicated to me here
If someone can help, I appreciate
AND NO, I DON’T WANT TO USE SDL, ALLEGRO, OR WHATEVER. Only if is libPNG, libJPG and ( I don’t know if exists ) libBMP. I don’t know how to use them, anyway