Module dmc::display [] [src]

The platform's display backend, windows, and OpenGL.

This module is not directly related to 2D/3D rendering (unlike the Graphics module) - rather, it is here to provide handle(s) to the platform-specific display backend (analoguous to SDL2's video subsystem), from which one can create potentially OpenGL-enabled windows.

There are a few features that some targets (such as mobile OSes, browser environnments and consoles) might not support :

  • Multiple display contexts (Display objects);
  • Multiple windows;
  • Some operations on windows such as resizing.

When appropriate, the use of such features either reports errors you can handle, or fails silently, depending on the case, but won't cause panics.

You are expected to at least "create" one window (which, on some targets, may actually just return the only window provided to your app), and have an event loop.

You might wonder what a Display is and why you would need one at all - the answer to this is : because it is the common denominator across all platforms, and it represents the minimum required information/context shared between windows. Other libs which provide you with "out-of-the-box" windows are actually hiding this in the name of ease of use.
On X11 for instance, a Display is a wrapper around an "X11 Display" object (which represents a connection to an X server) and some more data such as commonly-used X11 Atoms - but on other targets, it could very well be an empty struct which does nothing.

A nice consequence is also that OpenGL contexts are not implictly tied to a single window anymore. Rather, they are tied to a Display context (which is more correct), which allows you to have a single OpenGL context shared across windows, even though this might be discouraged.

Examples

Creating a window:

use dmc::display::{window, Display};
 
let display = Display::open()?;
let settings = window::Settings::from((800, 600));
let window = display.create_window(&settings)?;

Here, settings represents the absolute minimum information that needs to be known at window creation time (here, we use its From implementation which takes a fixed size and set all other fields to their target-specific default values, but if you want, you can initialize all of the fields one-by-one yourself).
Anything else, such as the window's title, is optional and can be set later.

window.set_title("Hello, display world!");

Then don't forget to show the window, because it makes sense for a window to be allocated but not "mapped" to the user's display.

window.show();

Creating an OpenGL context:

// default() will pick the best for the target platform,
// but keep in mind that you can tweak it at will.
let settings = display::GLContextSettings::default();
let gl = display.create_gl_context(&settings)?;

Rendering with OpenGL:

let swap_chain = gl.make_current(&window);
 
use display::GLSwapInterval::*;
// GLSwapInterval offers more options, go check them out!
if swap_chain.set_interval(LateSwapTearing).is_err() {
    if swap_chain.set_interval(VSync).is_err() {
        let _ = swap_chain.set_interval(LimitFps(60));
    }
}
 
'main_event_loop: loop {
    // Fetch and handle events...
    // glClear(...); ...
    // glDraw(...); ...
    swap_chain.present();
}

Modules

window

Module related to window initialization and management.

Structs

Display

A handle to the platform-specific display backend.

GLContext

Wrapper around a platform-specific OpenGL Context.

GLContextSettings

Settings requested for an OpenGL context.

GLMsaa
GLSwapChain

Handle to a window's ability to swap OpenGL buffers.

Enums

Error

Error types returned by this module.

GLProfile

Since OpenGL 3.2, the profile for an OpenGL context is either "core" or "compatibility".

GLSwapInterval

The interval at which OpenGL buffers are swapped.

GLVariant

Either Desktop GL or OpenGL ES.

GLVersion

Known OpenGL version numbers.

Requirement