tomaka / glium_text Goto Github PK
View Code? Open in Web Editor NEWText rendering with glium
Text rendering with glium
title says all.
Example font: https://github.com/adobe-fonts/source-han-sans/
There are a large number of Unicode characters, they do not require all converted Texture. This will block the process tens of seconds.
Perhaps we should render the texture in TextDisply::new(..)
, like SDL_ttf.
I will try to do this
glium_text::draw() uses Default::default() to instantiate new DrawParameters on every call. This seems both inefficient and very inflexible.
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"]
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: CompilationError("ERROR: 0:2: \'\' : version \'110\' is not supported\nERROR: 0:3: \'\' : #version required and missing.\nERROR: 0:4: \'attribute\' : syntax error: syntax error\n")', ../src/libcore/result.rs:731
https://github.com/tomaka/glium_text/blob/master/src/lib.rs#L226
Need add 140 version shader:
#version 140
uniform mat4 matrix;
in vec2 position;
in vec2 tex_coords;
out vec2 v_tex_coords;
void main() {
gl_Position = matrix * vec4(position, 0.0, 1.0);
v_tex_coords = tex_coords;
}
and
#version 140
in vec2 v_tex_coords;
out vec4 f_color;
uniform vec4 color;
uniform sampler2D tex;
void main() {
f_color = vec4(color.rgb, color.a * texture(tex, v_tex_coords));
if (f_color.a <= 0.01) {
discard;
}
}
When running both my own code and the hello world example provided, verbatim, Rust appears unable to find the glium::backend::Facade trait or glium::Surface, regardless of the fact that I have glium::Surface
and glium::DisplayBuild
used.
src/main.rs:14:18: 14:45 error: the trait `glium::backend::Facade` is not implemented for the type `glium::backend::glutin_backend::GlutinFacade` [E0277]
src/main.rs:14 let system = glium_text::TextSystem::new(&display);
^~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:14:18: 14:45 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:14:18: 14:45 note: required by `glium_text::TextSystem::new`
src/main.rs:16:16: 16:44 error: the trait `glium::backend::Facade` is not implemented for the type `glium::backend::glutin_backend::GlutinFacade` [E0277]
src/main.rs:16 let font = glium_text::FontTexture::new(&display, &include_bytes!("font.ttf")[..], 70).unwrap();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:16:16: 16:44 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:16:16: 16:44 note: required by `glium_text::FontTexture::new`
src/main.rs:36:9: 36:25 error: the trait `glium::Surface` is not implemented for the type `glium::Frame` [E0277]
src/main.rs:36 glium_text::draw(&text, &system, &mut target, matrix, (1.0, 1.0, 0.0, 1.0));
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.