PDA

View Full Version : OpenGl Es 2.0 Texture Mapping Problem



Eikou U
08-03-2015, 06:12 AM
Hello,

I render a street with OpenGL ES 2.0 and use TRIANGLE_STRIP for it. Now I want to add a texture to my road and use repead as the wrapping method. The street consists of segments. If the segment is 5 meters long, i want to map my texture 5 times to it, 3 meter 3 times and so on.

My problem looks like this:
2025
If the road is to long the texture is wrong. It looks like I use CLAMP_TO_EDGE.

If I have a road that consits out of 10 segments, then I have 22 vertices. The variable "offsets" is a QVector with 10 elements and defines the length of each segment.
Here is the C++ (Qt) code for generating the texture coordinates:



...
float len = 0;
QVector<QVector2D> texcoords;
texcoords.append(QVector2D(0.0, 0.0));
texcoords.append(QVector2D(0.0, 1.0));
for (GLubyte i = 0; i < offsets.size(); i++) {
len += offsets[i];
texcoords.append(QVector2D(len, 0.0));
texcoords.append(QVector2D(len, 1.0));
}

glBindTexture(GL_TEXTURE_2D, m_asphaltTexId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_asphaltTex.width(), m_asphaltTex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_asphaltTex.bits());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

f->glVertexAttribPointer(m_aTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, texcoords.data());
f->glEnableVertexAttribArray(m_aTexCoordLoc);
...


Are the UV respectively ST coordinates limited to a maximum value?
Where is my problem?

Best regards
Eikou