2
\$\begingroup\$

I want to design a very simple GUI for my game using OpenGL.

So far, every GUI implementation I have seen uses pixel space coordinates ( x range 0.0 to screen width and y 0.0 to screen height)

Why aren't they simply using screen space coordinates ? ( x and y range -1 to 1)

With screen space coordinates we would'nt have any issue with screen resizing, plus we won't have to transform coordinates for OpenGL since we use same space.

So why every GUI engine uses pixel space ?

\$\endgroup\$
1
  • \$\begingroup\$ You still have issues with screen resizing, just different issues. \$\endgroup\$ Commented May 8, 2016 at 5:49

1 Answer 1

6
\$\begingroup\$

Why aren't they simply using screen space coordinates ? ( x and y range -1 to 1)

Because generally, it's easier for people to reason about (and make adjustments with) whole numbers. If you were to describe your entire UI in -1 to 1 or 0 to 1 ranges, you'd frequently be dealing with values like 0.4827 and 0.188881881. In addition to being more difficult to visualize, these values are potentially subject to all the representational issues floats have with respect to holding certain values or round-tripping through serialized formats precisely.

It's perfectly viable to choose to describe your UI in screen space coordinates, however...

With screen space coordinates we would'nt have any issue with screen resizing,

...this is not true. You don't really solve anything by using screen space coordinates. The major issues you tend to run into have to do with aspect ratio and scaling the art. These remain problems even if you use a screen space representation.

plus we won't have to transform coordinates for OpenGL since we use same space.

This isn't really true either; OpenGL is still going to do the transformations even if those transformations are effectively identity transforms. Even if they are skipped in some fashion, this is an extreme nano-optimization that's not likely to matter one bit in real-world applications.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .