Page 2 of 2

Re: Textured Polygon

Posted: Thu Sep 01, 2011 10:51 pm
by Taehl
Very awesome, miko! How efficient is that? Can you draw, say, a hundred of these every frame at a decent framerate? Could they be animated or otherwise dynamic without using up a huge amount of FPS or RAM?

Re: Textured Polygon

Posted: Thu Sep 01, 2011 11:23 pm
by miko
Taehl wrote:Very awesome, miko! How efficient is that? Can you draw, say, a hundred of these every frame at a decent framerate? Could they be animated or otherwise dynamic without using up a huge amount of FPS or RAM?
It's not that efficient, but it is meant to create only at the game start, and then it is good enough. You could use threads to generate some images "in the background".
For animation you would do as usual (like in sprites) - create multiple copies (for each frame), then switch between them.
It takes CPU cycles to create the initial image (you are reading/writing individual pixels of an image), but then it uses only RAM (as in other images).

Edit: I have misread your question. You probably could draw "a hundred of these every frame" (as opposed to creating them), because once you create them, they are just like other images.
I have updated my code to include some "animation".

Re: Textured Polygon

Posted: Thu Sep 01, 2011 11:51 pm
by miko
Jasoco wrote:Now, if you can get it to distort, we'd have the makings for creating a 3D engine.
Using some math, you could do it. But for acceptable quality, you would need some interpolation algorithms, and that would be slow.
For real 3D engine you need much more than a way of distorting images. Writing this in Lua would be no fun - it's better to use OpenGL directly.

Some background:
http://stackoverflow.com/questions/1699 ... sformation
http://www.cambridgeincolour.com/tutori ... lation.htm
http://en.wikipedia.org/wiki/Bilinear_interpolation

Re: Textured Polygon

Posted: Fri Sep 02, 2011 12:22 am
by miko
kraftman wrote:can't you use a quad and http://love2d.org/wiki/(Image):setWrap
You can - only for rectangles, not for arbitrary polygons.

Re: Textured Polygon

Posted: Fri Sep 02, 2011 12:32 am
by slime
Quick proof-of-concept using Stencils in LÖVE 0.8.0 (it will give an error without the latest 0.8.0, because stencils aren't in 0.7.2): http://dl.dropbox.com/u/4214717/love/te ... lygon.love

I'm not sure if stencils would be the best way for terrain stuff though.

Re: Textured Polygon

Posted: Fri Sep 02, 2011 11:34 am
by Jasoco
miko wrote:
Jasoco wrote:Now, if you can get it to distort, we'd have the makings for creating a 3D engine.
Using some math, you could do it. But for acceptable quality, you would need some interpolation algorithms, and that would be slow.
For real 3D engine you need much more than a way of distorting images. Writing this in Lua would be no fun - it's better to use OpenGL directly.
Java can do it super fast. It's sad that Löve can't.

Re: Textured Polygon

Posted: Mon May 02, 2016 9:44 pm
by buday
After 5 years of silence in this thread...

I can suggest another solution: [[TexturedPolygon]]. It is placed on LOVE wiki in [[Category:Snippets]] category.

The story is: I had the same issue, came it this thread and found out that solution presented above is deprecated and cannot be run under latest version of LOVE. Unfortunately I even couldn't fix it.

Instead, I have written another solution which I present now. It doesn't use [[Canvas]], instead, it use <code>x,y</code> parameters passed to the function that is passed to the [[ImageData:mapPixel]] function, to check whether pixel is within polygon or not.

Go to [[TexturedPolygon]] on wiki to see it.

Re: Textured Polygon

Posted: Mon May 02, 2016 10:09 pm
by slime
In 0.9.0 and newer you can just use a [wiki]Mesh[/wiki], which allows you to draw textured polygons natively.

Re: Textured Polygon

Posted: Tue May 03, 2016 9:10 am
by cval
slime wrote:In 0.9.0 and newer you can just use a [wiki]Mesh[/wiki], which allows you to draw textured polygons natively.
This. And i want to add that as long as user is able to correctly track and calculate UV coordinates, the result will be repeating texture polygon (given that texture has correct setWrap flag enabled, like "repeat").
texturedmesh.love
(3.33 KiB) Downloaded 124 times
Note that on arbitrary polygons that arent rectangles you are going to have more complex UV calculations and corresponding texture distortion.