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,117
    You need to ask a specific question not "please write some of the code"

Similar Threads

  1. Loading an RGB bitmap with alpha?
    By PrestoChung in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-19-2011, 09:33 PM
  2. Loading bitmap in C
    By Andrew Davey in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-17-2004, 01:35 AM
  3. loading .TGA and bitmap
    By kashif saeed in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-11-2003, 08:59 AM
  4. Loading A Bitmap
    By Stack Overflow in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-10-2002, 02:04 PM
  5. Manually loading GL DLL
    By BwB in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 12-30-2000, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean