Opengl, textures are always the same size

I am trying to apply a texture to an array of vertices using 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 I can scale the texture of the floor, I already tried to scale the texture using Photoshop, but the result is the same, but harder.

+6
source share
2 answers

It depends on your texture coordinates, how you want to match the texture. Let’s take an example, it spans the entire 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, specify the coordinates of type `

 glTexCoord2f(0.0f, 0.0f); glTexCoord2f(5.0f, 0.0f); glTexCoord2f(5.0f, 5.0f); glTexCoord2f(0.0f, 5.0f);` 

As in the previous example, change the value as you want to match the texture.

+2
source

I assume that you want the texture to be smaller or the tile larger. In this case, change your texture coordinates, not the texture (i.e. what data is in texcoords ).

Also, your example texture is blue but brown in the rendered image. When loading, you can change the channels R + B.

+7
source

All Articles