Equivalent in OpenGL of DirectX texture wrapping ?

I’m trying to implement cylindrical texture mapping in a vertex program. For the most part it works OK but I’ve got a problem with the way OpenGL interpolates texture coordinates. What I need to remove the issue is the equivalent of DirectX texture wrapping, I know that it is not implemented in OpenGL core but is there an extension or maybe some kind of tricks to reproduce this functionality ?


Huh? It is implemented in the basic opengl core, or i am misunderstanding what you mean by “texture wrapping”.


And use texture coordinates > 1.0.

If so this is not an advanced question.


OK my description wasn’t clear enough, for more details on texture wrapping in DirectX check this http://msdn.microsoft.com/archive/defaul…urewrapping.asp

I agree that the name is misleading :slight_smile:

If i get this right, the texture wrapping from the example (2nd pic), is simple texture wrapping around the S axis, as Ysaneya described, with texcoords from vertex B with (1.1, 0.1). Maybe i don’t get it. It’s a horrible writing. If so, you could describe what you want to achieve with this “texture wrapping”. I never heard of someone who needs this kind of texture wrapping.


Ok I will do my best to explain it : I’m generating texture coordinates in the vertex program. To find cylindrical texture coordinates I’m taking the z coordinate (scaled and translated to be in the [0, 1] range) of the vertex to find v, and to find u I’m doing something like 1 / 2PI * atan2 (y, x) + 0.5 which puts me in the range [0, 1].

Now imagine a sphere for example, when I generate the u coordinate of the “last” vertex(which may be for example 0.9) there will be an interpolation between this and the first vertex (which have a u coordinate of 0.1 for example). Now with classical interpolation taking the shortest path in a 2D plane what I will see is my whole texture extremely compressed between the two vertices and “reversed” (as if you were looking in a mirror). This is perfectly logical because interpolation will travel from 0.9 down to 0.1. To remove this I need a wrapping mode which says that 0.0 and 1.0 are coincident so the shortest path between 0.9 and 0 will not be 0.9, 0.85, 0.8, 0.75…0.1 but 0.9, 0.95…and then wrap to 0, 0.1.

This is not simple to see the problem and it’s even more difficult to explain it :wink: especially in english, I hope it is clearer now though. I agree with you, there is a simple method : taking the absolute value of the difference between the coordinates, adding 1 to the smallest texture coordinate value and using texture repeat if this difference is greater than 0.5 would do the trick but because I’m in a vertex program I’ve no access to adjacent vertices to do this kind of thing.

Direct3D has a special (and somewhat annoying) texture coordinate wrapping mode called Cylindrical Wrap. The mode is there to avoid duplicating vertices as the wrap point. Without it, you need two vertices - one for the start (texture coordinate = 0) and one for the end (texture coordinate = 1).

Cylindrical Wrap looks at a primitive (not just the vertex) and chooses the shorter path through texture space.

It’s a fair amount of trouble to go through just to avoid duplicating a few vertices though…

Thanks -

So i think this texture wrapping mode comes from the pre t&l hardware time to save some transformations. On todays hardware it wouldn’t kill performance if you add a vertex at points where needed. You could do this in a preprocessing step or, if possible, modify your models.