Repeated texture inside a mesh

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
aloisdeniel
Prole
Posts: 17
Joined: Sat Jan 30, 2016 5:57 pm
Contact:

Repeated texture inside a mesh

Post 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!
My LÖVE libraries : pixelatlas, pixelmap
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Repeated texture inside a mesh

Post 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.
User avatar
aloisdeniel
Prole
Posts: 17
Joined: Sat Jan 30, 2016 5:57 pm
Contact:

Re: Repeated texture inside a mesh

Post 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)
My LÖVE libraries : pixelatlas, pixelmap
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Repeated texture inside a mesh

Post 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).

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Google [Bot], Semrush [Bot] and 4 guests