Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 574
Luca Avatar asked Jan 24 '13 09:01

Luca


2 Answers

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.

like image 82
JasonD Avatar answered Sep 30 '22 03:09

JasonD


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.

like image 22
Dinesh Subedi Avatar answered Sep 30 '22 04:09

Dinesh Subedi