Archived

This topic is now archived and is closed to further replies.

_Z

Probles with loading multiple TGAs

Recommended Posts

The probles is: I have a function which loads a TGA according to path given, the TGA is loaded to quad structure, which contains a GLuint var[1]...so there are multiple files, multiple quad structures. The problem is that all quads become one texture...why? The source is actually modified NeHe''s lesson10...I put it up at www.kivilinn.tartu.ee/z...Plz help me!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you are using nehe''s code, my guess is that you probably have a fixed array to hold, and define texture data.
You should have a texture[n] array, not texture[0] in LoadGLTextures..
Load all the textures to this array, but not to the same fixed place.

Bruno

Share this post


Link to post
Share on other sites
The problem isn''t in holding space (I suppose)...every quad holds its own texture in GLunit tex[1] (the structure is simple and looks like this:
typedef struct
{
tipp tipp[4]; //these are 4 vertices (each one x, y, z, u, v)
GLuint tex[1]; //this is the place to hold the texture
}quad;
).
The problem is like this:
Assume that we have two quads. Both of them have different textures, but both look like the second (assume its texture is red, and both are red) WHY???
The code is located at www.kivilinn.tartu.ee/z

(it is less than 100kb

Share this post


Link to post
Share on other sites
The problem isn''t in holding space (I suppose)...every quad holds its own texture in GLunit tex[1] (the structure is simple and looks like this:
typedef struct
{
tipp tipp[4]; //these are 4 vertices (each one x, y, z, u, v)
GLuint tex[1]; //this is the place to hold the texture
}quad;
).
The problem is like this:
Assume that we have two quads. Both of them have different textures, but both look like the second (assume its texture is red, and both are red) WHY???
The code is located at www.kivilinn.tartu.ee/z

(it is less than 100kb

Share this post


Link to post
Share on other sites
Hi

I gave a quick look at your code, and i have to say it''s a big mess

I found two bugs, first you cannot inside a glBegin() glEnd(), Bind textures.
In the SetupWorld function when you start building the display list, you have a glBegin(GL_QUADS) glEnd(), and immediatly after that, you are disabling texture usage, and also binding a texture.
Remove them from there, and place them somewhere else outside the glbegin/glend, and it should work.

hope this fixes your problem,

Bruno

Share this post


Link to post
Share on other sites
I didn't check your code but I am putting up my version of the Nehe example that I modified for my Map Engine. Note, I didn't put the complete function but the part that I put should help you find your problem.

make sure that somewhere in your Init() function you have:

glEnable( GL_TEXTURE_2D );


    
AUX_RGBImageRec *TextureImage[ NUM_TEXTURE ];

memset( TextureImage, 0, sizeof( void * ) * 1 );

for ( int index = 0; index < NUM_TEXTURE; index++ )
{
TextureImage[ index ] = LoadBMP( tileFileNames[ index ] );

if ( TextureImage[ index ] == NULL )
{
PostQuitMessage( 0 );
return( 0 );
}

}

// &texture[ 0 ]

glGenTextures( NUM_TEXTURE, &texture[ 0 ] ); // We are generating four textures


for ( int index = 0; index < NUM_TEXTURE; index++ )
{
glBindTexture( GL_TEXTURE_2D, texture[ index ] );
glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR ); // Linear Filtering

glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR ); // Linear Filtering

glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage[ index ]->sizeX,
TextureImage[ index ]->sizeY, 0, GL_RGB,
GL_UNSIGNED_BYTE, TextureImage[ index ]->data );
}



Now, this loads 4 textures into a GLint texture[4] array and it works fine when I blit the map to the screen so it should work for you also...

Hope it does....

NB: some of the comments my not say the correct thing as I didn't change them when I built the map engine...

"And that's the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP's Invasive Production Activation Technology!

Edited by - cyberdrek on April 25, 2001 11:07:30 AM

Share this post


Link to post
Share on other sites
About mess you''re absolutely right. It really is messy.
I tried your suggestions, well that didn''t do. All four quads are still one color (texture). How can I place different textures on different objects?

Share this post


Link to post
Share on other sites
CYBERDREK:
Actually I do the same, load different textures into places they belong (into different quad structs). You do it with one array. But how can I make so that different objects wear different textures, how does the texturing system actually work?

Share this post


Link to post
Share on other sites
Cyberdrek:
I remade my code as you suggested...nothing...all quads wear the last loaded texture. Why, I don''t know..

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Code is up at:
www.kivilinn.tartu.ee/z/Pack.zip

Share this post


Link to post
Share on other sites
NO HELP NEEDED (for this time) ANYMORE...thks to everyone, who tried to help me I found the bug....everything was simple:
when drawing the glbegin and glend were called 1 time each...this is why one texture was applied to all quads...

Share this post


Link to post
Share on other sites