Luca
Luca

Reputation: 1350

opengl, textures have always the same size

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: texture

so i have this result: 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.

Upvotes: 5

Views: 831

Answers (2)

Dinesh Subedi
Dinesh Subedi

Reputation: 2663

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.

Upvotes: 2

JasonD
JasonD

Reputation: 16582

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.

Upvotes: 6

Related Questions