# HG changeset patch # User Emmanuel Gil Peyrot # Date 1565821561 -7200 # Node ID 6be3320a1cb3e96d8b681ed0428f852d9492b9f3 # Parent 3e4cc64a254da0a1151a194b549b7ea46bf1c82c Use the same RenderState as PyTouhou in anmrenderer, and normalize color, thanks phaazon! diff --git a/examples/anmrenderer.rs b/examples/anmrenderer.rs --- a/examples/anmrenderer.rs +++ b/examples/anmrenderer.rs @@ -1,4 +1,5 @@ use image::GenericImageView; +use luminance::blending::{Equation, Factor}; use luminance::context::GraphicsContext; use luminance::framebuffer::Framebuffer; use luminance::pipeline::BoundTexture; @@ -24,7 +25,7 @@ use std::path::Path; const VS: &str = r#" in ivec3 in_position; in vec2 in_texcoord; -in uvec4 in_color; +in vec4 in_color; uniform mat4 mvp; @@ -36,8 +37,8 @@ void main() gl_Position = mvp * vec4(vec3(in_position), 1.0); texcoord = vec2(in_texcoord); - // Normalized from the u8 being passed. - color = vec4(in_color) / 255.; + // It’s already normalized from the u8 being passed. + color = in_color; } "#; @@ -73,6 +74,7 @@ pub enum Semantics { struct Vertex { pos: VertexPosition, uv: VertexTexcoord, + #[vertex(normalized = "true")] rgba: VertexColor, } @@ -181,7 +183,10 @@ fn main() { // TODO: check how to pass by reference. iface.mvp.update(*mvp.borrow_inner()); - rdr_gate.render(RenderState::default(), |tess_gate| { + let render_state = RenderState::default() + .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement)); + + rdr_gate.render(render_state, |tess_gate| { // render the tessellation to the surface the regular way and let the vertex shader’s // magic do the rest! tess_gate.render(&mut surface, (&tess).into()); @@ -195,12 +200,12 @@ fn main() { fn fill_vertices_ptr(sprite: Rc>, vertices: *mut Vertex) { let mut fake_vertices = unsafe { std::mem::transmute::<*mut Vertex, &mut [FakeVertex; 4]>(vertices) }; - sprite.borrow().fill_vertices(&mut fake_vertices); + sprite.borrow().fill_vertices(&mut fake_vertices, 0., 0., 0.); } fn fill_vertices(sprite: Rc>, vertices: &mut [Vertex; 4]) { let mut fake_vertices = unsafe { std::mem::transmute::<&mut [Vertex; 4], &mut [FakeVertex; 4]>(vertices) }; - sprite.borrow().fill_vertices(&mut fake_vertices); + sprite.borrow().fill_vertices(&mut fake_vertices, 0., 0., 0.); } fn load_from_disk(surface: &mut GlfwSurface, path: &Path) -> Option> {