GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


problem with loading bitmaps by vexator
1
 
i followed your article on how to load bitmap files manually (as i don't want to use glaux etc), but i get strange results: www.vexator.net/argh.jpg
any idea why?

FILE *fp = fopen(filename, "rb");

unsigned short uint;
unsigned int dword;
unsigned short word;
long llong;

fread(&uint, sizeof(uint), 1, fp);
fread(&dword, sizeof(dword), 1, fp);
fread(&uint, sizeof(uint), 1, fp);
fread(&uint, sizeof(uint), 1, fp);
fread(&dword, sizeof(dword), 1, fp);
fread(&dword, sizeof(dword), 1, fp);

long width, height;
fread(&width, sizeof(long), 1, fp);
fread(&height, sizeof(long), 1, fp);

fread(&word, sizeof(word), 1, fp);

unsigned short bitcount;
fread(&bitcount, sizeof(unsigned short), 1, fp);

unsigned long compression;
fread(&compression, sizeof(unsigned long), 1, fp);

fread(&dword, sizeof(dword), 1, fp);
fread(&llong, sizeof(long), 1, fp);
fread(&llong, sizeof(long), 1, fp);
fread(&dword, sizeof(dword), 1, fp);
fread(&dword, sizeof(dword), 1, fp);

unsigned char *imagedata;
imagedata = new unsigned char[width * height * 4];

for(int x=0; x < width; x++)
{
    for(int y=0; y < height; y++)
    {
        fread(&imagedata[(x * height + y)*4+0], sizeof(char), 1, fp);
        fread(&imagedata[(x * height + y)*4+1], sizeof(char), 1, fp);

        fread(&imagedata[(x * height + y)*4+2], sizeof(char), 1, fp);

        int r = imagedata[(x * height + y)*4+2];
        int b = imagedata[(x * height + y)*4+0];
        imagedata[(x * height + y)*4+0] = r;
        imagedata[(x * height + y)*4+2] = b;

        if(imagedata[(x * height + y)*4+0] == 255 && imagedata[(x * height + y)*4+1] == 0 && imagedata[(x * height + y)*4+2] == 255)
            imagedata[(x * height + y)*4+3] = 0;
        else
            imagedata[(x * height + y)*4+3] = 255;
    }
}
        
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_BGR, GL_UNSIGNED_BYTE, imagedata );
        
delete[] imagedata;