Improve transparent texture examples and docs #566
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi again! This PR introduces three changes that should hopefully ensure people use a correct material for transparent textures:
078a085 modifies the documentation of
is_transparentin the ColorMaterial. I propose this addition because I tried to 'fix' incorrect rendering of material by marking is transparent without modifying therender_states.blendproperty. This did not work, hopefully this addition helps steer future users (or future me) towards the solution.7355d51 modifies the
shapes2dexample to also show a textured rectangle using a transparent texture. I think this is a common use-case for 2d drawings like a hud or overlay, so to me it makes sense to have this in the example:texturesexample to show the difference between anColorMaterial::new_opaqueandColorMaterial::new_transparent, which again, hopefully helps people find the right material to render a transparent texture:Background; so over the weekend I tried create a fullscreen, transparent, click through window in X11 on which I could draw an overlay. Turns out that X11s blending alpha support is tricky, I couldn't get it right, but at a certain point I tried using opengl on my window, which worked and drawing a simple rectangle with transparency also worked. But drawing an image with transparency support required shaders and a lot of complexity in modern opengl. So I needed something to handle that: I used
three_d::context::Context::from_loader_functionandthree_d::core::Context::from_gl_contextfor that to create athree_d::Context👌 . That is called on aglfw-created window, which is made transparent, fullscreen and click-through using direct x11 calls. Then to make my texture I effectively ended up copying from here and ended up withCombined with this example image that led to the same dreaded overlay that I pretty much got from pure x11 calls.
Changing the texture into:
makes it much better, but it is still off, as it renders incorrectly against light backgrounds.
Modifying it finally to
makes it render completely correct.
Writing this up here, I actually wonder if we should talk about that
STANDARD_TRANSPARENCYin the comments in the examples. Anyways, hopefully this prevents a lot of debugging by other people in the future. Happy to accommodate any feedback etc, or remove changes if I went over-the-top 👍