Problem with Texturing...

The problem is : I can’t get it to work at all :\

ok, here it is :
First of all, I do enable 2d textures
glEnable(GL_TEXTURE_2D);

then I start a display list,
and I call
glTexEnvf(GL_TEXTURE_ENV,
GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexImage2D(GL_TEXTURE_2D, 0, 4, 256, 256,
0, GL_RGB, GL_UNSIGNED_CHAR, test);

test is defined as follow :
unsigned char test[2562563];

and does contain correct texture data loaded from a file (I’ve verified and it’s all fine)
the file contains 8-bit RGB data, stored in text-mode hexadecimal, but I convert it to Byte format, and I’ve verified that it works correctly.

then, I do
glBegin(GL_QUADS);

glTexCoord2f(0.0,0.0);
glVertex3f(1,0,0);
glTexCoord2f(1.0,0.0);
glVertex3f(0,0,0);
glTexCoord2f(1.0,1.0);
glVertex3f(0,0,-1);
glTexCoord2f(0.0,1.0);
glVertex3f(1,0,-1);
glEnd();

Results : The square shows fine, but there’s no texture on it.

I’ve tried querying gluGetError before every call to a texture-related function but each time it returned “no error”.

I don’t know what I’m doing wrong.

Texturing everywhere else works fine (in games or apps, but not in my code), so it’s unlikely to be a machine problem.

I don’t use texture binding 'cause I use display lists. I’m working on a 3d geometry file loader that’ll return the display list number. Everything works fine except for texture loading.
(File format : XGL)

You should not compile glTexImage2D into a display list, unless you are 100% sure that’s what you want to do. Uploading a texture is generally something you do once, and not several times (which is understood to be the case if you put it in a display list). Create the texture once, outside the display list.

As for the error; I don’t see where you bind your texture. You should bind it before uploading it, or OpenGL won’t know which texture ID to map the image data to. If you have some other texture bound previously, that texture will be overwritten, casue it’s the last texture bound.

Ok, I’ve revised my code so it now uses Texture Objects.

So, as new global vars, I have
GLuint *texobjects; // which is my array of texture objects “names”
int texindex = 0; // which is used to know which texture to use.

TEXTURE_2D is enabled,
unsigned char test[2562563]; is a temporary global array containing texture data (its data has been verified and is all correct). I use it only to get texture to work. Once it works, I’ll use textures specified in the files I am loading.

Then, I do
glGenTextures(1, &texobjects[texindex]);
(texindex at this moment being 0 )
// ->>[EDIT] Like Mezz said, that should be 3 and BYTE, not 4 and SHORT. changed.

glBindTexture(GL_TEXTURE_2D, texobjects[texindex]); // First call, so texture object is created and ready to accept parameters…
glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, test); // test is that tempo texture data stated earlier.

then I set other tex parameters :
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

Then, I create the display list, bind the texture :
glBindTexture(GL_TEXTURE_2D, texobjects[textures[textureface]]); // textures[textureface] being equal to 0 at that moment, verified.
then I glBegin triangles, set material data, normal data,
and then setting texture coordinates and vertex,
then I call glBindTexture(GL_TEXTURE_2D, 0); to be sure texture binding won’t remain over other geometry.
then I call glEnd(); and glEndList();

And, again, geometry and materials show fine, but no texture’s shown…

I’ve checked if(glIsTexture(texobjects[0])) and that returned TRUE, so, as another test, I manually defined a quad, which used the texture object texobjects[0] that I created earlier. So it goes like this

void Carre111 (void)
{
float c1[3] = {1,0,0};
float c2[3] = {0,0,0};
float c3[3] = {0,0,-1};
float c4[3] = {1,0,-1};

// Checking texobjects[0] to be sure…
if(glIsTexture(texobjects[0]))
{
fprintf(stderr,"Texture 0 ok
");
}
else
{
fprintf(stderr,"Texture 0 bad
");
}
// and that part said “Texture 0 ok”
glBindTexture(GL_TEXTURE_2D, texobjects[0]);

glBegin(GL_QUADS);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,JAUNE);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,NOIR);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,BLANC);
glNormal3f(0,-1,0);
                glTexCoord2f(0.0,0.0);
glVertex3fv(c1);
                glTexCoord2f(1.0,0.0);
glVertex3fv(c2);
                glTexCoord2f(1.0,1.0);
glVertex3fv(c3);
                glTexCoord2f(0.0,1.0);
glVertex3fv(c4);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

}

Then, whenever I call Carre111();, I see that geometry, and… no texture at all :\ I wonder what’s wrong. Even if test[] had erroneous data, at least it’d crash, or load something weird as texture, but it’d show texture.

[This message has been edited by Setzer (edited 07-19-2002).]

[This message has been edited by Setzer (edited 07-19-2002).]

If test is:

unsigned char [2562563]
why do you have ‘4’ as the third parameter in glTexImage2D?

also, the second-from-last parameter is GL_UNSIGNED_SHORT. It should probably be GL_UNSIGNED_BYTE

-Mezz

Originally posted by Mezz:
[b]If test is:

unsigned char [2562563]
why do you have ‘4’ as the third parameter in glTexImage2D?

also, the second-from-last parameter is GL_UNSIGNED_SHORT. It should probably be GL_UNSIGNED_BYTE

-Mezz[/b]

yes, thanks. I’ve adjusted my code and recompiled it… still no texture appears. but thanks anyways, that’ll be a bug/memory-usage less.

I think (think) that you may want to add these texparameter lines:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

and

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

I can’t guarentee anything, but try it.

-Mezz

Textures… I see TEXTURES!!

Yahoo!!!

Thanks a LOT!

It’s most likely that I’ll try to release my xgl file loader code to the public. And now, as it works… YAY!

Just in case you are interested, the reason behind that case of non-texturing is due to OpenGL’s default min/mag filters & behaviour when mipmapping.

Key is that by default min/mag involve at least one mipmap sample.

However, you didn’t give GL any mipmap set, and GL’s behaviour when you do that is to silently act as if texturing is disabled.

Annoying, I know.

-Mezz