I have 3d-models with 2d texture coordinates (s,t) outside the range [0,1]. Setting GL_TEXTURE_WRAP_S/T to GL_REPEAT via glTextParameter() makes OpenGL displaying the textures correctly.
For later processing, I indispensably need texture coordinates in the positive range (s,t>=0). The documentation says that OpenGL uses the fractional part of the coords as position and the integer part as number of repetitions - this means it should be possible to convert the texture coordinates of triangles/quads into the positive range somehow.
Using the absolute value of coordinates does not work at all. I’d really appreciate advise on how to convert the coordinates properly.
Thanks a lot!
For later processing, I indispensably need texture coordinates in the positive range (s,t>=0).
Can you explain more what is this later processing ? Pixel post processing ? Why do you need positive range only ?
Using the absolute value of coordinates does not work at all
Try modulo division instead, and per pixel rather than per vertex.
Thanks for your prompt reply.
My program creates a 3d model output-file (containing vertex and texture coordinates not pixels) which will then be used in a different piece of software unfortunately only supporting positive texture coordinates.
Modulo 1? Then the integer part will be lost and thus the repetition won’t work, right? I definitely need to convert the vertex texture coordinates as they will later be written in the output-file.
Modulo 1 will work per pixel.
Nothing can work per vertex.
EDIT : there is a way in fact, if the allowed range is [0;+inf] :
- find the smallest texcoord, let’s say tx=-2.3
- if tx is negative, then for each texcoord n, do txn = txn-floor(tx)
And do that separately in x and y.