BMP Loading Questions, More OpenGL!!! :D

This is a discussion on BMP Loading Questions, More OpenGL!!! :D within the Game Programming forums, part of the General Programming Boards category; Code: int LoadGLTextures() // Load Bitmaps And Convert To Textures { int Status=FALSE; // Status Indicator AUX_RGBImageRec *TextureImage[2]; // Create ...

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

    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.

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    here's a good book on OpenGL, and its free to download too. Covers your question(s).

    http://www.opengl.org/documentation/...1.0/index.html
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Thanks

    You must believe me I'm not asking anyone to do work for me, I have been studying this topic for a week

  4. #4
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    [EDIT]"no-one" posted while I was typing. i'll leave this here anyway though.

    your code generates 1 texture, because your only loading 1 texture. if you were loading 3 textures, you would generate 3 textures.
    My JPEG loading code (still applies):
    Code:
    void CreateTexture(UINT textureArray[], LPSTR strFileName, int textureID)
    {
    	if(!strFileName)									
    		return;
    	
    	tImageJPG *pImage = LoadJPG(strFileName);			
    
    
    	if(pImage == NULL)									
    		exit(0);
    	
    	glGenTextures(1, &textureArray[textureID]);
    	
    	glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
    	
    	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, pImage->sizeX, pImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pImage->data);
    	
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
    	
    	if (pImage)										
    	{
    		if (pImage->data)							
    		{
    			free(pImage->data);						
    		}
    
    		free(pImage);								
    	}
    }
    This code generates and loads 1 texture at a time. the texture is determined by the texture ID. your code is loading a hard-coded texture ID, so in your case, you would need to generate more than 1 to allow for more textureIDs.
    If you don't understand what I'm trying to say, just give another post, and i'll try and elabourate a little more.

    -psychopath
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  5. #5
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Lesse, since I'm implementing the texture in my program more than once, I should load it as much as I'm using it?

    I have a Cube, 6 sides, 3 sides are the NeHe1.bmp (one i modified), and the other 3 are NeHe.bmp

    Instead of generating 1 texture for each individual texture I should generate 3 because I'm using that many?

    OR

    I should use glGenTexture() ONCE for each Texture, not for as many times as I wish to implement it on my cube
    Last edited by Shamino; 05-07-2005 at 09:23 PM.

  6. #6
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    one Texture ID per texture. not per use.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  7. #7
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    So my code is pretty much as optimized as it can be for pregenerating textures before the program actually starts, cool...


    Question, what happens when I have 100 textures in my program, will this process still be as efficient?

  8. #8
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    however you go about it, you're still loading 100 textures, so no, I don't think it really matters, and it will have the same efficiency.

    -psychopath
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  9. #9
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Ah, I found out why you would generate more than one texture per texture ID...

    So you can add mip mapping, and other texture settings like that

  10. #10
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Another Question, also if I have 100 different textures, is there any way to organize them into a specific file, and load them all at once?

  11. #11
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    You'd either have to make your own file format and loader or find some API to do that for you.

  12. #12
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Oh I see, like alot of games have a .pak file

    For instance

    textures.pak
    sound.pak
    map.pak

    I see.. I'll have to learn that one on my own i guess

  13. #13
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    I believe a lot of them are just implementations of zip compression with a different filename. I know the warcraft 3 files you can open in winrar after renaming them.

  14. #14
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You could check out ZLIB.

    http://www.gzip.org/zlib/
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

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, 11:03 AM
  4. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 04:16 PM
  5. MISC questions about OpenGL
    By Silvercord in forum Game Programming
    Replies: 12
    Last Post: 01-25-2003, 03:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21