What's a "power of two"?

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.
Post Reply
Xoria
Citizen
Posts: 61
Joined: Sun Jan 31, 2010 1:24 am

What's a "power of two"?

Post 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.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

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

Post 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.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Xoria
Citizen
Posts: 61
Joined: Sun Jan 31, 2010 1:24 am

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

Post by Xoria »

Ohhhhh, so it's that straight forward, Thank you!
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post 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. ;)
Help us help you: attach a .love.
Ilukha
Prole
Posts: 2
Joined: Wed Feb 17, 2010 4:03 pm

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

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

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

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

Who is online

Users browsing this forum: Google [Bot] and 4 guests