PDA

View Full Version : Texture mapping doesn't work



Amir Vaxman
10-13-2003, 12:32 PM
Hello,

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.

chowe6685
10-13-2003, 03:20 PM
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.

10-13-2003, 10:44 PM
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.
Codifex

10-13-2003, 11:48 PM
One minor niggle - move the glNormal call inside the begin/end construct. It *wants* to be in there, honest! http://www.opengl.org/discussion_boards/ubb/wink.gif

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.

zix99
10-14-2003, 09:22 AM
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
zix

pkuloop
10-14-2003, 10:47 AM
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.