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 4 of 4

Thread: Loading A Bitmap

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

    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
    Intern 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
    Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    265

    Re: Loading A Bitmap

    Thanx!!!

  4. #4
    Intern Contributor
    Join Date
    Oct 2002
    Posts
    56

    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 );
    }

Posting Permissions

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