Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGDX - How does Gdx.graphics.getWidth() return the width of the display surface?

I want to understand more about inside world of LibGDX.

For example inside Graphics.java, I find the following:

/** @return the width in pixels of the display surface */ 
public int getWidth (); 

However, I can't find the source code of getWidth() method.

Where can I find the getWidth() method source code?

like image 906
user1232250 Avatar asked Jan 09 '23 14:01

user1232250


1 Answers

There is a different implementation of that interface for each of the available backends/platforms.

  • AndroidGraphics: For the Android backend.
  • LwjglGraphics: For the desktop backend.
  • GwtGraphics: For the browser backend
  • IOSGraphics: for the iOS backend.
  • MockGraphics: for the server backend.
  • JglfwGraphics: for the alternative desktop backend.

In the LWJGL backend, the implementation looks like this for example:

public int getWidth () {
    if (canvas != null)
        return Math.max(1, canvas.getWidth());
    else
        return (int)(Display.getWidth() * Display.getPixelScaleFactor());
}

The actual implementation is delegated once more to either the AWT Canvas, or the LWJGL Display.

The general idea behind these kind of interfaces can be found everywhere in LibGDX. You can also do platform specific code yourself. It is descibed in the wiki.

like image 140
noone Avatar answered Jan 17 '23 07:01

noone