I was just trying out some ways to generate a racing track from a few points, generating the vertices worked out right but I'm having some problems with the texture coordinates. I currently have a distance variable which keeps track of the current track distance and a textureSize variable which determines how much pixels of the track the texture should cover.
The code which calculates the uv coordinates:
float textureSize = 64.0f //The texture is 64x64 so this should display it at the real scale.
// The two sides of the point in the track.
leftVertex.texCoords = sf::Vector2f(0.0f, distance / textureSize);
rightVertex.texCoords = sf::Vector2f(1.0f, distance / textureSize);
I render the vertices like this:
renderer.SaveGLStates();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_WRAP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_WRAP);
renderer.SetTexture(&m_Texture);
renderer.Begin(sf::Renderer::TriangleStrip);
for (int i = 0; i < m_sideVertices.size(); i++)
{
renderer.AddVertex(m_sideVertices[i].position.x,
m_sideVertices[i].position.y,
m_sideVertices[i].texCoords.x,
m_sideVertices[i].texCoords.y,
sf::Color::White);
}
renderer.End();
renderer.RestoreGLStates();
But it looks like this (red lines show where the vertices are):
As you can see the beginning of the track (the left side) is textured correctly because the v coordinates are within the 0-1 range, after that the texture gets stretched out.
So is setting the texture wrapping mode to GL_REPEAT not working or am I using the wrong texture coordinates?