Hi everyone! i need your help again, i have a simple flat floor with tiles using triangel strips, but when i texturing it, just 1 row have te correct texture, the problem is with the text coord, i need a texture for 1 tile not a big texture for all the floor, anyone can help me with the correct text coord for a flat floor with tiles (each tiles has his own texture)
thanks in advance folks!!
oh!! here is te code that i use to generate the floor and the texture i’m using VBO
for(int x = 0;x<MAP_SIZE_X;x++){
for(int z = 0;z<MAP_SIZE_Z;z++){
verticesStd.push_back(x*size);
verticesStd.push_back(size);
verticesStd.push_back(z*size);
textCordStd.push_back(1.0);
textCordStd.push_back(0.0);
verticesStd.push_back(x*size);
verticesStd.push_back(size);
verticesStd.push_back((z*size) + size);
// text coord
textCordStd.push_back(0.0);
textCordStd.push_back(0.0);
verticesStd.push_back((x*size)+size);
verticesStd.push_back(size);
verticesStd.push_back(z*size);
// text coord
textCordStd.push_back(1.0);
textCordStd.push_back(1.0);
verticesStd.push_back((x*size) + size);
verticesStd.push_back(size);
verticesStd.push_back((z*size) + size);
// text coord
textCordStd.push_back(0.0);
textCordStd.push_back(1.0);
}
}
here it’s where i get the data from the
std::vector to a simple C array
vertices = new float[verticesStd.size()];
verticesSize = sizeof(vertices)*verticesStd.size();
if (!verticesStd.empty()) {
vertices = &verticesStd.front();
}
textCord = new float[textCordStd.size()];
textCordSize = sizeof(textCord)*textCordStd.size();
if (!textCordStd.empty()) {
textCord = &textCordStd.front();
}
// do the VBO stuff (maybe the map coord error is here)
glGenBuffersARB(1, &vboId);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, verticesSize+textCordSize, 0, GL_STATIC_DRAW_ARB);
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, verticesSize, vertices);
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, verticesSize, textCordSize, textCord);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
here is the “codelet” render code for the floor and the textures
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId);
glActiveTextureARB( GL_TEXTURE0_ARB );
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D,1);
glTexCoordPointer(2, GL_FLOAT, 0,(void*)(verticesSize) );
glVertexPointer(3, GL_FLOAT, 0, 0);
glLockArraysEXT(0, verticesSize);
glDrawArrays(GL_TRIANGLE_STRIP, 0, verticesSize/12);
glUnlockArraysEXT();