How to display Wireframe Mode in gfx-rs?

I’m learning opengl by gfx-rs. but when I want to display a triangle by line mode., I cannot find a function to realize it.
Here has a function called “glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);” in C++ can.
like this:

I am guessing you’re talking about gfx pre-ll, and not gfx-hal.

On pre-ll, you can create a Rasterizer with RasterMethod::Line.

use gfx::state::{Rasterizer, RasterMethod};

let mut rasterizer = Rasterizer::new_fill();
rasterizer.method = RasterMethod::Line(1);

Now you can create a pipeline state object by passing your rasterizer to factory.create_pipeline_state() or factory.create_pipeline_from_program()

See the terrain_tessellated example for more details.

Thank you! I have realized it by your means.:smile:

//set fillmode
let mut fillmode = gfx::state::Rasterizer::new_fill();
fillmode.method = gfx::state::RasterMethod::Line(1);
//import shader
let vs = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/rect.glslv"));
let fs = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/rect.glslf"));
let set = factory.create_shader_set(vs, fs).unwrap();
// define pipeline
let pso = factory.create_pipeline_state(
//define triangle
const TRIANGLE: &[Vertex] = &[
    Vertex { pos: [  -0.5, 0.0 ], color: WHITE },
    Vertex { pos: [   0.0, 0.87 ], color: WHITE },
    Vertex { pos: [   0.5, 0.0 ], color: WHITE },
//define indices
const INDICES: &[u16] = &[0, 1, 2];

let (vertex_buffer, slice) =
    factory.create_vertex_buffer_with_slice(TRIANGLE, INDICES);

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.