Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invert Stencil for Non-Convex Polygons #317

Open
tyehle opened this issue Sep 10, 2019 · 2 comments
Open

Invert Stencil for Non-Convex Polygons #317

tyehle opened this issue Sep 10, 2019 · 2 comments

Comments

@tyehle
Copy link

tyehle commented Sep 10, 2019

looks like Blend::Invert will not work when drawing to the stencil buffer. This is one of the easiest ways I've found of drawing non-convex polygons.

Could this be supported? I took a look at the draw_state code and I wasn't sure how to go about implementing such support.

@bvssvni
Copy link
Member

bvssvni commented Sep 10, 2019

There is a "draw_state" example which might help: https://github.com/PistonDevelopers/opengl_graphics/blob/master/examples/draw_state.rs

@tyehle
Copy link
Author

tyehle commented Sep 11, 2019

Yeah I saw that, but I don't think anything in there is quite what I'd like to do. I was trying to do something like this:

|triangles, transform, g| {
    // create the stencil
    g.clear_stencil(0);
    let clip = DrawState::new_clip().blend(Blend::Invert);
    for triangle in triangles {
        Polygon::new([1.0, 1.0, 1.0, 1.0])
            .draw(triangle, &clip, transform, g);
    }

    // fill the stenciled area
    Rectangle::new([1.0, 0.0, 0.0, 1.0])
        .draw([0.0, 0.0, 100.0, 100.0], &DrawState::new_inside(), transform, g);
}

But it looks like the blend mode for the stencil drawing is always just adding because the StencilOp is always bound as gl::StencilOp(gl::REPLACE, gl::KEEP, gl::KEEP); if the stencil is Clip(val).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants