I can't understand U and V in meshes

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
Zarty55
Citizen
Posts: 79
Joined: Thu Jul 25, 2013 2:36 am

I can't understand U and V in meshes

Post by Zarty55 »

I'm trying to make a little quad textured with a canvas (which is a image of 1x9). The canvas is pretty much this:

Image

I'm using this code in a draw callback:

Code: Select all

  mesh:setVertex(1, 0, 0, 0, 0, 255, 255, 255, 255)
  mesh:setVertex(2, 45, 20, 1, 0, 255, 255, 255, 255)
  mesh:setVertex(3, 45, 30, 1, 1, 255, 255, 255, 255)
  mesh:setVertex(4, 0, 50, 0, 1, 255, 255, 255, 255)
  lg.draw(mesh)
But the texture is in a weird shape:

Image

I've never used meshes, so I'm not sure what the problem is. Thanks already :D
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: I can't understand U and V in meshes

Post by micha »

The u-v coordinates are correct, but the x-y coordinates are not. You set them to these:

(0,0) -- (45,20) -- (45,30) -- (0,50)

This is not a rectangle, but exactly the shape you have in the image you posted. If you want a rectangle then do something like this:
(0,0) -- (45,0) -- (45,50) -- (0,50)

or more general with two numbers a and b:
(0,0) -- (a,0) -- (a,b) -- (b,0)
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: I can't understand U and V in meshes

Post by Karai17 »

micha wrote:The u-v coordinates are correct, but the x-y coordinates are not. You set them to these:

(0,0) -- (45,20) -- (45,30) -- (0,50)

This is not a rectangle, but exactly the shape you have in the image you posted. If you want a rectangle then do something like this:
(0,0) -- (45,0) -- (45,50) -- (0,50)

or more general with two numbers a and b:
(0,0) -- (a,0) -- (a,b) -- (b,0)
(0,0) -- (a,0) -- (a,b) -- (0,b)
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests