Thread: Help me Understand (OpenGL Question)

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

    Help me Understand (OpenGL Question)

    Code:
    int LoadGLTextures()									// Load Bitmaps And Convert To Textures
    {
    	int Status=FALSE;									// Status Indicator
    
    	AUX_RGBImageRec *TextureImage[1];					// 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
    	}
    
    	return Status;										// Return The Status
    }
    I Know it has something to do with freeing memory up memory for the specific texture, but I don't know exactly how it works step by step, its something I've been looking at for 3 days now, can't seem to catch it :\

    Code:
    // 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
    I think, this takes the iArray textureimage[0] and sets it equal to the bitmap "Data/NeHe.bmp", then sets the Status bool to TRUE, which ultimately means the texture was successfully loaded....

    Right?

    Oh I see, TextureImage is declared as a pointer to the memory store for texture[1]!!! So Every time they refer to TextureImage theyre referring to the bmp I have it set to... Genius! programming is so Genius! (Note to all, Still don't understand most of it)
    Last edited by Shamino; 05-06-2005 at 05:51 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM