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

Change your texture coordinates from 0.0 and 1.0 to x+0.0, x+1.0, z+0.0 and z+1.0. This should do.

mfort

06-21-2007, 11:21 PM

Just went though your code and found:

vertices = new float[verticesStd.size()];
verticesSize = sizeof(vertices)*verticesStd.size();
if (!verticesStd.empty()) {
vertices = &amp;verticesStd.front();
}1. memory leak (the float array is never released from memory when the vector is not empty (usual case)
2. verticesSize is incorrectly computed. Should be sizeof(float) or sizeof(*vertices), now you are multiplying size of pointer
3. The same applies to texcoord

glDrawArrays(GL_TRIANGLE_STRIP, 0, verticesSize/12);This will work only for one row.
Imagine how the first triangle of next row is rendered. The triangle strip means that the vertices of new triangle are connected to the
last triangle.
So there are 2 strangle very big triangles from last tile,previous row to the next row,first tile.If this is intentional then I'd play with culling to get rid of them.
The other way is to split the rows in separate runs of triangle strips.
Using display list is probably an option too, you can compile all the strips into one call to OpenGL.

mfort

06-21-2007, 11:29 PM

or try to replace GL_TRIANGLE_STRIP to GL_QUADS.
It has the same vertex arrangement and probably better for your tiles.

Olivier B.

06-22-2007, 02:57 AM

Defines your texcoord between 0 and 1 for each tiles or use GL_REPEAT.

juglarx

06-22-2007, 08:55 PM

tks to all for the response!
@mfort:i fix the memory leak and the correct size,that's ok now... i can render all the floor using tringle strips using

glDrawArrays(GL_TRIANGLE_STRIP, 0, verticesSize/12);but the problem is with the texture coord,here i put an image of the problem,
http://imagesjack.us/picture.php?p=5e4dc4cea7.jpg
can you help me to figure out what it's wrong ?
thanks in advance!!

kon

06-23-2007, 02:15 AM

since you want to render tiles don't use a strip, use quads! (because a corner for a tile has different texture coordinates for an adjacent tile)

Definitely use quads (if you need mesh for lights)
or use one big quad over whole floor and set texture repeat.

I've found that the your tri.strip is wrong. Don't forget the tri.strip vertex is connected to last two. In your case the connection takes place
between last two vertices of previous tile and first vertex of new tile.
That is because you are drawing one very large tri.strip. (Maybe wanted to draw several tri.strips with 4 vertices, but your code doesn't do that).

See the last argument to

glDrawArrays(GL_TRIANGLE_STRIP, 0, verticesSize/12);It should be number of vertices to draw (in case of triangle strip it is number of vertices of one tri.strip)
Look what you give: verticesSize/12. You are giving number of bytes of vertex array divided by 12. Thats weird isn't it? You are bit lucky because 5*5*12*4 bytes / 12 = 100, which is number of vertices. So you are drawing very long triangle strip.
You can do that (See my first post, I thought you were doing it). You can prepare very long tri.strip in very special way, you must create degerate triangles at the end of each row, which are never rendered (too small,or culled away) and take care of transition of one tile to another. But it is tricky.