Page 1 of 1

Repeated texture inside a mesh

Posted: Mon Dec 19, 2016 6:29 pm
by aloisdeniel
Hi,

I'm currently stuggling at displaying a polygon filled with a repeated texture, which is actually a quad of an image.

Here a quick sketch :
Image

I suppose that a Mesh should be used...

Thanks!

Re: Repeated texture inside a mesh

Posted: Mon Dec 19, 2016 7:03 pm
by raidho36
OpenGL doesn't expose means to use sub-texture as if it was the whole texture. One way of solving it is using a shader. The other way is to use a whole separate texture. Either way has same data bus overhead since both require an additional GPU draw call, the shader solution will be more computationally intensive to render. Lastly you can indeed use a mesh, but then you'll need to generate sub-quads in the whole thing and generate the whole thing from scratch if the texture coordinates have to move.

Re: Repeated texture inside a mesh

Posted: Mon Dec 19, 2016 7:23 pm
by aloisdeniel
Okay thanks!

I don't need dynamic texture coordinates : I think I'm gonna generate image from the area of the original sheet data with a new image ( I've a limited set of textures for these polygons) :

Code: Select all

image = love.graphics.newImage( data)

Re: Repeated texture inside a mesh

Posted: Mon Dec 19, 2016 9:06 pm
by s-ol
aloisdeniel wrote:Okay thanks!

I don't need dynamic texture coordinates : I think I'm gonna generate image from the area of the original sheet data with a new image ( I've a limited set of textures for these polygons) :

Code: Select all

image = love.graphics.newImage( data)
if you don't need a moving texture you can just set the u/v coordinates corretly and it should loop:

Code: Select all

   0
   .-------1,2
    \          \
     \ 5,4 ...3

with these as the vertices, and if one texture loop is the same distance as 0-1, uv would be

0: Xs, Ys
1: Xl, Ys
2: xs, Ys
3: Xl, Yl
4, Xs, Yl
5: Xl, Yl

Xs/Ys is the top left corner of your texture quad (normalized) and Xl/Yl is the lower-right corner.
Note how you need two vertices (insert two at every texture end) to loop around the texture since you can't go out of range to wrap like with a seperate texture (:setWrapMode).