Page 1 of 1
Pixel offset
Posted: Tue Aug 23, 2011 6:25 pm
by chrism
Why are pixels offset by 0.5? What are all the functions affected by this? Is it just the "drawing" functions?
Here's what I'm talking about. Only the middle line (the one offset by 0.5) in the following code is one pixel wide and the correct color.
Code: Select all
function love.draw()
love.graphics.setColor(0,255,0,255)
love.graphics.line(0,0,0,150)
love.graphics.line(0.5,150,0.5,300)
love.graphics.line(1,300,1,450)
end
edit- is there anything wrong with doing a love.graphics.translate(0.5, 0.5) at the top of every draw() ?
Re: Pixel offset
Posted: Tue Aug 23, 2011 6:43 pm
by tentus
If two line tips are on an even grid coord (imagine a vertical line for simplicity), then half the line has to be to one side of the coord, and the other half will be on the other side. So, a 1 pixel wide line will half half a pixel to the left of the grid, and half a pixel to the right. A 2 pixel wide line would have 1 pixel to each side.
There's nothing wrong with a translate at the beginning of each draw statement. Most camera systems in Love rely heavily on this.
Re: Pixel offset
Posted: Tue Aug 23, 2011 8:45 pm
by chrism
tentus wrote:If two line tips are on an even grid coord (imagine a vertical line for simplicity), then half the line has to be to one side of the coord, and the other half will be on the other side. So, a 1 pixel wide line will half half a pixel to the left of the grid, and half a pixel to the right. A 2 pixel wide line would have 1 pixel to each side.
There's nothing wrong with a translate at the beginning of each draw statement. Most camera systems in Love rely heavily on this.
I guess that makes sense, although it still seems "weird" to me. I'm guess I'm used to the coordinates being the pixels themselves, not something overlaid on top of them.
How does this affect blits? If I blit something say at (1,1) and want to draw a box around it, should it be at (0.5,0.5) to start? Or, if you blit something at (1,1), does that put half of the first row/col of the image on one side of (1,1) and the other half on the other side? That's why this seems confusing to me...
Re: Pixel offset
Posted: Sat Aug 27, 2011 4:46 am
by miloguy
I'm pretty sure the offset thing is common for anti-alias drawing. HTML5 canvas uses it