Textured Polygon

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.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Textured Polygon

Post 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?
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Textured Polygon

Post 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".
Attachments
TexturedPolygonAnimated.love
(25.18 KiB) Downloaded 153 times
Last edited by miko on Fri Sep 02, 2011 12:16 am, edited 1 time in total.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Textured Polygon

Post 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
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Textured Polygon

Post 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.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
slime
Solid Snayke
Posts: 3134
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Textured Polygon

Post 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.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Textured Polygon

Post 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.
buday
Prole
Posts: 1
Joined: Mon May 02, 2016 4:26 pm

Re: Textured Polygon

Post 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.
User avatar
slime
Solid Snayke
Posts: 3134
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Textured Polygon

Post by slime »

In 0.9.0 and newer you can just use a [wiki]Mesh[/wiki], which allows you to draw textured polygons natively.
cval
Citizen
Posts: 58
Joined: Sun Apr 20, 2014 2:15 pm
Location: Ukraine

Re: Textured Polygon

Post 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 107 times
Note that on arbitrary polygons that arent rectangles you are going to have more complex UV calculations and corresponding texture distortion.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests