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


BMP Loading by MystikIce
1
 
unsigned char* GLIMG::loadBmp(const char *fileName)
{
    FILE *filePtr;
    BITMAPFILEHEADER bHeader;
    BITMAPINFOHEADER bInfoHeader;

    if(!fileName)
        return NULL;
    if(!(filePtr = fopen(fileName, "rb")))
        return NULL;

    fread(&bHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
    fread(&bInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
    if(bInfoHeader.biBitCount < 24)
        return NULL;
    if(bInfoHeader.biHeight == 128)
        MessageBox(NULL, "128", NULL, MB_OK);
    if(bInfoHeader.biWidth == 128)
        MessageBox(NULL, "128", NULL, MB_OK);

    DWORD imageSize = bHeader.bfSize - bHeader.bfOffBits;

    pImageData = new unsigned char[imageSize];

    if(pImageData){
        fread(pImageData, 1, imageSize, filePtr);
        fclose(filePtr);
        return pImageData;
    }
    return NULL;
}

//This code is called before above:

GLuint texture[1];
    glGenTextures(1, &texture[0]);    
    glBindTexture(GL_TEXTURE_2D, texture[0]); 
    pSandTexture = glImg->loadBmp("C:\\Work\\My Projects\\OpenGl_Terrain_Engine\\sandTex.bmp");
    if(!pSandTexture)
        MessageBox(NULL, "Could Not Load File", NULL, MB_OK);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_RGB, GL_BITMAP, pSandTexture);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);