shmolyneaux / imgui_gfx_example

Another imgui / gfx example for rustlang
7 stars 0 forks source link

render to texture #1

Open bekraoui opened 5 years ago

bekraoui commented 5 years ago

hello, i'm new to Rust & gfx-rs, i' want to render to a texture and use that texture as an image to imgui , after several hours :-) i have created a texture using factory.view_texture_as_render_target successufully but i don't know how to use it as texture in imgui; ( ps : i have done this once using c++ as https://gamedev.stackexchange.com/questions/140693/how-can-i-render-an-opengl-scene-into-an-imgui-window?rq=1 )

what i have done until now:

/*start of code*/

//let _depth = factory.create_depth_stencil_view_only(width as u16, height as u16).unwrap();

let levels = 1;
let kind = gfx::texture::Kind::D2(width as u16, height as u16, gfx::texture::AaMode::Single);
//providing the storage configuration and requesting the capabilities
let texture_buf = factory.create_texture::<gfx::format::R8_G8_B8_A8>(kind, levels,  gfx::memory::Bind::SHADER_RESOURCE |  gfx::memory::Bind::RENDER_TARGET,  gfx::memory::Usage::Data, None).unwrap();

// creating an RTV for level 0
let target_tex = factory.view_texture_as_render_target::<ColorFormat>(&texture_buf, 0, None).unwrap();      

// creating an SRV for the whole mipmap range
let resource_tex = factory.view_texture_as_shader_resource::<ColorFormat>(&texture_buf, (0, levels-1), gfx::format::Swizzle::new()).unwrap(); 

/*end of code*/

thank you. more ressources: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/

bekraoui commented 5 years ago

it would be nice if i can put the triangle inside an imgui window