CUGL 1.2
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
cugl::Display Class Reference

#include <CUDisplay.h>

Public Types

enum  Aspect : unsigned int {
  Aspect::SQUARE = 0, Aspect::PORTRAIT_3_4 = 1, Aspect::PORTRAIT_2_3 = 2, Aspect::PORTRAIT_10_16 = 3,
  Aspect::PORTRAIT_3_5 = 4, Aspect::PORTRAIT_9_16 = 5, Aspect::PORTRAIT_9_19p5 = 6, Aspect::PORTRAIT_600_1024 = 7,
  Aspect::PORTRAIT_IPAD_PRO_LARGE = 8, Aspect::PORTRAIT_IPAD_PRO_SMALL_2017 = 9, Aspect::PORTRAIT_IPAD_PRO_SMALL_2018 = 10, Aspect::LANDSCAPE_4_3 = 11,
  Aspect::LANDSCAPE_3_2 = 12, Aspect::LANDSCAPE_16_10 = 13, Aspect::LANDSCAPE_5_3 = 14, Aspect::LANDSCAPE_16_9 = 15,
  Aspect::LANDSCAPE_19p5_19 = 16, Aspect::LANDSCAPE_1024_600 = 17, Aspect::LANDSCAPE_IPAD_PRO_LARGE = 18, Aspect::LANDSCAPE_IPAD_PRO_SMALL_2017 = 19,
  Aspect::LANDSCAPE_IPAD_PRO_SMALL_2018 = 20, Aspect::UNKNOWN = 21
}
 
enum  Orientation : unsigned int {
  Orientation::FIXED = 0, Orientation::LANDSCAPE = 1, Orientation::PORTRAIT = 2, Orientation::LANDSCAPE_REVERSED = 3,
  Orientation::UPSIDE_DOWN = 4, Orientation::FACE_UP = 5, Orientation::FACE_DOWN = 6, Orientation::UNKNOWN = 7
}
 
typedef std::function< void(Orientation previous, Orientation current, bool display)> Listener
 

Public Member Functions

std::string getTitle () const
 
void setTitle (const std::string &title)
 
void setTitle (const char *title)
 
void show ()
 
void hide ()
 
Rect getBounds () const
 
Rect getPixelBounds () const
 
Rect getUsableBounds (bool display=true)
 
Vec2 getPixelDensity () const
 
Aspect getAspect () const
 
bool isLandscape () const
 
bool isPortrait () const
 
bool hasNotch () const
 
Orientation getInitialOrientation () const
 
Orientation getDisplayOrientation () const
 
Orientation getDeviceOrientation () const
 
bool hasOrientationListener () const
 
const Listener getOrientationListener () const
 
void setOrientationListener (Listener listener)
 
bool removeOrientationListener ()
 
float getAspectRatio () const
 
const std::string getAspectName () const
 
int widthForHeight (int height) const
 
int heightForWidth (int width) const
 
void refresh ()
 
bool prepareOpenGL (bool multisample)
 
bool initOpenGL (bool multisample)
 

Static Public Member Functions

static bool start (std::string title, Rect bounds, Uint32 flags)
 
static void stop ()
 
static Displayget ()
 
static Aspect getAspect (float ratio)
 
static float getAspectRatio (Aspect aspect)
 
static const std::string getAspectName (Aspect aspect)
 
static int widthForHeight (int height, Aspect aspect)
 
static int heightForWidth (int width, Aspect aspect)
 

Static Public Attributes

static Uint32 INIT_FULLSCREEN
 
static Uint32 INIT_HIGH_DPI
 
static Uint32 INIT_MULTISAMPLED
 
static Uint32 INIT_CENTERED
 

Protected Member Functions

 Display ()
 
bool init (std::string title, Rect bounds, Uint32 flags)
 
void dispose ()
 
 ~Display ()
 

Protected Attributes

std::string _title
 
SDL_Window * _window
 
SDL_GLContext _glContext
 
Aspect _aspect
 
Rect _bounds
 
Rect _usable
 
Vec2 _scale
 
bool _notched
 
Listener _orientationListener
 
Orientation _initialOrientation
 
Orientation _displayOrientation
 
Orientation _deviceOrientation
 

Static Protected Attributes

static Display_thedisplay
 

Friends

class Application
 

Detailed Description

This class is a singleton representing the native display.

The static methods of this class start() and stop() the SDL video system. Without it, you cannot draw anything. This should be the first and last methods called in any application. The Application class does this for you automatically.

The primary purpose of the display object is to initialize (and dispose) the OpenGL context. Any start-up features for OpenGL should go in this class. That are set via static attributes (like setFullscreen(bool) that are read by the method start(). Setting these attributes after the display has started will have no effect (though this may be a a feature for later releases).

The singleton display object also has several methods to get the (current) screen resolution and aspect ratio. The most important of these two is the the aspect ratio. Aspect ratio is one of the most unportable parts of cross-platform development. Everything else can be scaled to the screen, but the aspect ratio is fixed from the very beginning.

The singleton display also has information about the display and device orientation for mobile devices. In fact, is is possible to assign a listener to the object to respond to changes in device orientation.

If the device has multiple displays, this singleton will only refer to the main display.

Member Typedef Documentation

This type represents a listener for an orientation change.

In CUGL, listeners are implemented as a set of callback functions, not as objects. For simplicity, Displays only have a single listener that handles both display and device changes (see getDisplayOrientation() and getDeviceOrientation().) If you wish for more than one listener, then your listener should handle its own dispatch.

Since the device orientation will always change when the display orientation does, this callback can easily safely handle both. The boolean parameter in the callback indicates whether or not a display orientation change has happened as well.

Unlike other events, this callback will be invoked at the end of an animation frame, after the screen has been drawn. So it will be processed before any input events waiting for the next frame.

The function type is equivalent to

 std::function<void(Orientation previous, Orientation current, bool display)>
Parameters
previousThe previous device orientation (before the change)
currentThe current device orientation (after the change)
displayWhether the display orientation has changed as well

Member Enumeration Documentation

enum cugl::Display::Aspect : unsigned int
strong

The display aspect ratio.

This enum includes support for almost every shipping aspect rations. For information on your device, see

 https://www.mydevice.io/#compare-devices

With that said, Apple is making this impossible to keep up with, so it is unclear how much longer we will support this enum.

Enumerator
SQUARE 

Aspect ratio of 1:1

This is the aspect ratio of many early Blackberry devices.

PORTRAIT_3_4 

Portrait aspect ratio of 3:4

This is the portrait aspect ratio of most Apple iPads except for the iPad Pro.

PORTRAIT_2_3 

Portrait aspect ratio of 2:3

This is the portrait aspect ratio of older iPhones (before the 4s) and Microsoft Surface 3.

PORTRAIT_10_16 

Portrait aspect ratio of 10:16

This is the portrait aspect ratio of 8" and 10" Samsung tablets.

PORTRAIT_3_5 

Portrait aspect ratio of 3:5

This is the portrait aspect ratio of Samsung Galaxy S tablets.

PORTRAIT_9_16 

Portrait aspect ratio of 9:16

This is the portrait aspect ratio of almost all modern smart phones. This includes newer iPhones and Samsung phones.

PORTRAIT_9_19p5 

Portrait aspect ratio of 9:19.5

This is the portrait aspect ratio of iPhone X (including plus) models. However, this is includes the notch, which should be accounted for.

PORTRAIT_600_1024 

Portrait aspect ratio of 600:1024

This is an unusual portrait aspect ratio for the Kindle Fire tablet and the Samsung Galaxy 7.

PORTRAIT_IPAD_PRO_LARGE 

Portrait aspect ratio of 512:683

This is a unique portrait aspect ratio for the first generation (12.9") Apple iPad Pro, carried over to later generations.

PORTRAIT_IPAD_PRO_SMALL_2017 

Portrait aspect ratio of 417:556

This is a unique portrait aspect ratio for the first generation (10.5") Apple iPad Pro, which only lasted one year (sigh).

PORTRAIT_IPAD_PRO_SMALL_2018 

Portrait aspect ratio of 417:597

This is a unique portrait aspect ratio for the second generation (11") Apple iPad Pro, which has no home button.

LANDSCAPE_4_3 

Landscape aspect ratio of 4:3

This is the landscape aspect ratio of most Apple iPads except for the iPad Pro. It is also the standard definition TV aspect ratio.

LANDSCAPE_3_2 

Landscape aspect ratio of 3:2

This is the landscape aspect ratio of older iPhones (before the 4s) and Microsoft Surface 3.

LANDSCAPE_16_10 

Landscape aspect ratio of 16:10

This is the landscape aspect ratio of 8" and 10" Samsung tablets. It is also the aspect ratio of Apple desktop and notebook displays.

LANDSCAPE_5_3 

Landscape aspect ratio of 5:3

This is the landscape aspect ratio of Samsung Galaxy S tablets.

LANDSCAPE_16_9 

Landscape aspect ratio of 16:9

This is the landscape aspect ratio of almost all modern smart phones. This includes newer iPhones and Samsung phones. It is also the high definition TV aspect ratio.

LANDSCAPE_19p5_19 

Landscape aspect ratio of 19.5:9

This is the landscape aspect ratio of iPhone X (including plus) models. However, this is includes the notch, which should be accounted for.

LANDSCAPE_1024_600 

Landscape aspect ratio of 1024:600

This is an unusual landscape aspect ratio for the Kindle Fire tablet and the Samsung Galaxy 7.

LANDSCAPE_IPAD_PRO_LARGE 

Landscape aspect ratio of 683:512

This is a unique landscape aspect ratio for the first generation (12.9") Apple iPad Pro, carried over to later generations.

LANDSCAPE_IPAD_PRO_SMALL_2017 

Landscape aspect ratio of 556:417

This is a unique landscape aspect ratio for the first generation (10.5") Apple iPad Pro, which only lasted one year (sigh).

LANDSCAPE_IPAD_PRO_SMALL_2018 

Landscape aspect ratio of 597:417

This is a unique landscape aspect ratio for the second generation (11") Apple iPad Pro, which has no home button.

UNKNOWN 

The landscape aspect ratio is unknown

This is an error value for type safety. It evaluates to an aspect ration of 0.

enum cugl::Display::Orientation : unsigned int
strong

The possible device/display orientations.

We use the same orientations for device and display even though these may not always agree (such as when the user has locked the display)

Enumerator
FIXED 

The orientation that of a fixed display.

This is the orientation for desktops and laptops. This orientation will never change.

LANDSCAPE 

Landscape orientation with the right side up.

One notched devices, this will put the notch to the left. On devices with a home button, the button will be to the right.

PORTRAIT 

Standard portrait orientation

One notched devices, this will put the notch to the top. On devices with a home button, the button will be to the bottom.

LANDSCAPE_REVERSED 

Landscape orientation with the left side up.

One notched devices, this will put the notch to the right. On devices with a home button, the button will be to the left.

UPSIDE_DOWN 

Reversed portrait orientation

One notched devices, this will put the notch to the bottom. On devices with a home button, the button will be to the top.

Many devices (e.g. iPhones) do not allow this mode as it interferes with the camera and incoming calls.

FACE_UP 

The device is face up.

This is a device-only orientation, not a display orientation. Some devices will not report this orientation.

FACE_DOWN 

The device is face down.

This is a device-only orientation, not a display orientation. Some devices will not report this orientation.

UNKNOWN 

The orientation is unknown.

This is rarely ever reported, and may mean an issue with the accelerometer in the case of a mobile device.

Constructor & Destructor Documentation

cugl::Display::Display ( )
protected

Creates a new, unitialized Display.

All of the values are set to 0 or UNKNOWN, depending on their type. You must initialize the Display to access its values.

WARNING: This class is a singleton. You should never access this constructor directly. Use the start() method instead.

cugl::Display::~Display ( )
inlineprotected

Deletes this object, releasing all resources.

This method quits the SDL video system and disposes the OpenGL context, effectively exitting and shutting down the entire program.

WARNING: This class is a singleton. You should never access this destructor directly. Use the stop() method instead.

Member Function Documentation

void cugl::Display::dispose ( )
protected

Uninitializes this object, releasing all resources.

This method quits the SDL video system and disposes the OpenGL context, effectively exitting and shutting down the entire program.

WARNING: This class is a singleton. You should never access this method directly. Use the stop() method instead.

static Display* cugl::Display::get ( )
inlinestatic

Returns the singleton instance for the display

You must call this static method first to get information about your specific display. This method will return nullptr until start() is called first.

Returns
the singleton instance for the display
Aspect cugl::Display::getAspect ( ) const
inline

Returns the aspect of this monitor.

The aspect is returned as an enum, not a ratio. Round off error might cause devices with very similar aspect ratios to have slightly different ratio values. Therefore, the enum is a way of normalizing device aspects.

If you would like to know the actual ratio, use the method getAspectRatio() instead. In addition, there are methods for computing width from height and vice versa.

Device aspects are relatively standardized. For information on your device, see

 http://mydevice.io/devices/
Returns
the aspect of this monitor.
static Aspect cugl::Display::getAspect ( float  ratio)
static

Returns the aspect for the given aspect ratio.

It is safest to represent aspects as an enum, not a ratio. Round off error might cause devices with very similar aspect ratios to have slightly different ratio values. Therefore, the enum is a way of normalizing device aspects.

Device aspects are relatively standardized. For information on your device, see

 http://mydevice.io/devices/

This method is guaranteed to match every aspect ratio on that page. If the aspect ratio is not on that page, it will return UNKNOWN.

Parameters
ratioThe aspect ratio in the form width/height
Returns
the aspect for the given aspect ratio.
const std::string cugl::Display::getAspectName ( ) const
inline

Returns a string representation of the device aspect ratio

This value is useful for debugging. The first part of the string, before the space, is guaranteed to be in the format x:y

Returns
a string representation of the aspect ratio
static const std::string cugl::Display::getAspectName ( Aspect  aspect)
static

Returns a string representation of the given aspect

This value is useful for debugging. The first part of the string, before the space, is guaranteed to be in the format x:y

Parameters
aspectThe device aspect value
Returns
a string representation of the given aspect
float cugl::Display::getAspectRatio ( ) const
inline

Returns the device aspect ratio

The value is computed width/height.

Returns
the device aspect ratio
static float cugl::Display::getAspectRatio ( Aspect  aspect)
static

Returns the aspect ratio for the given aspect.

The value is computed width/height. If the aspect is UNKNOWN, it will return 0.

Parameters
aspectThe device aspect value
Returns
the aspect ratio for the given aspect.
Rect cugl::Display::getBounds ( ) const
inline

Returns the full screen resolution for this display in points.

This method returns the bounds for the current resolution, not the maximum resolution. You should never change the resolution of a display. Allow the user to have their preferred resolution. Instead, you should adjust your camera to scale the viewport.

The value returned represents points, not pixels. If you are using a traditional display, these are the same. However, on Retina displays and other high DPI monitors, these may be different. Regardless, you should always work with points, not pixels, when computing the screen size. In particular, this is what you should assign the OpenGL viewport when using fullscreen.

Returns
the full screen resolution for this display in points.
Orientation cugl::Display::getDeviceOrientation ( ) const
inline

Returns the current device orientation.

The device orientation is a mobile device, as held by the user. It may or may not agree with the display orientation, which is how the screen is drawn. For example, if the screen is locked to landscape orientation, it is still possible for the device to have portrait orientation when it is held on its side.

This method is useful when you want to switch game modes for a different orientation (e.g. Powerpuff Girls Flipped Out).

Returns
the current device orientation.
Orientation cugl::Display::getDisplayOrientation ( ) const
inline

Returns the current display orientation.

The display orientation is the orientation of the coordinate space. In other words, the origin is at the bottom left of the screen in this orientation.

This may or may not agree with the device orientation. In particular, it will not agree if the display orientation is locked (to say portrait or landscape only). However, this is the orientation that is important for drawing to the screen.

Returns
the current display orientation.
Orientation cugl::Display::getInitialOrientation ( ) const
inline

Returns the initial display orientation.

The display orientation is the orientation of the coordinate space. In other words, the origin is at the bottom left of the screen in this orientation. This value is the display orientation at startup.

This may or may not agree with the device orientation. In particular, it will not agree if the display orientation is locked (to say portrait or landscape only). However, this is the orientation that is important for drawing to the screen. To get the device orientation, call getDeviceOrientation().

Returns
the current display orientation.
const Listener cugl::Display::getOrientationListener ( ) const
inline

Returns the listener for the display orientation.

This listener handles changes in either the device orientation (see getDeviceOrientation() or the display orientation (see getDeviceOrientation(). Since the device orientation will always change when the display orientation does, this callback can easily safely handle both. The boolean parameter in the callback indicates whether or not a display orientation change has happened as well.

Unlike other events, this listener will be invoked at the end of an animation frame, after the screen has been drawn. So it will be processed before any input events waiting for the next frame.

The display may only have one orientation listener at a time. If there is no listener, this method returns nullptr.

Returns
the orientation listener (if any) for this display
Rect cugl::Display::getPixelBounds ( ) const
inline

Returns the full screen resolution for this display in pixels.

This method returns the bounds for the current resolution, not the maximum resolution. You should never change the resolution of a display. Allow the user to have their preferred resolution. Instead, you should adjust your camera to scale the viewport.

The value returned represents the value pixels, not points. This is to help align the results with input devices on Retina displays and other high DPI monitors.

Returns
the full screen resolution for this display in pixels.
Vec2 cugl::Display::getPixelDensity ( ) const
inline

Returns the number of pixels for each point.

A point is a logical screen pixel. If you are using a traditional display, points and pixels are the same. However, on Retina displays and other high dpi monitors, they may be different. In particular, the number of pixels per point is a scaling factor times the point.

You should never need to use these scaling factor for anything, as it is not useful for determining anything other than whether a high DPI display is present. It does not necessarily refer to physical pixel on the screen. In some cases (OS X Retina displays), it refers to the pixel density of the backing framebuffer, which may be different from the physical framebuffer.

Returns
the number of pixels for each point.
std::string cugl::Display::getTitle ( ) const
inline

Returns the title of this display

On a desktop, this title will be displayed at the top of the window.

Returns
the title of this display
Rect cugl::Display::getUsableBounds ( bool  display = true)

Returns the usable full screen resolution for this display in points.

Usable is a subjective term defined by the operating system. In general, it means the full screen minus any space used by important user interface elements, like a status bar (iPhone), menu bar (OS X), or task bar (Windows), or a notch (iPhone X). In the case of the latter, you can specify whether you want to use the display orientation or the device orientation.

This method computes the bounds for the current resolution, not the maximum resolution. You should never change the resolution of a display. Allow the user to have their preferred resolution. Instead, you should adjust your camera to scale the viewport.

The value returned represents points, not pixels. If you are using a traditional display, these are the same. However, on Retina displays and other high DPI monitors, these may be different. Regardless, you should always work with points, not pixels, when computing the screen size.

Parameters
displayWhether to use the display (as opposed to the device) orientation
Returns
the usable full screen resolution for this display in points.
bool cugl::Display::hasNotch ( ) const
inline

Returns true if this device has a notch.

Notched devices are edgeless smartphones or tablets that include at dedicated area in the screen for a camera. Examples include the iPhone X.

If a device is notched you should call getUsableDisplayBounds() before laying out UI elements. It is acceptable to animate and draw backgrounds behind the notch, but it is not acceptable to place UI elements outside of these bounds.

Returns
true if this device has a notch.
bool cugl::Display::hasOrientationListener ( ) const
inline

Returns true if this display has an orientation listener

This listener handles changes in either the device orientation (see getDeviceOrientation() or the display orientation (see getDeviceOrientation(). Since the device orientation will always change when the display orientation does, this callback can easily safely handle both. The boolean parameter in the callback indicates whether or not a display orientation change has happened as well.

Unlike other events, this listener will be invoked at the end of an animation frame, after the screen has been drawn. So it will be processed before any input events waiting for the next frame.

The display may only have one orientation listener at a time.

Returns
true if this display has an orientation listener
int cugl::Display::heightForWidth ( int  width) const
inline

Returns the closest height value for the device aspect ratio.

This value is used when you want to scale a viewpoint to match the display. The value returned is rounded up to the nearest int, assuming that you want the viewport in points.

Parameters
widthThe width in points
Returns
the closest height value for the device aspect ratio.
static int cugl::Display::heightForWidth ( int  width,
Aspect  aspect 
)
inlinestatic

Returns the closest height value for the given aspect

This value is used when you want to scale a viewpoint to match the display. The value returned is rounded up to the nearest int, assuming that you want the viewport in points.

Parameters
widthThe width in points
aspectThe device aspect value
Returns
the closest height value for the given aspect
void cugl::Display::hide ( )

Hides the window for this display (assuming it was visible).

This method does nothing if the window was not visible.

bool cugl::Display::init ( std::string  title,
Rect  bounds,
Uint32  flags 
)
protected

Initializes the display with the current screen information.

This method creates a display with the given title and bounds. As part of this initialization, it will create the OpenGL context, using the flags provided. The bounds are ignored if the display is fullscreen. In that case, it will use the bounds of the display.

This method gathers the native resolution bounds, pixel density, and orientation using platform-specific tools.

WARNING: This class is a singleton. You should never access this initializer directly. Use the start() method instead.

Parameters
titleThe window/display title
boundsThe window/display bounds
flagsThe initialization flags
Returns
true if initialization was successful.
bool cugl::Display::initOpenGL ( bool  multisample)

Initializes the OpenGL context

This has to be done after the Window is created.

Parameters
mutlisampleWhether to support multisampling.
Returns
true if initialization was successful
bool cugl::Display::isLandscape ( ) const
inline

Returns true if this device has a landscape orientation

Returns
true if this device has a landscape orientation
bool cugl::Display::isPortrait ( ) const
inline

Returns true if this device has a portrait orientation

Returns
true if this device has a portrait orientation
bool cugl::Display::prepareOpenGL ( bool  multisample)

Assign the default settings for OpenGL

This has to be done before the Window is created.

Parameters
mutlisampleWhether to support multisampling.
Returns
true if preparation was successful
void cugl::Display::refresh ( )

Refreshes the display.

This method will swap the OpenGL framebuffers, drawing the screen.

It will also reassess the orientation state and call the listener as necessary

bool cugl::Display::removeOrientationListener ( )

Removes the display orientation listener for this display.

This listener handles changes in either the device orientation (see getDeviceOrientation() or the display orientation (see getDeviceOrientation(). Since the device orientation will always change when the display orientation does, this callback can easily safely handle both. The boolean parameter in the callback indicates whether or not a display orientation change has happened as well.

Unlike other events, this listener will be invoked at the end of an animation frame, after the screen has been drawn. So it will be processed before any input events waiting for the next frame.

A display may only have one orientation listener at a time. If this display does not have an orientation listener, this method will fail.

Returns
true if the listener was succesfully removed
void cugl::Display::setOrientationListener ( Listener  listener)
inline

Sets the orientation listener for this display.

This listener handles changes in either the device orientation (see getDeviceOrientation() or the display orientation (see getDeviceOrientation(). Since the device orientation will always change when the display orientation does, this callback can easily safely handle both. The boolean parameter in the callback indicates whether or not a display orientation change has happened as well.

A display may only have one orientation listener at a time. If this display already has an orientation listener, this method will replace it for the once specified.

Unlike other events, this listener will be invoked at the end of an animation frame, after the screen has been drawn. So it will be processed before any input events waiting for the next frame.

Parameters
listenerThe listener to use
void cugl::Display::setTitle ( const std::string &  title)
inline

Sets the title of this display

On a desktop, the title will be displayed at the top of the window.

Parameters
titleThe title of this display
void cugl::Display::setTitle ( const char *  title)

Sets the title of this display

On a desktop, the title will be displayed at the top of the window.

Parameters
titleThe title of this display
void cugl::Display::show ( )

Shows the window for this display (assuming it was hidden).

This method does nothing if the window was not hidden.

static bool cugl::Display::start ( std::string  title,
Rect  bounds,
Uint32  flags 
)
static

Starts up the SDL display and video system.

This static method needs to be the first line of any application, though it is handled automatically in the Application class.

This method creates the display with the given title and bounds. As part of this initialization, it will create the OpenGL context, using the flags provided. The bounds are ignored if the display is fullscreen. In that case, it will use the bounds of the display.

Once this method is called, the get() method will no longer return a null value.

Parameters
titleThe window/display title
boundsThe window/display bounds
flagsThe initialization flags
Returns
true if the display was successfully initialized
static void cugl::Display::stop ( )
static

Shuts down the SDL display and video system.

This static method needs to be the last line of any application, though it is handled automatically in the Application class. It will dipose of the display and the OpenGL context.

Once this method is called, the get() method will return nullptr. More importantly, no SDL function calls will work anymore.

int cugl::Display::widthForHeight ( int  height) const
inline

Returns the closest width value for the device aspect ratio.

This value is used when you want to scale a viewpoint to match the display. The value returned is rounded up to the nearest int, assuming that you want the viewport in points.

Parameters
heightThe height in points
Returns
the closest width value for the device aspect ratio.
static int cugl::Display::widthForHeight ( int  height,
Aspect  aspect 
)
inlinestatic

Returns the closest width value for the given aspect

This value is used when you want to scale a viewpoint to match the display. The value returned is rounded up to the nearest int, assuming that you want the viewport in points.

Parameters
heightThe height in points
aspectThe device aspect value
Returns
the closest width value for the given aspect

Friends And Related Function Documentation

friend class Application
friend

This is called by the application loop

Member Data Documentation

Aspect cugl::Display::_aspect
protected

The aspect ratio (coded as the enum)

Rect cugl::Display::_bounds
protected

The full screen resolution of this device

Orientation cugl::Display::_deviceOrientation
protected

The value of the device orientation

Orientation cugl::Display::_displayOrientation
protected

The value of the display orientation

SDL_GLContext cugl::Display::_glContext
protected

The associated OpenGL drawing context

Orientation cugl::Display::_initialOrientation
protected

The value of the initial orientation

bool cugl::Display::_notched
protected

Whether this device has a notch in it

Listener cugl::Display::_orientationListener
protected

A listener for the orientation

Vec2 cugl::Display::_scale
protected

The pixel density of the device

Display* cugl::Display::_thedisplay
staticprotected

The display singleton

std::string cugl::Display::_title
protected

The title (Window name) of the display

Rect cugl::Display::_usable
protected

The full screen resolution minus menu bars and other features

SDL_Window* cugl::Display::_window
protected

The SDL window, which provides the OpenGL drawing context

Uint32 cugl::Display::INIT_CENTERED
static

Whether this display should be centered (on windowed screens)

Uint32 cugl::Display::INIT_FULLSCREEN
static

Whether this display should use the fullscreen

Uint32 cugl::Display::INIT_HIGH_DPI
static

Whether this display should support a High DPI screen

Uint32 cugl::Display::INIT_MULTISAMPLED
static

Whether this display should be multisampled


The documentation for this class was generated from the following file: