Multiple Texture Loading Problem

Started by
4 comments, last by luridcortex 20 years, 4 months ago
Im modifying the texturemapping tutorial to load multiple textures. What i did was create an array of strings for the bitmap filenames, wrap a for loop around the code block that actually creates and binds the textures:

for(int x=0; x<7; x++)
	{
		if (TextureImage[x]=LoadBMP(texFile[x]))
		{
			Status=TRUE;									// Set The Status To TRUE

			glGenTextures(1, &texture[x]);					// Create The Texture

			// Typical Texture Generation Using Data From The Bitmap
			glBindTexture(GL_TEXTURE_2D, texture[x]);
			glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[x]->sizeX, TextureImage[x]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[x]->data);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		}
	}
 
what i get is the following assertion failure in fopen.c: Expression: *file != _T("\0") So im guessing this might be a problem with my string array, something to do with a null terminator but i cant seem to pinpoint the exact problem. another thing, even though there is an assertion error the app will still run with all the textures loaded.
Advertisement
Take a look near the top of lesson 17:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=17

In that tutorial he loads 2 images.


the only diffrences if i'm not missing any are.

from vars at the top:
GLuint	texture[2];    // Storage For Our Font Textureand then this function below changes:   int LoadGLTextures()								// Load Bitmaps And Convert To Textures{	int Status=FALSE;							// Status Indicator	AUX_RGBImageRec *TextureImage[2];					// Create Storage Space For The Textures	memset(TextureImage,0,sizeof(void *)*2);				// Set The Pointer To NULL	if ((TextureImage[0]=LoadBMP("Data/Font.bmp")) &&			// Load The Font Bitmap		(TextureImage[1]=LoadBMP("Data/Bumps.bmp")))			// Load The Texture Bitmap	{		Status=TRUE;				glGenTextures(2, &texture[0]);					// Create Two Texture		for (loop=0; loop<2; loop++)					// Loop Through All The Textures		{			// Build All The Textures			glBindTexture(GL_TEXTURE_2D, texture[loop]);			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);			glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);		}	}	for (loop=0; loop<2; loop++)		{	        if (TextureImage[loop])						// If Texture Exists			{				if (TextureImage[loop]->data)			// If Texture Image Exists				{					free(TextureImage[loop]->data);		// Free The Texture Image Memory				}				free(TextureImage[loop]);			// Free The Image Structure			}		}	return Status;								// Return The Status}


hopefully i didn't copy and paste anything wrong. Check out lesson 17 if you are confused.

Notice all the places with the number 2 are the ammount of images you are loading. So edit that number to the ammount you want.

[edited by - ssnhavok on November 17, 2003 7:15:08 PM]
yeah, i see what he is doing with his code there. however, im doing it a bit different to make loading lots of textures easier.

Also, since its an assert error i dont get any errors in the release build, id just like to know what the assert error is all about.. heres my routine:

/****TEXTURE LOADING DATA MEMBERS****/const int MaxTextures = 8;	 char texFile[MaxTextures][30] = {"data/plant_001.bmp", 				 "data/plant_002.bmp", 				 "data/plant_003.bmp", 				 "data/plant_004.bmp", 				 "data/plant_005.bmp",				 "data/plant_006.bmp",				 "data/plant_007.bmp",				 "data/plant_008.bmp"};GLuint	texture[MaxTextures];	// Storage for Texures/****TEXTURE LOADING FUNCTIONS****/AUX_RGBImageRec *LoadBMP(char *Filename)				// Loads A Bitmap Image{	FILE *File=NULL;	// File Handle									if (!Filename)		// Make Sure A Filename Was Given									{		return NULL;	// If Not Return NULL									}	File=fopen(Filename,"r");	// Check To See If The File Exists							if (File)	// Does The File Exist?											{		fclose(File);		// Close The Handle									// Load The Bitmap And Return A Pointer                return auxDIBImageLoad(Filename);					}	return NULL;	// If Load Failed Return NULL								}int LoadGLTextures()									// Load Bitmaps And Convert To Textures{	int Status=FALSE;	// Status Indicator									AUX_RGBImageRec *TextureImage[MaxTextures]; // 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	for(int x=0; x < MaxTextures; x++)	{		if (TextureImage[x]=LoadBMP(texFile[x]))		{			Status=TRUE;	// Set The Status To TRUE											// Create The Texture                        glGenTextures(1, &texture[x]);								// Typical Texture Generation Using Data From The Bitmap			glBindTexture(GL_TEXTURE_2D, texture[x]);			glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[x]->sizeX, TextureImage[x]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[x]->data);			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);		}	}	for(int x=0; x<7; x++)	{		if (TextureImage[x])									// If Texture Exists		{			if (TextureImage[x]->data)							// If Texture Image Exists			{				free(TextureImage[x]->data);					// Free The Texture Image Memory			}			free(TextureImage[x]);								// Free The Image Structure		}	}	return Status;										// Return The Status}


[edited by - luridcortex on November 17, 2003 10:46:22 PM]

[edited by - luridcortex on November 17, 2003 10:47:47 PM]
Hi,

Try changing memset code to
memset(TextureImage,0,sizeof(void *) * MAX_TEXTURES);

Secondly I would advise you to write your own image loader routine instead of AUX.


The more applications I write, more I find out how less I know
Yeah, id love to write my own bitmap and texture loader. just dont know quite where to begin :\

know of any good resources?
Try using this library!

http://openil.sourceforge.net/

It has same Syntax as OpenGL and handles texture conversion for you too!

--------------------------------------------------------

"If it looks good, it is good computer graphics"
"If it looks like computer graphics, it is bad computer graphics"

Corrail
corrail@gmx.at
ICQ#59184081
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...

This topic is closed to new replies.

Advertisement