Page 1 of 1

Surfaces and Drawing

Posted: Mon Aug 30, 2010 8:39 pm
by Lap
It doesn't seem like there is any documentation on surfaces or drawing images. I can't even find a good example of how to draw images in the TOME module either. Any example code for drawing an image on a surface?

Re: Surfaces and Drawing

Posted: Mon Aug 30, 2010 9:01 pm
by darkgod
Yes the C code has no luadoc this needs to be fixed :=)

To load an image the simpliest way is to do:

Code: Select all

local img = core.display.loadImage("/data/..../foo.png")
Then you can draw it on an other surface like that:

Code: Select all

dest:merge(img, x, y)
You can also directly display a surface on screen:

Code: Select all

img:toScreen(x, y)
If the surface wont change later you can make an opengl texture from it to speed up rendering:

Code: Select all

local tex = im:glTexture()
and display it:

Code: Select all

tex:toScreen(x, y, w, h)
You can actually update the texture if the surface changes (this is how dialogs work internally) this is faster than jsut drawing the surface.

But you probably dont need to optimize just yet ;)

Re: Surfaces and Drawing

Posted: Tue Aug 31, 2010 7:27 am
by Antagonist
I see this has not been added to the wiki yet.

This situation has been fixed.

Re: Surfaces and Drawing

Posted: Tue Aug 31, 2010 7:39 am
by darkgod
Yeah thanks anta :)