Thread: BMP Loading Questions, More OpenGL!!! :D

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    BMP Loading Questions, More OpenGL!!! :D

    Code:
    int LoadGLTextures()									// Load Bitmaps And Convert To Textures
    {
    	int Status=FALSE;									// Status Indicator
    
    	AUX_RGBImageRec *TextureImage[2];					// Create Storage Space For The Texture
    
    	memset(TextureImage,0,sizeof(void *)*1);           	// Set The Pointer To NULL
    
    	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
    	if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))
    	{
    
    		Status=TRUE;									// Set The Status To TRUE
    
    		glGenTextures(1, &texture[0]);					// Create The Texture
    
    		// Typical Texture Generation Using Data From The Bitmap
    		glBindTexture(GL_TEXTURE_2D, texture[0]);
    		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    	}
    
    
    	if (TextureImage[0])									// If Texture Exists
    	{
    		if (TextureImage[0]->data)							// If Texture Image Exists
    		{
    			free(TextureImage[0]->data);					// Free The Texture Image Memory
    		}
    
    		free(TextureImage[0]);								// Free The Image Structure
    	}
    
    	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
    	if (TextureImage[1]=LoadBMP("Data/NeHe1.bmp"))
    	{
    
    		Status=TRUE;									// Set The Status To TRUE
    
    		glGenTextures(1, &texture[1]);					// Create The Texture
    
    		// Typical Texture Generation Using Data From The Bitmap
    		glBindTexture(GL_TEXTURE_2D, texture[1]);
    		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    	}
    
    
    	if (TextureImage[1])									// If Texture Exists
    	{
    		if (TextureImage[1]->data)							// If Texture Image Exists
    		{
    			free(TextureImage[1]->data);					// Free The Texture Image Memory
    		}
    
    		free(TextureImage[1]);								// Free The Image Structure
    	}
    
    	return Status;										// Return The Status
    }
    Now you see, this code is cool and all, and it loads my textures, but........ Why would I need to modify the glGenTextures() function to generate more than 1 texture at a time....

    Do I need to do this to allocate memory for each time I use this texture? Say 3 sides of my cube are one texture, and the other 3 are some other texture, do I need to generate 3 textures (for better memory allocation) Or is it save generating one texture for unlimited usage of the texture....
    Last edited by Shamino; 05-07-2005 at 07:27 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGl questions
    By Shadowwoelf in forum Windows Programming
    Replies: 4
    Last Post: 06-20-2007, 05:35 PM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. Loading an image into memory using OpenGL
    By Kaelin in forum C++ Programming
    Replies: 3
    Last Post: 02-08-2005, 12:03 PM
  4. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 05:16 PM
  5. MISC questions about OpenGL
    By Silvercord in forum Game Programming
    Replies: 12
    Last Post: 01-25-2003, 04:20 PM