LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: CmSID on March 21, 2014, 11:18:18

Title: Display.getHeight() problem
Post by: CmSID on March 21, 2014, 11:18:18
Hi, this is my first post in this forum.

I have a problem with Display.getHeight()
It's working perfectly, until I create a window which is more than 883 pixels in height, ie: I created a 1600x900 display, but the biggest value ever returned by getHeight() is 883.

I also tried it with other values like 1000x1000.

Here's the stripped down version of the code
package screenheight;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

public class ScreenHeight {

public static void main(String[] args) {

try {
Display.setDisplayMode(new DisplayMode(1600, 900));
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}

System.out.println(Display.getWidth() + "\t" + Display.getHeight());

while(!Display.isCloseRequested()) {

Display.update();
Display.sync(60);
}
}

}


The console prints "1600   883"
Am I doing something wrong?
Title: Re: Display.getHeight() problem
Post by: imber on March 22, 2014, 09:03:40
It might be that your monitor has a max height of 900 or something.

I ran your code on my laptop which has a resoultion of 1366 x 768 and the width and height printed were 1372 751 so I guess it only shows what is displayed on the screen. The Display#getWidth() calls the parent, which is java.awt.Canvas's getWidth/getHeight method but I didn't see anything in the docs about a component going offscreen.

If you want the actual size then you could call Display.getDisplayMode().getWidth()/getHeight()
Title: Re: Display.getHeight() problem
Post by: CmSID on March 22, 2014, 12:19:41
Thanks! Your solution worked.

My monitor does indeed support the maximum of 900 in height, but I would still expect Display.getHeight() to return 900 (unless it takes the taskbar and the window header into account?).

Unfortunately, the real problem I had was with the Mouse.getY(). My origin is in the top left corner of the screen, so I used
Display.getHeight() - Mouse.getY() - 1
to get the mouse Y. It didn't work properly, so I looked around and found this (solved) problem about Display.getHeight(). I thought that's the source of the problem, but now that it's fixed:
Display.getDisplayMode() - Mouse.getY() - 1
The problem with the mouse still persists :( I think Mouse.getY() may be calling hava.awt.Canvas too?

The problem with the mouse is that it works ok at the bottom of the screen, but the closer it is to the top, the more inaccurate it is (on the Y axis). This does not happen in fullscreen. Would this also have any solution?
Title: Re: Display.getHeight() problem
Post by: imber on March 22, 2014, 17:57:48
I am pretty sure the task bar affects the height, I tried hiding the task bar but it still printed out as 751 instead of 768.

I tested out what your y problem could be and I came up with this (I'm not sure if this is what you're saying) -
My monitor is 1366 x 768 and I set the display mode to 1600 x 900 and used (Display.getDisplayMode().getHeight() - Mouse.getY() - 1) to get the y coordinate but it had an offset of about 150 at the very top. This is because Mouse.getY() gets the mouse coordinate within the Display.getWidth() and Display.getHeight() boundary and not the specified 1600 x 900. When I called Display.getHeight() it printed 751, so using displayMode.getHeight() - Mouse.getY() - 1 would return (900 - 751 - 1) which is 150 at the very top.

If you really want it to be accurate then you could do something like:
int height = Display.getDisplayMode().getHeight();
int diff = height - Display.getHeight();
int y = height - Mouse.getY() - diff - 1;

but you're probably be best setting the display at fullscreen or at least one that is less than your maximum display.getWidth(), which is 883, for now.
Title: Re: Display.getHeight() problem
Post by: CmSID on March 22, 2014, 18:02:28
That's what I thought... Anyway, thanks for the help! I'll see what I can do from here onwards  ;D