I'm trying to apply a texture to a vertex array whit the following code:
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glColor3f(1.0f, 1.0f, 1.0f);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glDrawElements(GL_QUADS, 12, GL_UNSIGNED_BYTE, faceIndices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisable(GL_TEXTURE_2D);
with this texture:
so i have this result:
Now I'm wondering how can I scale the floor texture, i've already tried to scale the texture with photoshop, but the result is the same but heavier.
I assume you mean you want the texture to tile less, or tile more. In which case, change your texture coordinates, not the texture (i.e. whatever data is in texcoords
).
Also, your example texture is blue, but it's brown in the rendered image. You might be swapping the R+B channels when loading.
It depends on your texture coordinates how you want to map the texture. Let take example,it cover the whole polygon
glTexCoord2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f);
Now if you want to repeat the texture five times then provide coordinates like `
glTexCoord2f(0.0f, 0.0f);
glTexCoord2f(5.0f, 0.0f);
glTexCoord2f(5.0f, 5.0f);
glTexCoord2f(0.0f, 5.0f);`
Like above example change the value how you want to map the texture.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With