Help needed with Meshes

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Ltven0mI
Prole
Posts: 1
Joined: Sun Jul 26, 2015 3:47 am
Contact:

Help needed with Meshes

Post by Ltven0mI »

I'm attempting to make a mesh for a background
And I need it to appear to be going from the foreground into the background
But when I try and draw a texture on it, it has weird results

This is what I'm trying to achieve
Image

And this is what I actually get
Image

This is my code

Code: Select all

local mesh = nil
local img = love.graphics.newImage("test_blue.png")

function love.load()
  mesh = love.graphics.newMesh(4, img, "fan")
  mesh:setVertices({
    {125, 100, 0, 0, 255, 255, 255, 255},  --Top Left
    {150, 100, 1, 0, 255, 255, 255, 255},  --Top Right
    {200, 400, 1, 1, 255, 255, 255, 255},  --Bottom Right
    {100, 400, 0, 1, 255, 255, 255, 255} --Bottom Left
	})
end

function love.draw()
  love.graphics.draw(mesh, 200, 0)
end
I don't understand why this is happening so if anyone could tell me. It would be much appreciated
Attachments
example.love
(843 Bytes) Downloaded 74 times
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Help needed with Meshes

Post by arampl »

Hmm. I don't think you can have perspective effect in 2d with ordinary meshes. Squares will be stretched evenly for sure.

P.S. Better move this question to the "Support and Development" board.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Help needed with Meshes

Post by Jasoco »

This question gets asked so often. Löve isn't necessarily made for 3D, but there's such a strong portion of the Löve user base who are doing their darnedest to do as much 3D as they can. So 3D topics come up all the time. (I know your question isn't necessarily about 3D, but it's related)

The problem with Meshes is that they don't correct for perspective, hence why you have the weird looking texture. A while ago I brought this "problem" up with the devs and after a few days another forum member (Who seems to have disappeared) wrote a really awesome Shader to do this for us. It's not the most perfect shader, but it works. (I modified my own version heavily to work better for my needs, but the original version works just fine.)

Note that since the shader needs to run for every single texture, and that due to the nature of how Shaders work, it will be processing the entire resolution of the window every time its called, it might cause a bit of slowdown if a lot of textures are needed to be drawn, however this hasn't stopped me in the past...

Image Image Image Image Image
(I like to brag about this whenever I can.)

Here is where you can find the most recent posts about this very subject including a link to the library/shader: viewtopic.php?f=5&t=80530&p=187040&hili ... ve#p187037
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests