TGA texture woes
I looked around at the TGA posts on here but can''t find a solution to my problem, and I know it''s likely a stupid little mistake.
I''m basing my code off of the TGA loader in NeHe''s lesson 25. I''m trying to add support for more than 1 texture to be loaded. Currently he loads just the Font.tga into texture[0]
I want to load another tga into texture[1]
What I''m not clear on is how to choose textures using texID so I just left that the way it is, could that be the problem? Thanks in advance!
glGenTextures(1, &texture[1].texID); // Generate OpenGL texture IDs
glBindTexture(GL_TEXTURE_2D, texture[1].texID); // Bind Our Texture
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtered
if (texture[1].bpp==32) // Was The TGA 32 Bits
{
type=GL_RGBA; // If So Set The ''type'' To GL_RGBA
}
glTexImage2D(GL_TEXTURE_2D, 0, type, texture[1].width, texture[1].height,0, type, GL_UNSIGNED_BYTE, texture[1].imageData);
Well lets say you want to load 5 textures. Then create a texture id array of size 5. GLuint texture[5]. Then in a loop or something load each texture into its own array subscript. So like texture[0] would hold the id for say 'man.tga' and texture[1] would have the id for say 'woman.tga' etc... Oh also remember when you call glGenTextures to set the first parameter to the number of textures your array will hold. So in my example it would be like glGenTextures( 5, texture );
What i like to do is have an array of strings that hold each texture name. And my loop would be something like this:
GLuint texture[5];
glGenTextures( 5, texture );
for( int x = 0; x < numOfTextures; ++x )
{
LoadTexture( texturenames[x], texture[x] );
(any other opengl texture code here if needed)
}
Where texturenames is like this:
char *texturenames[] = { {"name1.tga"},{"name2.tga"} }; and so on. Where i have the 'any other opengl code...' is where i set the glTexParameteri stuff and where i call glTexImage2D and stuff liek that. But you could do that in the load function.
Hope that made sence and or helps some.
-SirKnight
Edited by - SirKnight on September 25, 2001 10:17:13 PM
Edited by - SirKnight on September 25, 2001 10:19:15 PM
What i like to do is have an array of strings that hold each texture name. And my loop would be something like this:
GLuint texture[5];
glGenTextures( 5, texture );
for( int x = 0; x < numOfTextures; ++x )
{
LoadTexture( texturenames[x], texture[x] );
(any other opengl texture code here if needed)
}
Where texturenames is like this:
char *texturenames[] = { {"name1.tga"},{"name2.tga"} }; and so on. Where i have the 'any other opengl code...' is where i set the glTexParameteri stuff and where i call glTexImage2D and stuff liek that. But you could do that in the load function.
Hope that made sence and or helps some.
-SirKnight
Edited by - SirKnight on September 25, 2001 10:17:13 PM
Edited by - SirKnight on September 25, 2001 10:19:15 PM
TY TY TY!
turns out I had glGentextures in my code twice and apparently opengl doesn't like that.
so I had:
glGenTextures( 1, texture[0] );
//load texture routines
glGenTextures( 1, texture[1] );
//load next texture routines
the proper way as you stated being:
glGenTextures( 2, texture[0] );
//load texture routines
works fine now thanks!
Edited by - element2001 on September 26, 2001 2:18:29 AM
turns out I had glGentextures in my code twice and apparently opengl doesn't like that.
so I had:
glGenTextures( 1, texture[0] );
//load texture routines
glGenTextures( 1, texture[1] );
//load next texture routines
the proper way as you stated being:
glGenTextures( 2, texture[0] );
//load texture routines
works fine now thanks!
Edited by - element2001 on September 26, 2001 2:18:29 AM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement