Page 2 of 2
Re: Image vs Graphics
Posted: Sun Sep 26, 2010 10:38 am
by rude
ImageData is indeed just the decoded pixels stored in regular memory. Image (love.graphics) represents a non-changeable OpenGL texture stored in GPU memory. Sending a texture to the GPU is expensive. You don't want to do this every frame.
Also note that when you do:
Code: Select all
i = love.graphics.newImage("foo.png")
What "really" happens is:
Code: Select all
f = love.filesystem.newFile("foo.png")
id = love.image.newImageData(f)
i = love.graphics.newImage(id)
Re: Image vs Graphics
Posted: Sun Sep 26, 2010 7:52 pm
by bmelts
MaskedRetreiver wrote:Huh. In my case I'm using imageData so I can use the :paste method to slice up tile files into their own graphical contexts... perhaps there's something in graphics I'm missing?
For example, all these have to be imageData:
Code: Select all
--a 640x480 graphic is 20x15 tiles
for j=0,14 do
for i=0,19 do
tileImagepile[i+j*15]= love.image.newImageData(32,32)
tileImagepile[i+j*15]:paste(TilesImageData,0,0,32*i,32*j,32,32)
end
end
You
definitely want Quads for that.
Code: Select all
--a 640x480 graphics is 20x15 tiles
tiles = {}
tileImage = love.graphics.newImage("tiles.png")
local tw = tileImage:getWidth()
local th = tileImage:getHeight()
for j = 0, 14 do
for i = 1, 20 do -- to work with Lua's 1-indexed array system
tiles[i+j*20] = love.graphics.newQuad(32*(i-1),32*j,32,32,tw,th)
end
end
Then, to draw a given tile, simply:
Code: Select all
love.graphics.drawq(tileImage, tiles[tileNumber], x, y)
For reference:
love.graphics.newQuad and
love.graphics.drawq.
Re: Image vs Graphics
Posted: Wed Sep 29, 2010 3:26 am
by MaskedRetreiver
Is drawing quads any faster than drawing images, or just easier? I think to get performance I'll still have to break my game world up into big chunks and save them for rapid single-command display...
Re: Image vs Graphics
Posted: Wed Sep 29, 2010 5:43 am
by bartbes
It most certainly saves memory, and depending on how often you generate the images it's faster.
Re: Image vs Graphics
Posted: Wed Sep 29, 2010 7:12 pm
by MaskedRetreiver
Yep, I benchmarked drawing a load of tiles against my current method and it's definitely faster. I'm still going to be drawing my screen in big chunks of tiles pasted together, but I'll probably switch to quads eventually for the speed boost. Thanks Love Forums!
(Seriously, this forum is amazingly friendly. Over at Allegro.cc you get keelhauled for even being a /little/ out of your depth.)
Re: Image vs Graphics
Posted: Wed Sep 29, 2010 7:14 pm
by bartbes
Well, we do it more covertly, in your sleep we sneak up to you, and then (redacted). Or not.
Re: Image vs Graphics
Posted: Thu Sep 30, 2010 7:34 am
by kikito
Yeah, I asked one simple question one day, and the next day I woke up and someone had drawn a moustache on my face.
I just assumed it was bartbes.
Re: Image vs Graphics
Posted: Thu Sep 30, 2010 8:00 pm
by Robin
kikito wrote:I just assumed it was bartbes.
Oh, that was me. The big hole in the side of your house with the dead dolphin fetuses was bartbes. (You did that yesterday, didn't you, bartbes? Or were you going to do that tomorrow after all?)