Advertisement

Yet Another Newbie Texture Problem

Started by November 25, 2002 02:20 PM
8 comments, last by Eibwen 22 years, 3 months ago
ok my texture class is finaly working and it isnt loading single coloured textures but now i have another problem when I load multiple textures. The last texture i load is the only one working... I''m loading the texture with the following code: SDL_Surface* texImage; if( ( texImage = SDL_LoadBMP(filename) ) ) { /* Create The Texture */ glGenTextures( 1, &ID[0] ); /* Typical Texture Generation Using Data From The Bitmap */ glBindTexture(GL_TEXTURE_2D, ID[0]); /* Generate The Texture */ glTexImage2D( GL_TEXTURE_2D, 0, 3, texImage->w, texImage->h, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, texImage->pixels ); SDL_FreeSurface(texImage); } and i have a cube(dice) with 6 diffrent textures. then i call for every side of the dice: glBegin(GL_QUADS); glBindTexture(GL_TEXTURE_2D, texid); glTexCoordf(..) ; glVertex3f(...); . . glEnd(); and this just shows one side of the dice with a texture and the others are white Thanks for your help Eibwen
note the lines with ID[0] in them. don''t these look just a little bit fishy?

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Advertisement
aye

i changed it now to a GLuint ID (from GLuint[1]);
but still same effect
ok, I''ll be more specific: the texture loading code you''re using is run every time you load a texture. Right? Now imagine loading your texture into the same address space (well, really only reusing the identifier for it) over and over again. It doesn''t matter what identifier you''re using as long as it''s the same one every one you call the function. It''s like having to feed six dogs, but everytime you finish feeding the next one, you start feeding the first one. Think about it - it''s a paradox - how many dogs will have been fed after you''ve served six doggie meals...

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Actually, the problem is that (afaik) you can''t do bind texture inside glBegin()

(assuming i''m right) does anyone actually know opengl here? >;-)
C-Junkie is absolutely correct. According to the Red Book (1.2) the only OpenGL calls that are valid within a glBegin()/glEnd() pair are:

glVertex*()
glColor*()
glIndex*()
glNormal*()
glTexCoord*()
glMultiTexCoord*ARB()
glEdgeFlag*()
glMaterial*()
glArrayElement()
glEvalCoord*()
glEvalPoint*()
glCallList()
glCallLists()

Enigma
Advertisement
ok

my glBindTexture(..) is outside of the glBegin() glEnd() block
still the same effect.

i load 3 textures in my init function

g_tex1.loadTexture("stone.bmp");
g_tex2.loadTexture("metal.bmp");
g_tex3.loadTexture("green.bmp");

if i load the textures in this order everything with a green.bmp texture renders fine - other QUADS are white

now i saw g_tex1 with g_tex3:

g_tex3.loadTexture("green.bmp");
g_tex2.loadTexture("metal.bmp");
g_tex1.loadTexture("stone.bmp");

now everything with the stone.bmp texture renders fine and the others are white again.

so i still think it has something to do with my load texture function i pasted in one of the previous posts

Thanks for your help
Eibwen

[edited by - Eibwen on November 27, 2002 4:40:48 AM]
ok..
I''ll just go over texture loading just so you can make absolutly sure (I''m not trying to patronize, so if I sound a bit mean or whatnot just say)

when you load a texture, openGL gives it an integer id... ie, the first to load might be 1, then 2, then 3, etc...

when you call:
glGenTextures( 1, &ID[0] );

the reason it needs a pointer is because it fills that value with the id you need to use to view the texture..

here, it appears your passing in a pointer to the same value every single time...
that would mean, when you create your first texture ID[0] will be set to, say, 1, but then if you create a second, it may be set to 2.. over writing the id of the first texture...

if ID is a member of a texture class, thats fine, but if it''s global, then you have a big problem.

also,
the call
glBindTexture(GL_TEXTURE_2D, texid);

texid is the id that the genTextures call gave you... ie, ID[0]... which will always be the same value, hence you only ever see the last texture you bound...


other than that the only issue I could see is you are switching between texture with and without generated mipmaps... and always setting the filter mode to that of the last texture (this is very unlikly though)....

| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |
yay thanks a lot riptorn

you were right about the mipmap
im new to opengl so i dont know a lot about it yet..
i thought you have to call the glTexParameteri once and it sets this for all Textures but you have to call it for all textures you load.

Thanks for your help

Eibwen

I''m having a similiar problem also.

"A programmer being told to ''''go to'''' hell sees the ''''go to'''' part of the sentence as the bad part."
"A programmer being told to ''go to'' hell sees the ''go to'' part of the sentence as the bad part."

This topic is closed to new replies.

Advertisement