tomaka / glium_text

Text rendering with glium
48 stars 35 forks source link

Does not compile with old glium #13

Open Kingdread opened 8 years ago

Kingdread commented 8 years ago

Compiling the unchanged git clone gives errors about different types in glutin 0.3.7:

% cargo build
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling glutin v0.3.7
   Compiling image v0.3.15
/home/daniel/.multirust/toolchains/stable/cargo/registry/src/github.com-121aea75f9ef2ce2/glutin-0.3.7/src/api/osmesa/mod.rs:82:63: 83:69 error: mismatched types:
 expected `*mut libc::c_void`,
    found `*mut libc::types::common::c95::c_void`
(expected enum `libc::c_void`,
    found enum `libc::types::common::c95::c_void`) [E0308]
/home/daniel/.multirust/toolchains/stable/cargo/registry/src/github.com-121aea75f9ef2ce2/glutin-0.3.7/src/api/osmesa/mod.rs:82         let ret = osmesa_sys::OSMesaMakeCurrent(self.context, self.buffer.as_ptr()
/home/daniel/.multirust/toolchains/stable/cargo/registry/src/github.com-121aea75f9ef2ce2/glutin-0.3.7/src/api/osmesa/mod.rs:83                                                 as *mut libc::c_void, 0x1401, self.width
/home/daniel/.multirust/toolchains/stable/cargo/registry/src/github.com-121aea75f9ef2ce2/glutin-0.3.7/src/api/osmesa/mod.rs:82:63: 83:69 help: run `rustc --explain E0308` to see a detailed explanation
/home/daniel/.multirust/toolchains/stable/cargo/registry/src/github.com-121aea75f9ef2ce2/glutin-0.3.7/src/api/x11/window.rs:517:38: 517:63 error: mismatched types:
 expected `*mut libc::c_void`,
    found `*mut libc::types::common::c95::c_void`
(expected enum `libc::c_void`,
    found enum `libc::types::common::c95::c_void`) [E0308]
/home/daniel/.multirust/toolchains/stable/cargo/registry/src/github.com-121aea75f9ef2ce2/glutin-0.3.7/src/api/x11/window.rs:517                 (display.xlib.XFree)(hint as *mut libc::c_void);
                                                                                                                                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/daniel/.multirust/toolchains/stable/cargo/registry/src/github.com-121aea75f9ef2ce2/glutin-0.3.7/src/api/x11/window.rs:517:38: 517:63 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to 2 previous errors

Bumping the versions to the latest crates seems to fix the problem:

diff --git a/Cargo.toml b/Cargo.toml
index d0351e3..b2ad520 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,11 +7,11 @@ keywords = ["text", "opengl"]
 license = "MIT"

 [dependencies]
-freetype-sys = "0.1"
-libc = "0.1"
+freetype-sys = "0.2"
+libc = "0.2"

 [dependencies.glium]
-version = "0.9"
+version = "0.12"
 default-features = false
 features = ["cgmath"]

@@ -19,5 +19,5 @@ features = ["cgmath"]
 cgmath = "0.2"

 [dev-dependencies.glium]
-version = "0.9"
+version = "0.12"
 features = ["glutin"]
fourthaugmentation commented 8 years ago

I am trying to compile an example and I am getting "An unknown error occurred."

#[macro_use]
extern crate glium;
extern crate glium_text;

fn main() {

       use glium::{DisplayBuild, Surface};
      let display = glium::glutin::WindowBuilder::new().build_glium().unwrap();

        // The `TextSystem` contains the shaders and elements used for text display.
        let system = glium_text::TextSystem::new(&display);

        // Creating a `FontTexture`, which a regular `Texture` which contains the font.
        // Note that loading the systems fonts is not covered by this library.
        let font = glium_text::FontTexture::new(&display, std::fs::File::open(&std::path::Path::new("Droid_Sans_Mono.ttf")).unwrap(), 24).unwrap();

        // Creating a `TextDisplay` which contains the elements required to draw a specific sentence.
        let text = glium_text::TextDisplay::new(&system, &font, "Hello world!");

        // Finally, drawing the text is done like this:
        let matrix = [[1.0, 0.0, 0.0, 0.0],
                      [0.0, 1.0, 0.0, 0.0],
                      [0.0, 0.0, 1.0, 0.0],
                      [0.0, 0.0, 0.0, 1.0]];
        glium_text::draw(&text, &system, &mut display.draw(), matrix, (1.0, 1.0, 0.0, 1.0));

        loop {
            let mut target = display.draw();
            target.clear_color(0.0, 0.0, 1.0, 1.0);
            target.finish().unwrap();

            for ev in display.poll_events() {
                match ev {
                    glium::glutin::Event::Closed => return,
                     _ => ()
                    }
             }
         }
}