Image vs Graphics

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
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Image vs Graphics

Post 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)
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: Image vs Graphics

Post 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.
MaskedRetreiver
Prole
Posts: 22
Joined: Sat Sep 25, 2010 4:13 pm

Re: Image vs Graphics

Post 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...
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Image vs Graphics

Post by bartbes »

It most certainly saves memory, and depending on how often you generate the images it's faster.
MaskedRetreiver
Prole
Posts: 22
Joined: Sat Sep 25, 2010 4:13 pm

Re: Image vs Graphics

Post 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.)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Image vs Graphics

Post by bartbes »

Well, we do it more covertly, in your sleep we sneak up to you, and then (redacted). Or not.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Image vs Graphics

Post 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.
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Image vs Graphics

Post 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?)
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 215 guests