1
\$\begingroup\$

In regards to gdx.graphics, what is the difference between using getWidth and getHeight, and using getBackBufferWidth and getBackBufferHeight?


I am learning LibGDX and Java. I programmed formerly in pygame. To my knowledge, getBackBuffer means the width and height of the actual window. Is that true?

\$\endgroup\$
  • \$\begingroup\$ The backbuffer doesn't have to be the same size as the window (although it typically is). Disclaimer: I don't know LibGDX; this statement comes from my knowledge of Direct3D where this is the case, hence a comment and not an answer. \$\endgroup\$ – Maximus Minimus Jan 9 '17 at 16:10
1
\$\begingroup\$

The documentation explains it. getWidth and getHeight return the size of the client area (this is generally the usable portion of your game window). getBackBufferWidth and getBackBufferHeight return the size of the frame buffer, where actual drawing happens before it's presented to the window.

Sometimes these values differ; for example you might render to frame buffer that is smaller than the window and let presentation to the window upsample it, to achieve a "pixelated" effect. Similarly you might use a larger frame buffer and let it downsample to achieve a crude anti-aliasing effect.

You can look at the source to verify this; note that the specifics of the behavior of the functions differ based on which backend ends up being used. For example, compare this implementation with this one.

\$\endgroup\$
  • \$\begingroup\$ I would generally advice to only refer to the backbuffer when the need to know size exists. Calculating or reacting to backbuffer size will never lead to errors, only to pixelated or wrongly scaled content but never out of bounds as could happen with GetWidth/Height. \$\endgroup\$ – Yosh Synergi Sep 9 '17 at 23:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.