3D Grid Texture Mapping

Started by
0 comments, last by Falken42 18 years ago
Hi, well thise time I'm creating a room,where the floor and walls are made with GL_QUAD_STRIP, like a kind of GRID, now the problem is that I can't make the Texture Mapping over the floor, I have tryed several forms to do it, but no once seems to work... glNormal3f(0.0, 1.0, 0.0); for (j = 0; j <= h; j+=2) { glBegin(GL_QUAD_STRIP); for (i = 0; i <= w; ++i) { if(i==0&&j==0) glTexCoord2f(0.0f, (float)h); else if(i>=w&&j>=h) glTexCoord2f((float)w, (float)h); glVertex3f(i, 0.0, (j + 2)); if(i==0&&j==0) glTexCoord2f(0.0f, 0.0f); else if(i>=w&&j>=h) glTexCoord2f((float)w, 0.0f); glVertex3f(i, 0.0, j); } glEnd(); } Sorry about my bad english :p

twitter: @leonidax

website: www.leonidax.com

Advertisement
glTexCoord2f requires texture coordinates in the range of [0.0f -> 1.0f], unless you are using some kind of texture repeat/mirroring method (or NPOT sized textures with non-normalized texture coordinates). I'm guessing that both 'w' and 'h' are much larger than 1.

Try dividing your loop index by the width/height passed to glTexCoord2f, like so:
if(i==0&&j==0) glTexCoord2f(0.0f, (float)j / (float)h);else if(i>=w&&j>=h) glTexCoord2f((float)i / (float)w, (float)j / (float)h);

This is also assuming you've properly loaded, bound, and enabled your texture as well... but I'd need to see some more code to determine if there is a problem there or not.

This topic is closed to new replies.

Advertisement