Module conrod::backend::piston::window [] [src]

This code is adapted from the piston_window crate for convenience when using the piston window API with a conrod app.

Provides a simple API over the gfx graphics backend and the glutin window context and events.

Sets up:

Example

extern crate conrod;
extern crate graphics;

use conrod::backend::piston::{self, Window, WindowEvents};
use graphics::*;

fn main() {
    let mut window: Window =
        piston::window::WindowSettings::new("Hello World!", [512; 2])
            .build().unwrap();
    let mut events = WindowEvents::new();
    while let Some(e) = window.next_event(&mut events) {
        window.draw_2d(&e, |c, g| {
            clear([0.5, 0.5, 0.5, 1.0], g);
            rectangle([1.0, 0.0, 0.0, 1.0], // red
                      [0.0, 0.0, 100.0, 100.0], // rectangle
                      c.transform, g);
        });
    }
}

Swap to another window back-end

Change the generic parameter to the window back-end you want to use.

This example is not tested
extern crate conrod;
extern crate sdl2_window;

use conrod::backend::piston::{self, Window};
use sdl2_window::Sdl2Window;


let window: Window<Sdl2Window> =
    piston::window::WindowSettings::new("title", [512; 2])
        .build().unwrap();

sRGB

The impl of BuildFromWindowSettings in this library turns on WindowSettings::srgb, because it is required by gfx_graphics.

Most images such as those found on the internet uses sRGB, that has a non-linear gamma corrected space. When rendering 3D, make sure textures and colors are in linear gamma space. Alternative is to use Srgb8 and Srgba8 formats for textures.

For more information about sRGB, see https://github.com/PistonDevelopers/piston/issues/1014

Re-exports

pub use super::gfx::draw;
pub use super::gfx::GlyphCache;

Structs

Position

Structure to store the window position.

Size

Structure to store the window size.

Window

Contains everything required for controlling window, graphics, event loop.

WindowEvents

An event loop iterator

WindowSettings

Settings structure for window behavior.

Traits

AdvancedWindow

Trait representing a window with the most features that are still generic.

BuildFromWindowSettings

Constructs a window from a WindowSettings object.

EventWindow

Used to integrate a window with an event loop, enables the window to handle some events, if necessary

OpenGLWindow

Trait for OpenGL specific operations on a window.

Functions

convert_event

Converts any GenericEvent to a Raw conrod event.