Pixel offset

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
chrism
Prole
Posts: 21
Joined: Wed May 25, 2011 6:17 pm

Pixel offset

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

Re: Pixel offset

Post 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.
Kurosuke needs beta testers
chrism
Prole
Posts: 21
Joined: Wed May 25, 2011 6:17 pm

Re: Pixel offset

Post 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...
User avatar
miloguy
Prole
Posts: 32
Joined: Sat Jul 02, 2011 2:09 am

Re: Pixel offset

Post by miloguy »

I'm pretty sure the offset thing is common for anti-alias drawing. HTML5 canvas uses it
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 65 guests