generating textures

hi, i am trying to generate 3 textures from 1 tga image i have loaded. i know the tga image loads fine because if i generate just 1 texture it works fine. The problem is when i try to generate more than 1 from the same image. here is my texture generating code…

int LoadGLTextures() // Load Bitmaps And Convert To Textures
int Status = false; // Status Indicator

// Load The Bitmap, Check For Errors.
if (LoadTGA(&texture[0], "test.tga"))

	Status = true;
	glGenTextures(3, &texture[0].texID);					// Create Three Textures

	// Create Nearest Filtered Texture
	glBindTexture(GL_TEXTURE_2D, texture[0].texID);
	glTexImage2D(GL_TEXTURE_2D, 0, 3, texture[0].width, texture[0].height, 0, texture[0].type, GL_UNSIGNED_BYTE, texture[0].imageData);

	// Create Linear Filtered Texture
	glBindTexture(GL_TEXTURE_2D, texture[1].texID);
	glTexImage2D(GL_TEXTURE_2D, 0, 3, texture[0].width, texture[0].height, 0, texture[0].type, GL_UNSIGNED_BYTE, texture[0].imageData);

	// Create MipMapped Texture
	glBindTexture(GL_TEXTURE_2D, texture[2].texID);		
	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, texture[0].width, texture[0].height,texture[0].type, GL_UNSIGNED_BYTE, texture[0].imageData);// ( NEW )	

if (texture[0].imageData)					// If Texture Image Exists
		free(texture[0].imageData);				// Free The Texture Image Memory

return Status;

whenever there is 3 in the glGenTexture it displays the pure white texture, however if i change the 3 to a 1 i get 2 textures and one white one! can someone please help me???

my tga loader is from lesson 33 at nehe.


I could be mistaken but…

glGenTextures(3, &texture[0].texID);

I believe this is actually four textures 0,1,2 and 3. So, by changing the 3 to 1 you are getting textures at 0 and 1, with your 3rd texture not being placed into 2.

That’s the most I can figure from your code.
Let me know if I am wrong.

well what i have found is that if i load the same tga file 3 times, that everything works out ok. So i’m not sure if its my loading routine or maybe something to do with the texture array not being setup properly or something, but loading the texture 3 times will have to do now i guess, unless someone else knows something?

Originally posted by werdy666:
glGenTextures(3, &texture[0].texID);

This will put three texture names into the memory area pointed to. That is not what you want, since your texture variable is a struct containing more fields. Either call the glGenTextures three times for texture[0] through [2] or call it with a temporary GLint array and copy the texture names into the texture struct.

Effectively your second ant third texture structs currently contain invalid texture names, so the textures display as pure white when used.