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:


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:


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:


glDisable(GL_TEXTURE_2D);
//Anf finally i do this:
glutSwapBuffers();

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

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?

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.

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.

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

To do this all we need is this line in our LoadTexture function:

 
 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:


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

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.