title: How can I render an gfx-rs (opengl) scene into an ImGui-rs window?
body: <p>i'm new to Rust &amp; gfx-rs, i' want to render to a texture and use that texture as an image to imgui , after several houres :-) 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 <a href="https://gamedev.stackexchange.com/questions/140693/how-can-i-render-an-opengl-scene-into-an-imgui-window?rq=1">https://gamedev.stackexchange.com/questions/140693/how-can-i-render-an-opengl-scene-into-an-imgui-window?rq=1</a> )</p>
  
  <p>Actually that's what I want to do, and I tried it but it doesn't work. It seems the textures are not considered the same type (or mybe i did it the wrong way: as i'm beginner to rust), I would apreciate if take a look at the code below , maybe you can give me other sugestion.
  Ps: in c++ it uses pointers. But in rust i'm not very used to the typing system.</p>
  
  <p>it is based on this example : <a href="https://github.com/WimbledonLabs/imgui_gfx_example" rel="nofollow noreferrer">https://github.com/WimbledonLabs/imgui_gfx_example</a>
  thank you</p>
  
  <pre><code>pub fn main() {
      let mut events_loop = glutin::EventsLoop::new();
      //window &amp;&amp; glcontext
      let windowbuilder = glutin::WindowBuilder::new()
          .with_title("Triangle Example".to_string())
          .with_dimensions(LogicalSize::from((512, 512)));
  
      let contextbuilder = glutin::ContextBuilder::new()
          .with_gl(GlRequest::Specific(OpenGl, (3, 2)))
          .with_vsync(true);
      let (window, mut device, mut factory, mut color_view, mut depth_view) =
          gfx_glutin::init::&lt;ColorFormat, DepthFormat&gt;(
              windowbuilder,
              contextbuilder,
              &amp;events_loop,
          );
  
  
      let sampler = factory.create_sampler_linear();
      let texture = gfx_load_texture(&amp;mut factory);
  
      let (vertex_buffer, slice) =
          factory.create_vertex_buffer_with_slice(&amp;TRIANGLE, ());
      let transform_buffer = factory.create_constant_buffer(1);
  
  
  
  
  
  
  let viewer_size = (200, 200);
  let (width, height) = viewer_size;
  
  //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::&lt;gfx::format::R8_G8_B8_A8&gt;(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::&lt;ColorFormat&gt;(&amp;texture_buf, 0, None).unwrap();      
  
  // creating an SRV for the whole mipmap range
  let mut resource_tex = factory.view_texture_as_shader_resource::&lt;ColorFormat&gt;(&amp;texture_buf, (0, levels-1), gfx::format::Swizzle::new()).unwrap(); 
  
  
  
  
  
  
      let data = pipe::Data {
          vbuf: vertex_buffer,
          tex: (texture, sampler),
          transform: transform_buffer,
          //out: color_view.clone(),
          out: target_tex,
      };
  
  
  let mut text_for_imgui = imgui::Textures::new();
  let texture_for_imgui = text_for_imgui.insert(&amp;texture_buf);
  .
  .
  .
  let ui = imgui.frame(frame_size, delta_s);
  ui.image(texture_for_imgui , img_size);
  .
  .
  .
  </code></pre>