Results 1 to 7 of 7

Thread: Loading Images Faster

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2009
    Posts
    5

    Loading Images Faster

    Hi,
    I am trying to load three photos at the same time in a window. Two of the photos are changing at each loop and one photo is just a logo. The program is running very slow. Any ideas what I should be doing in the program differently? Thanks in advance. Here is how I am loading photos:
    Code :
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, textures[0]);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity();
    glPushMatrix();
    glBegin(GL_QUADS);// Just create a simple square
    glTexCoord2f ...
    glVertex2d ...
    . 
    .
    glEnd();
    glPopMatrix();

    Then I run this subroutine:
    Code :
    bool loadbmp(UINT textureArray[], LPSTR strFileName, int ID)//(NEW) the name of our function
    {
     if(!strFileName)   return false;//If no file name was given then return a false value
     
        AUX_RGBImageRec *pBitMap = auxDIBImageLoad(strFileName); //Load the file into a new variable where we can then manipulate it into our texture array
     if(pBitMap == NULL)    exit(0);// If no data was loaded then exit the program.
     
    glGenTextures(1, &textureArray[ID]);// Generate one texture into our texture array in the slot defined
    glBindTexture(GL_TEXTURE_2D, textureArray[ID]);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0,3,pBitMap->sizeX, pBitMap->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, pBitMap->data);
     
     
        if (pBitMap)    //If pBitMap still has a value then we want to clear it.                                    
        {
            if (pBitMap->data)                                
            {
                free(pBitMap->data);                        
            }
            free(pBitMap);                                    
        }
        return true;
    }
    Then I run:
    Code :
    glDisable(GL_TEXTURE_2D);
    //Anf finally i do this:
    glutSwapBuffers();

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Loading Images Faster

    Not clear from you snippets, but loadbmp() should be called only 1 time for each different texture, and not at each frame !

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2009
    Posts
    5

    Re: Loading Images Faster

    Sorry, I am a bit new to this. but could you explain more. I am calling loadbmp() for each new image that i am going to load including the logo. which lines should I use for each new image and which ones should I use only once?

  4. #4
    Member Newbie
    Join Date
    Apr 2006
    Posts
    41

    Re: Loading Images Faster

    have you considered using an image library like DevIL?

    i think it comes with some samples on how to upload image data to the GL.

    otherwise you could look at the sample code in the redbook, it's available from the menu at the top of the page.

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2009
    Posts
    5

    Re: Loading Images Faster

    I am using all off the above code in each loop. which lines should not be called for each different image?

    I had a look at the DevIL and I could not get it to work.

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2009
    Posts
    5

    Re: Loading Images Faster

    Solved my problem, just followed the instruction from this Tutorial.
    http://www.swiftless.com/tutorials/o...eneration.html


    To do this all we need is this line in our LoadTexture function:
    Code :
     gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );
     Instead of the line:
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
    The 'data' being the texture, the width and height being the width and height
    of the texture file.

    Then you just bind it like you would a normal texture.

    But because we are now using mipmaps, we also want to change:
    Code :
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
     To
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );

  7. #7
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: Loading Images Faster

    By the way - don't use glGenTexture for each texture you load. This way you will keep filling up memeory on GPU since you do not call glDeleteTextures anywhere.

    If you use only 3 textures at once, then simply use glGenTextures once to create them and from now on you will only need to replace images for these textures.

Similar Threads

  1. loading tga images
    By Riuzaki90 in forum OpenGL: Linux
    Replies: 2
    Last Post: 02-18-2012, 10:12 AM
  2. loading glsl programs faster
    By zed in forum OpenGL: GLSL
    Replies: 6
    Last Post: 04-30-2005, 02:26 PM
  3. Replies: 8
    Last Post: 12-01-2003, 08:35 AM
  4. loading images please help
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-07-2002, 02:49 AM
  5. Loading Images
    By Sajjad in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-20-2001, 01:36 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