diff --git a/src/glium_renderer.rs b/src/glium_renderer.rs index f113199..2338b7d 100644 --- a/src/glium_renderer.rs +++ b/src/glium_renderer.rs @@ -1,10 +1,12 @@ use glium::{ index, program, texture, vertex, - Blend, DrawError, DrawParameters, IndexBuffer, Program, Rect, Surface, Texture2d, VertexBuffer + Blend, DrawError, DrawParameters, GlObject, IndexBuffer, Program, Rect, Surface, Texture2d, + VertexBuffer }; use glium::backend::{Context, Facade}; use glium::index::PrimitiveType; use glium::texture::{ClientFormat, RawImage2d}; +use libc::uintptr_t; use std::borrow::Cow; use std::fmt; use std::rc::Rc; @@ -97,13 +99,16 @@ impl Renderer { [ 0.0, 0.0, -1.0, 0.0 ], [ -1.0, 1.0, 0.0, 1.0 ] ]; - let uniforms = uniform! { - matrix: matrix, - tex: &self.device_objects.texture - }; + let font_texture_id = self.device_objects.texture.get_id() as uintptr_t; let mut idx_start = 0; for cmd in draw_list.cmd_buffer { + // We don't support custom textures...yet! + assert!(cmd.texture_id as uintptr_t == font_texture_id); + let uniforms = uniform! { + matrix: matrix, + tex: &self.device_objects.texture + }; let draw_params = DrawParameters { blend: Blend::alpha_blending(), scissor: Some(Rect { @@ -165,6 +170,7 @@ impl DeviceObjects { }; Texture2d::new(ctx, data) })); + im_gui.set_texture_id(texture.get_id() as uintptr_t); Ok(DeviceObjects { vertex_buffer: vertex_buffer, diff --git a/src/lib.rs b/src/lib.rs index a6d211b..382b089 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ extern crate imgui_sys; extern crate libc; -use libc::{c_char, c_float, c_int, c_uchar}; +use libc::{c_char, c_float, c_int, c_uchar, c_void, uintptr_t}; use std::borrow::Cow; use std::convert::From; use std::ffi::CStr; @@ -155,6 +155,11 @@ impl ImGui { }) } } + pub fn set_texture_id(&mut self, value: uintptr_t) { + unsafe { + (*self.io_mut().fonts).tex_id = value as *mut c_void; + } + } pub fn set_ini_filename(&mut self, value: Option>) { { let io = self.io_mut();