Page 1 of 1

What's a "power of two"?

Posted: Tue Feb 02, 2010 12:23 am
by Xoria
To get rid of those white blocks when loading an img ,

somebody w/ the same question said that this can help:

Code: Select all

local mc, ml = math.ceil, math.log
local ml2inv = 1/ml(2)
nx = mc(ml(x)*ml2inv)
ny = mc(ml(y)*ml2inv)
from this topic: http://love2d.org/forum/viewtopic.php?f ... ite#p10585

It's a bit vague, and how can this code get rid of those white boxes precisely? Where in a code like

Code: Select all

ball=love.graphics.newImage('redball.png')
function love.draw()
  love.graphics.draw(ball,200,200)
end
this can I incorperate it? Thanks much.

Re: What's a "power of two"?

Posted: Tue Feb 02, 2010 1:37 am
by Taehl
A power of two is a number that's made by multiplying 2 by 2 some number of times. The powers of two are 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, and so on. Graphics cards prefer textures with dimensions which are powers of two. Some graphics cards actually can't handle anything else.

So, the easiest way to fix your graphics problems would be to resize your image to a power of two. For instance, if the image is 100x200 pixels, make it 128x256.

Re: What's a "power of two"?

Posted: Tue Feb 02, 2010 4:07 am
by Xoria
Ohhhhh, so it's that straight forward, Thank you!

Re: What's a "power of two"?

Posted: Tue Feb 02, 2010 5:24 pm
by Robin
And if you don't like to resize all your images, you can put this file in your project folder:
padding.lua
(583 Bytes) Downloaded 231 times
, add this line at the start of main.lua:

Code: Select all

require "padding"
and you're done. ;)

Re: What's a "power of two"?

Posted: Wed Feb 17, 2010 4:12 pm
by Ilukha
Robin wrote:And if you don't like to resize all your images, you can put this file in your project folder...
Cool stuff! Is there any reason for padding to not to be done implicitly in the code? The lack of padding makes most Love demos fail on some integrated graphics cards :roll:

Re: What's a "power of two"?

Posted: Wed Feb 17, 2010 6:22 pm
by Robin
Ilukha wrote:Cool stuff! Is there any reason for padding to not to be done implicitly in the code? The lack of padding makes most Love demos fail on some integrated graphics cards :roll:
Before 0.6, this was the case, but it caused some trouble with aligning and rotating images (and maybe more).