'egui glow image black screen
pub struct FrameBuffer {
renderer_id: glow::Framebuffer,
color_attachment: glow::Texture,
//depth_attachment: glow::Texture,
width: u32,
height: u32,
samples: u32,
swap_chain_target: bool
}
impl FrameBuffer {
pub fn new(
gl: &glow::Context,
width: u32,
height: u32,
samples: u32,
swap_chain_target: bool
) -> FrameBuffer {
unsafe { assert_eq!(
unsafe { gl.get_error() },
glow::NO_ERROR,
"OpenGL error occurred!"
);
let frame_buffer = gl.create_framebuffer().unwrap();
gl.bind_framebuffer(glow::FRAMEBUFFER, Some(frame_buffer));
let color_attachment = gl.create_texture().unwrap();
gl.bind_texture(glow::TEXTURE_2D, Some(color_attachment));
gl.tex_image_2d(glow::TEXTURE_2D, 0, glow::RGBA8 as i32, width as i32, height as i32, 0, glow::RGBA, glow::UNSIGNED_BYTE, None);
gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MIN_FILTER, glow::LINEAR as i32);
gl.tex_parameter_i32(glow::TEXTURE_2D, glow::TEXTURE_MAG_FILTER, glow::LINEAR as i32);
gl.framebuffer_texture_2d(glow::FRAMEBUFFER, glow::COLOR_ATTACHMENT0, glow::TEXTURE_2D, Some(color_attachment), 0);
gl.bind_framebuffer(glow::FRAMEBUFFER, None);
assert_eq!(
unsafe { gl.get_error() },
glow::NO_ERROR,
"OpenGL error occurred!"
);
FrameBuffer {
renderer_id: frame_buffer,
color_attachment,
//depth_attachment,
width,
height,
samples,
swap_chain_target
}
}
}
Im trying to use a framebuffer to render to a texture that I can give to egui but it just gives a black screen
fn on_ui_update(&mut self, egui: &EguiGlow) {
let _timer = Timer::new("Editor::on_tick");
egui::SidePanel::left("my_side_panel").show(egui.ctx(), |ui| {
ui.heading("Hello World!");
if ui.button("Quit").clicked() {
//quit = true;
}
});
if self.frame_buffer.is_some() {
egui::Image::new(User(self.frame_buffer.as_ref().unwrap().unwrap_color_attachment() as u64), egui::Vec2::new(1200.0, 720.0));
}
}
i bind it before my draw calls
fn on_tick(&mut self, renderer: &mut Renderer) {
if self.frame_buffer.is_none() {
self.frame_buffer = Some(FrameBuffer::new(renderer.borrow_context(), 800, 600, 1 ,false));
}
self.frame_buffer.as_mut().unwrap().bind(renderer.borrow_context());
let _timer = Timer::new("SandBox::on_tick");
self.camera_controller.on_tick();
self.camera_controller.get_camera().recalculate_matrix();
renderer.clear();
renderer.begin(&self.camera_controller.get_camera());
renderer.draw_quad(glm::vec3(0.0, 0.0, 0.0), glm::vec2(4.0, 4.0), &mut self.checker_board_texture);
for y in 0..20 {
for x in 0..20 {
let pos = glm::vec3(-0.5 + (x as f32) * 0.11, -0.5 + (y as f32) * 0.11, 0.0);
renderer.draw_flat_color_quad(pos, glm::vec3(0.1, 0.1, 0.1),glm::vec4((x as f32) / 20.0, 0.0, (y as f32) / 20.0, 1.0));
}
}
renderer.draw_quad(glm::vec3(0.1, 0.1, 0.1), glm::vec2(0.1, 0.1), &mut self.cherno_logo_texture);
renderer.end();
self.frame_buffer.as_mut().unwrap().unbind(renderer.borrow_context());
}
What I've done looks like its in line with https://learnopengl.com/Advanced-OpenGL/Framebuffers except for RGBA instead of RGB
gl.get_error has no error and the only thing printed by my debug callback is
source: 33350, error_type: 33361, id: 131185, severity: 33387, message: Buffer detailed info: Buffer object 1 (bound to GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (0), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (1), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (2), and GL_ARRAY_BUFFER_ARB, usage hint is GL_STREAM_DRAW) will use VIDEO memory as the source for buffer object operations.
source: 33350, error_type: 33361, id: 131185, severity: 33387, message: Buffer detailed info: Buffer object 2 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_STREAM_DRAW) will use VIDEO memory as the source for buffer object operations.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|