Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Loading bitmap manually

  1. #1
    Newbie Newbie
    Join Date
    Dec 2012
    Posts
    1

    Loading bitmap manually

    Hi
    im developing a personal minilib, and im trying to load and draw a sprite bitmap, i already searched on google...but not worked.
    im want to use ONLY opengl(gl/gl.h) without libs like glu,glaux,etc...

    can someone help me?

    my code:

    Code :
    GLuint loadBMP_custom(const char * imagepath)
    {
    unsigned char header[54];
    unsigned int dataPos;
    unsigned int width, height;
    unsigned int imageSize;
    unsigned char * data;
    FILE * file = fopen(imagepath,"rb");
    if (!file){MessageBoxA(0,"FALHA AO ABRIR A MERDA","",MB_OK); return 0;}
    if ( fread(header, 1, 54, file)!=54 ){ // If not 54 bytes read : problem
        MessageBoxA(0,"Arquivo Incorreto","",MB_OK);
        return false;
    }
    if ( header[0]!='B' || header[1]!='M' ){
        MessageBoxA(0,"Incorreto","",MB_OK);
        return 0;
    }
    dataPos    = *(int*)&(header[0x0A]);
    imageSize  = *(int*)&(header[0x22]);
    width      = *(int*)&(header[0x12]);
    height     = *(int*)&(header[0x16]);
    if (imageSize==0)    imageSize=width*height*3;
    if (dataPos==0)      dataPos=54;
    data = new unsigned char [imageSize];
    fread(data,1,imageSize,file);
    fclose(file);
    GLuint textureID;
    glGenTextures(1, &textureID);
    glBindTexture(GL_TEXTURE_2D, textureID);
     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
    	glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, width,height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, data);
     
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    return(textureID);
    }

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,109
    You need to ask a specific question not "please write some of the code"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •