Texture mapping doesn't work


I have tried every rule in the book concerning how to texture polygons, and also looked over some source code tutorials. But yet, I can’t seem to get it to work, and the polygons I try to texture just appear in the color formerly defined. Some clarifications:

  1. glGenTextures doesn’t give me back a new ID, why is that?

  2. is there something that must be done, a variable or register that must be set before beginning to work with textures (including the uploading)? should the viewport be defined first or something?

  3. why does glGetError always give me the same error flag, even on consecutive calls? shouldn’t it reset it?

I would like it very much if someone could give me a hand here.

We cannot possibly help you without looking at your code, the only thing I can recommend is making sure you have a valid rendering context, without one all gl* calls will fail, even glGetError. nehe.gamedev.net has a tutorial on setting up a rendering context on most OS’s.

First thought…

Don’t try to chose or bind a texture between a glBegin and glEnd pair.

Here is a snippet of my code:

glBindTexture (GL_TEXTURE_2D, materialid); // choose texture
glNormal3f(normal.x, normal.y, normal.z); glBegin (GL_TRIANGLES);
glTexCoord2f(0.0f, 0.0f);
glVertex3f (xa, ya, za);
glTexCoord2f(1.0f, 0.0f);
glVertex3f (xb, yb, zb);
glTexCoord2f(1.0f, 1.0f);
glVertex3f (xc, yc, zc);
glEnd ();

I hope this helps you.

One minor niggle - move the glNormal call inside the begin/end construct. It wants to be in there, honest!

Make sure you’re enabling texturing:

glEnable(GL_TEXTURE_2D) ;

And post the code you use to generate texture ids, upload the texture data etc.

There are 3 things that i can think of, that usually happen to me.

First thing is i forget to enable GL_TEXTURE2D.

Second, The texture i’m using isn’t a proper size (EX: has to be 512x512 or 512x1024 etc)

Third, I forgot to initialize OGL before I load the texture, which would cause your problem of the glGenTexture not giving you new numbers

I hope I could help

How did you creat your texture?
if the texture size is not power of 2, it will be problem. (though some extensions work with non power of 2 texture size)

Post more details.