Page 1 of 1

Window one pixel higher than expected

Posted: Thu Sep 21, 2017 11:01 pm
by Foppy
In the game I am writing a window mode is set like this:

Code: Select all

love.window.setMode(1024,768)
It seems that the window is one pixel higher than expected. Since the top row is at y = 0, I thought the bottom row should be y = 767. But drawing a horizontal line at y = 767 still leaves a line of pixels below it. (Which can be filled by drawing a line at y = 768.) It can be worked around in the game but I wondered if I am missing something or that this is a known thing. :)

Re: Window one pixel higher than expected

Posted: Thu Sep 21, 2017 11:08 pm
by raidho36
I've actually measured the window size and it's exactly what it was set to. You're probably misunderstanding the render coordinates.

Re: Window one pixel higher than expected

Posted: Thu Sep 21, 2017 11:36 pm
by Foppy
Thank you, you are correct in that the window is of the requested height. I didn't think of checking it like that!

The problem or my confusion then seems to be in how the line is drawn using love.graphics.line().

The following still leaves a row of empty pixels below the line:

Code: Select all

love.graphics.setLineStyle("rough")
love.graphics.setLineWidth(1)
love.graphics.setColor(255,0,0)
love.graphics.line(0,767,1024,767)

Re: Window one pixel higher than expected

Posted: Thu Sep 21, 2017 11:40 pm
by grump
It's exactly what it should be for me too (Linux, LÖVE 10.2).

In theory, coordinates for points and lines should be offset by 0.5 for correct rendering, because you're supposed to specify the pixel centers. As far as I understand, a line from (0, 767) to (1023, 767) should be drawn as

Code: Select all

love.graphics.line(0.5, 767.5, 1023.5, 767.5)
But ONLY points and lines, and line rectangles; not text, filled rectangles, images or other primitives(?); I'm not entirely sure though; it's a little bit confusing, tbh.

Re: Window one pixel higher than expected

Posted: Thu Sep 21, 2017 11:45 pm
by Foppy
you're supposed to specify the pixel centers
This explains it! I ran into this because I am writing a pseudo 3d racing game which consists mostly of horizontal lines and saw a few unexpected empty lines. Thanks for your help!