...am i getting the wrong object back in my Handler-dispatch code? i probably am.
This commit is contained in:
parent
33b3270c10
commit
d3f83c48c1
1 changed files with 14 additions and 60 deletions
|
@ -1,62 +1,3 @@
|
||||||
/*extern crate sdl2;
|
|
||||||
|
|
||||||
use sdl2::pixels::PixelFormatEnum;
|
|
||||||
use sdl2::rect::Rect;
|
|
||||||
use sdl2::event::Event;
|
|
||||||
use sdl2::keyboard::Keycode;
|
|
||||||
|
|
||||||
pub fn main() -> Result<(), String> {
|
|
||||||
let sdl_context = sdl2::init()?;
|
|
||||||
let video_subsystem = sdl_context.video()?;
|
|
||||||
|
|
||||||
let window = video_subsystem.window("rust-sdl2 demo: Video", 800, 600)
|
|
||||||
.position_centered()
|
|
||||||
.opengl()
|
|
||||||
.build()
|
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
|
|
||||||
let mut canvas = window.into_canvas().build().map_err(|e| e.to_string())?;
|
|
||||||
let texture_creator = canvas.texture_creator();
|
|
||||||
|
|
||||||
let mut texture = texture_creator.create_texture_streaming(PixelFormatEnum::RGB24, 256, 256)
|
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
// Create a red-green gradient
|
|
||||||
texture.with_lock(None, |buffer: &mut [u8], pitch: usize| {
|
|
||||||
for y in 0..256 {
|
|
||||||
for x in 0..256 {
|
|
||||||
let offset = y*pitch + x*3;
|
|
||||||
buffer[offset] = x as u8;
|
|
||||||
buffer[offset + 1] = y as u8;
|
|
||||||
buffer[offset + 2] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
|
|
||||||
canvas.clear();
|
|
||||||
canvas.copy(&texture, None, Some(Rect::new(100, 100, 256, 256)))?;
|
|
||||||
canvas.copy_ex(&texture, None,
|
|
||||||
Some(Rect::new(450, 100, 256, 256)), 30.0, None, false, false)?;
|
|
||||||
canvas.present();
|
|
||||||
|
|
||||||
let mut event_pump = sdl_context.event_pump()?;
|
|
||||||
|
|
||||||
'running: loop {
|
|
||||||
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...
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
extern crate rustro;
|
extern crate rustro;
|
||||||
extern crate sdl2;
|
extern crate sdl2;
|
||||||
|
|
||||||
|
@ -117,6 +58,7 @@ impl MyEmulator {
|
||||||
|
|
||||||
impl retro::convert::Handler for MyEmulator {
|
impl retro::convert::Handler for MyEmulator {
|
||||||
fn video_refresh(&mut self, data: &[u8], width: u32, height: u32, pitch: u32) {
|
fn video_refresh(&mut self, data: &[u8], width: u32, height: u32, pitch: u32) {
|
||||||
|
println!("self ref: {:?}", self as *mut Self);
|
||||||
//println!("video_refresh {}x{}", width, height);
|
//println!("video_refresh {}x{}", width, height);
|
||||||
//let rect = Rect::new(0, 0, width, height);
|
//let rect = Rect::new(0, 0, width, height);
|
||||||
if let Some(tex) = self.texture.as_mut() {
|
if let Some(tex) = self.texture.as_mut() {
|
||||||
|
@ -159,7 +101,9 @@ pub fn main() -> failure::Fallible<()> {
|
||||||
let mut canvas = window.into_canvas().build()?;
|
let mut canvas = window.into_canvas().build()?;
|
||||||
let texture_creator = canvas.texture_creator();
|
let texture_creator = canvas.texture_creator();
|
||||||
emu.texture = texture_creator.create_texture_streaming(emu.pixel_format, width, height).ok();
|
emu.texture = texture_creator.create_texture_streaming(emu.pixel_format, width, height).ok();
|
||||||
println!("{:?}", emu.texture.is_some());
|
|
||||||
|
let mut x: u8 = 1;
|
||||||
|
println!("emu ref: {:?}", &emu as *const MyEmulator);
|
||||||
|
|
||||||
let mut event_pump = sdl_context.event_pump().map_err(failure::err_msg)?;
|
let mut event_pump = sdl_context.event_pump().map_err(failure::err_msg)?;
|
||||||
'running: loop {
|
'running: loop {
|
||||||
|
@ -172,6 +116,16 @@ pub fn main() -> failure::Fallible<()> {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(tex) = emu.texture.as_mut() {
|
||||||
|
tex.with_lock(None, |tex_buffer: &mut [u8], tex_pitch: usize| {
|
||||||
|
for i in 0..tex_buffer.len() {
|
||||||
|
tex_buffer[i] = x;
|
||||||
|
x = (x + 1) % 255;
|
||||||
|
}
|
||||||
|
}).unwrap();
|
||||||
|
//tex.update(None, data, pitch as usize).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
// The rest of the game loop goes here...
|
// The rest of the game loop goes here...
|
||||||
emu.run();
|
emu.run();
|
||||||
canvas.clear();
|
canvas.clear();
|
||||||
|
|
Loading…
Add table
Reference in a new issue