Page 1 of 2

Efficient Image Drawing

Posted: Wed Feb 08, 2012 3:36 pm
by thetree
Hey,

I'm writing a fairly simple game however on older PCs (without OpenGL) there is a significant drop in FPS when drawing images. For example I am drawing clouds in a similar way to the LOVE demos. I changed the clouds to use a sprite sheet which has made the fps better though I have multiple images to draw for trees/enemies/bullets etc and it doesn't look like a sprite sheet is really meant for constantly changing objects like bullets. Is there a better way than sprite sheets or iterating through each object and drawing the image straight?

Thanks

tree

Re: Efficient Image Drawing

Posted: Wed Feb 08, 2012 3:40 pm
by tentus
A couple things in how you worded that have me worded. You you post an example of what you're doing?

Draw a handful of images shouldn't immediately devastate your FPS, spritesheets or not.

Re: Efficient Image Drawing

Posted: Wed Feb 08, 2012 3:49 pm
by thetree
tentus wrote:A couple things in how you worded that have me worded. You you post an example of what you're doing?

Draw a handful of images shouldn't immediately devastate your FPS, spritesheets or not.
The images combined are probably rendering to 80% of the screen at once if that makes a difference? Tbh, the PC I'm testing this on is a bit weird. The FPS fluctuates constantly and reaches 40 FPS max even when using the sheets though is mostly around 20. I'm starting to wonder if its just this computer, though I want to at least try make it work.

The actual drawing is something like this (don't have actual code with me atm):

Code: Select all

function love.draw()
    for i = 1, Cloud.count() do
        love.graphics.draw(cloudImg, clouds[i].getX(), clouds[i].getY(), 0, 1, 1)
    end
end
I've tried removing the movement code for the clouds and just having them static to rule out the possibility of the movement code being bad, but that wasn't the problem.

There are 6 clouds 350px by 250px png format.

Re: Efficient Image Drawing

Posted: Wed Feb 08, 2012 3:53 pm
by tentus
Yeah, nothing in that code looks like a problem. Odds are its the machine then.

Re: Efficient Image Drawing

Posted: Wed Feb 08, 2012 3:55 pm
by thetree
tentus wrote:Yeah, nothing in that code looks like a problem. Odds are its the machine then.
Ok, just wanted to check to make sure I hadn't done anything horrifically bad.

Thanks for the quick response :)

Re: Efficient Image Drawing

Posted: Wed Feb 08, 2012 4:21 pm
by Ellohir
Could you post a .love file so we can take a look anyway? I'm curious :nyu:

Re: Efficient Image Drawing

Posted: Wed Feb 08, 2012 4:42 pm
by coffee
thetree wrote:Ok, just wanted to check to make sure I hadn't done anything horrifically bad.
Unless your Cloud.count hides something terrible like recalculating without need the clouds. love file please! :D

Re: Efficient Image Drawing

Posted: Wed Feb 08, 2012 4:45 pm
by slime
What's your computer's hardware? I think some GPUs/drivers revert to software rendering when trying to draw an image with non power-of-two dimensions, rather than making it blank. Try using images with power of 2 dimensions, like 512x512 or 128x256 or whatever.

Re: Efficient Image Drawing

Posted: Wed Feb 08, 2012 5:15 pm
by thetree
slime wrote:What's your computer's hardware? I think some GPUs/drivers revert to software rendering when trying to draw an image with non power-of-two dimensions, rather than making it blank. Try using images with power of 2 dimensions, like 512x512 or 128x256 or whatever.
I'm using the latest 0.8.0 build to get round the PO2 problem, though I did try it with 0.7.2 and PO2 images but if anything it was slower.

Regarding the other code, I don't think thats the problem as I've already debugged the rest of the code to check its not my code. Commenting out the actual love.graphics.draw() function was the only thing that affected the FPS.

I don't know what the specs were, I was testing it on a PC that I do not own. I remember all the stats apart from the graphics ( Intel Core 2 Duo @ 2.2 GHz, 3GB RAM, XP Professional 32bit ), though its definitely integrated motherboard graphics. Intel HD or something similar would be my best guess.

As a side note, my main PC with all the normal stuff you'd expect on a mid/high range rig seems to be capped at 60 FPS, though my old crappy laptop doesn't have this cap and runs fine at ~150 FPS. This normal?

I'll test it on every machine I have access to and just check to see if its a problem with that specific PC.

Re: Efficient Image Drawing

Posted: Wed Feb 08, 2012 5:45 pm
by Boolsheet
thetree wrote:As a side note, my main PC with all the normal stuff you'd expect on a mid/high range rig seems to be capped at 60 FPS, though my old crappy laptop doesn't have this cap and runs fine at ~150 FPS. This normal?
Yes. LÖVE enables vertical synchronization (vsync) by default which limits the frame rate to the refresh rate of the display. This is 60 Hz for most displays today.

You can change the setting with love.graphics.setMode, but the graphics driver can froce vsync on, off, or not support it at all. Keep this in mind while programming time-related game logic and animations.