Integrating LEXSDL in a existing project is easy.
The only thing necessary is having access to the raw SDL_Window and SDL_Renderer.
Bellow are examples on how to do it.
The functions to be used are:
This example can be run after clonning the repo as "make integrating"
This example can be run after clonning the repo as "cargo run --example integrating"
use lexsdl::*;
fn main(){
// initialize sdl
let sdl_context = sdl2::init().unwrap();
let video_subsystem = sdl_context.video().unwrap();
// create window and canvas
let window = video_subsystem.window("LEXSDL Rust Example - integrating", 800,600).position_centered().build().unwrap();
let mut canvas = window.into_canvas().build().unwrap();
// to integrate
unsafe {
// get the window pointer out of the canvas and set it.
LEXSDL_SetWindow(canvas.window_mut().raw());
// get the renderer pointer out of the canvas and set it.
LEXSDL_SetRenderer(canvas.raw());
}
// now LEXSDL can be normally used.
unsafe {
// set the backgroud to a lime color.
LEXSDL_SetBackgroundColor(0x7D,0xBF,0x2F,0xFF);
// and render
LEXSDL_NewFrame();
LEXSDL_ShowFrame();
}
// sleep for 3 seconds before exiting.
std::thread::sleep(std::time::Duration::from_secs(3));
}