PDA

View Full Version : Loading bitmaps



03-04-2004, 11:26 AM
Im trying to load a bitmap using openGl under linux redhat 9, but i cant seem to figure out how to do it, done some research but so far i come accross windows examples.
Anyone with some Ideas?
Thanks
Sokoyoo

nexusone
03-04-2004, 12:00 PM
Nehe.gamedev.net has linux examples at the bottom of each of his lesson's pages.



Originally posted by sokoyoo:
Im trying to load a bitmap using openGl under linux redhat 9, but i cant seem to figure out how to do it, done some research but so far i come accross windows examples.
Anyone with some Ideas?
Thanks
Sokoyoo



[This message has been edited by nexusone (edited 03-04-2004).]

colguin
03-04-2004, 08:28 PM
Here is how I read in a bitmap:
This here is for a 256x256 bmp, but can
be changed as necessary. The bmp is loaded into the image array where the 3 values are
the rgb values.

void load_bmp_256(char name[30], GLubyte image[256][256][3])
{
int i, j;
int stat;
char color[3];
FILE *fptr;

if ((fptr = fopen(name,"rb")) == NULL)
{
fprintf(stderr,"Unable to open BMP file.\n");
exit(-1);
}

fseek(fptr,54,SEEK_SET);//we skip the header

for (j=0;j<256;j++)
{
for (i=0;i<256;i++)
{
stat = fread(color, 1, 3, fptr);
image[i][j][0]=color[2];
image[i][j][1]=color[1];
image[i][j][2]=color[0];
}
}fclose(fptr);
}