Efficient Image Drawing

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.
thetree
Prole
Posts: 15
Joined: Sun Jan 08, 2012 10:22 pm

Efficient Image Drawing

Post 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
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Efficient Image Drawing

Post 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.
Kurosuke needs beta testers
thetree
Prole
Posts: 15
Joined: Sun Jan 08, 2012 10:22 pm

Re: Efficient Image Drawing

Post 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.
Last edited by thetree on Wed Feb 08, 2012 3:54 pm, edited 1 time in total.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Efficient Image Drawing

Post by tentus »

Yeah, nothing in that code looks like a problem. Odds are its the machine then.
Kurosuke needs beta testers
thetree
Prole
Posts: 15
Joined: Sun Jan 08, 2012 10:22 pm

Re: Efficient Image Drawing

Post 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 :)
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Efficient Image Drawing

Post by Ellohir »

Could you post a .love file so we can take a look anyway? I'm curious :nyu:
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Efficient Image Drawing

Post 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
User avatar
slime
Solid Snayke
Posts: 3147
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Efficient Image Drawing

Post 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.
thetree
Prole
Posts: 15
Joined: Sun Jan 08, 2012 10:22 pm

Re: Efficient Image Drawing

Post 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.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Efficient Image Drawing

Post 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.
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests