Public Group

# may seem simple question about tex coords but...

This topic is 5076 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey people, I've got a grid of Vertices that define a landscape like so (just a small example)

5----4----8
|  / |  / |
| /  | /  |
1----0----7
|  / |  / |
| /  | /  |
2----3----6

Now the problem comes when i want to define the texture coordinates. Technically each quad lower left vertex will have tex (0,0) and upper right (1,1) with the other two being (0,1) or (1,0). But that means that vertex 0 (for example) will have to have several texture coordinates depending on which quad. Does this mean i have to duplicate vertices at that point for each quad or is there a way around this?

##### Share on other sites
Well, every vertex can only have one texture coordinate* (and one normal etc.)
But there's no problem anyway - just set texture wrapping mode to GL_REPEAT.
In your example you would give vertex 2 the texture coordinates (0,0), vertex 0 would have (1,1) and 8 would have (2,2) and so on.

* per texture unit, that is.

##### Share on other sites
okay and i assume vertex 7 would have coords (2,1) and vertex 1 would have (0,1)?

Also i'm using directX and GL_REPEAT is openGL (isn't it?)

Anyway i thought that maybe the directX equvilant would be to set the texture wrapper SetRenderState(D3DRS_WRAP0, D3DWRAPCOORD_2)

But i don't think that's right anyway cuz it states:
"Be sure the texture wrapping data does not contain any texture coordinates outside of the range of [0.0, 1.0] because this will produce undefined results."

##### Share on other sites
Yes, in OpenGL vertex 7 would have texture coordinates (2,1).. I have no idea what you should do in D3D to get the same effect - I've never used it. Someone else will have to answer here...

##### Share on other sites
Quote:
 Original post by LifeOfTamirTechnically each quad lower left vertex will have tex (0,0) and upper right (1,1) with the other two being (0,1) or (1,0).

That is correct for OpenGL.

However, in DirectGraphics, the texture coordinate (0, 0) is the upper-left of the texture and (1, 1) represents the lower-right of the texture.

For D3D:

##### Share on other sites
Thanks for the replies guys. But it's still not quite working yet.

What i've got now is a combinatino of all your suggestions.
So my upper left vertex (5 is diagram above) had tex coords (0,0)
vertices 0 and 6 have (1,1) and (2,2) respectively. vertex 4 would have (1,0) vertex 1 (0,1) and so forth for the rest.

then i've used

to render and while there is a mark improvement it's still not really correct as demonstrated below:

at first i thought it might be because i've got some of my tex coords wrong but i've double checked and they are definitely correct (at least correct in the way i've described)

any ideas what could be wrong?

--edit--
actually the SetSamplerState seems to be having no effect, if i comment out the code i still get exactly the same display

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 36
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631703
• Total Posts
3001816
×