Expand description
§Getting started
extern crate sdl2;
use sdl2::pixels::Color;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use std::time::Duration;
pub fn main() {
let sdl_context = sdl2::init().unwrap();
let video_subsystem = sdl_context.video().unwrap();
let window = video_subsystem.window("rust-sdl2 demo", 800, 600)
.position_centered()
.build()
.unwrap();
let mut canvas = window.into_canvas().build().unwrap();
canvas.set_draw_color(Color::RGB(0, 255, 255));
canvas.clear();
canvas.present();
let mut event_pump = sdl_context.event_pump().unwrap();
let mut i = 0;
'running: loop {
i = (i + 1) % 255;
canvas.set_draw_color(Color::RGB(i, 64, 255 - i));
canvas.clear();
for event in event_pump.poll_iter() {
match event {
Event::Quit {..} |
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
break 'running
},
_ => {}
}
}
// The rest of the game loop goes here...
canvas.present();
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60));
}
}
Re-exports§
Modules§
- audio
- Audio Functions
- clipboard
- controller
- cpuinfo
- event
- Event Handling
- filesystem
- gfx
- A binding for the library
SDL2_gfx
- haptic
- Haptic Functions
- hint
- image
- A binding for the library
SDL2_image
- joystick
- keyboard
- log
- messagebox
- mixer
- A binding for the library
SDL2_mixer
- mouse
- pixels
- rect
- Rectangles and points.
- render
- 2D accelerated rendering
- rwops
- surface
- timer
- touch
- ttf
- A binding for the library
SDL2_ttf
- url
- Opening URLs in default system handlers
- version
- Querying SDL Version
- video
Structs§
- Audio
Subsystem - Event
Pump - A type that encapsulates SDL event-pumping functions.
- Event
Subsystem - Game
Controller Subsystem - Haptic
Subsystem - Joystick
Subsystem - Sdl
- The SDL context type. Initialize with
sdl2::init()
. - Sensor
Subsystem - Timer
Subsystem - Video
Subsystem
Enums§
- Error
- Integer
OrSdl Error - A given integer was so big that its representation as a C integer would be negative.
Functions§
- clear_
error - get_
error - get_
platform - Get platform name
- init
- Initializes the SDL library. This must be called before using any other SDL function.
- set_
error - set_
error_ from_ code