Window one pixel higher than expected

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
User avatar
Foppy
Prole
Posts: 11
Joined: Mon Aug 28, 2017 8:50 pm
Location: Netherlands
Contact:

Window one pixel higher than expected

Post 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. :)
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Window one pixel higher than expected

Post 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.
User avatar
Foppy
Prole
Posts: 11
Joined: Mon Aug 28, 2017 8:50 pm
Location: Netherlands
Contact:

Re: Window one pixel higher than expected

Post 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)
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Window one pixel higher than expected

Post 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.
User avatar
Foppy
Prole
Posts: 11
Joined: Mon Aug 28, 2017 8:50 pm
Location: Netherlands
Contact:

Re: Window one pixel higher than expected

Post 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!
Post Reply

Who is online

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