Results 1 to 4 of 4

Thread: Loading A Bitmap

  1. #1
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Loading A Bitmap

    Is there a tutorial or a simple way to load a bitmap from file and stretch it to fit the window size.

    - VC6-OGL

  2. #2
    Member Contributor
    Join Date
    Nov 2002
    Location
    Oirsbeek,Holland
    Posts
    69

    Re: Loading A Bitmap

    loading as a texture could be :
    AUX_RGBImageRec *Pic1 auxDibImageLoad("dir");
    glGenTextures(1,&TextureBin[0]);
    glBindTexture(GL_TEXTURE_2D,TextureBin[0]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
    (GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

    glTexImage2D(GL_TEXTURE_2D,0,3,Pic1->sizeX,Pic1->sizeY,0,GL_UNSIGNED_BYTE,GL_RGB,Pic1->data);
    free(pic1->data);
    free(pic1);

    and to fit it use glOrtho and by glVertex2f draw GL_SQUAD ever hole window and put texture on it.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Re: Loading A Bitmap

    Thanx!!!

  4. #4
    Member Contributor
    Join Date
    Oct 2002
    Posts
    54

    Re: Loading A Bitmap

    Real men write their own loaders!

    Code :
    void LoadTexture( unsigned int texture, char *filename )
    {
    #define getLEushort(t)  temp = (unsigned char*)(&(t)); temp[0] = getc(infile); temp[1] = getc(infile);
    #define getLEuint(t)    temp = (unsigned char*)(&(t)); temp[0] = getc(infile); temp[1] = getc(infile); temp[2] = getc(infile); temp[3] = getc(infile);
      unsigned int i, row, numrows, numcols;
      unsigned short bitsperpix;
      FILE *infile = NULL;
      unsigned char *temp, *data;
     
      infile = fopen( filename, "rb" );
      if (!infile) {
        printf( "error opening file" ); exit( 0 ); }
      for (i=0; i<18; i++)
        getc( infile );
      getLEuint( numcols );
      getLEuint( numrows );
      getc( infile ); getc( infile );
      getLEushort( bitsperpix );
      for (i=0; i<24; i++)
        getc( infile );
      if (bitsperpix != 24) {
        printf( "Not a 24 bit image." ); exit( 0 ); }
      data = new unsigned char[numrows * numcols * 3];
      if (!data) {
        printf( "could not alloc enough mem" ); exit( 0 ); }
      for (row=0; row < numrows; row++) {
        for (i=0; i < numcols; i++) {
          data[(row*numcols+i)*3+2] = getc( infile ); // b
          data[(row*numcols+i)*3+1] = getc( infile ); // g
          data[(row*numcols+i)*3] = getc( infile ); } // r
        for (i=0; i < (((3 * numcols + 3) / 4) * 4) - 3 * numcols; i++)
          getc( infile ); }
      if (numrows == 1) {
        glBindTexture( GL_TEXTURE_1D, texture );
        glTexImage1D( GL_TEXTURE_1D, 0, 3, numcols, 0, GL_RGB, GL_UNSIGNED_BYTE, data );
        glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
        glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
      } else {
        glBindTexture( GL_TEXTURE_2D, texture );
        glTexImage2D( GL_TEXTURE_2D, 0, 3, numcols, numrows, 0, GL_RGB, GL_UNSIGNED_BYTE, data );
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); }
      delete [] data;
      fclose( infile );
    }

Similar Threads

  1. Problems loading a bitmap
    By BrandonLP in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 10-27-2006, 03:40 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. Bitmap loading problem.
    By zenon in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-23-2003, 09:21 AM
  5. Loading bitmap formats
    By EPHERE in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-12-2002, 09:11 AM

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