Textured Polygon
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Textured Polygon
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+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: Textured Polygon
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".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?
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 172 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
Re: Textured Polygon
Using some math, you could do it. But for acceptable quality, you would need some interpolation algorithms, and that would be slow.Jasoco wrote:Now, if you can get it to distort, we'd have the makings for creating a 3D engine.
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
Re: Textured Polygon
You can - only for rectangles, not for arbitrary polygons.kraftman wrote:can't you use a quad and http://love2d.org/wiki/(Image):setWrap
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
- slime
- Solid Snayke
- Posts: 3170
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Textured Polygon
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.
I'm not sure if stencils would be the best way for terrain stuff though.
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Textured Polygon
Java can do it super fast. It's sad that Löve can't.miko wrote:Using some math, you could do it. But for acceptable quality, you would need some interpolation algorithms, and that would be slow.Jasoco wrote:Now, if you can get it to distort, we'd have the makings for creating a 3D engine.
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.
Re: Textured Polygon
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.
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.
- slime
- Solid Snayke
- Posts: 3170
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Textured Polygon
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
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").slime wrote:In 0.9.0 and newer you can just use a [wiki]Mesh[/wiki], which allows you to draw textured polygons natively.
Note that on arbitrary polygons that arent rectangles you are going to have more complex UV calculations and corresponding texture distortion.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Giapp and 5 guests