<small id='ld8hN'></small><noframes id='ld8hN'>

  1. <legend id='ld8hN'><style id='ld8hN'><dir id='ld8hN'><q id='ld8hN'></q></dir></style></legend>
  2. <i id='ld8hN'><tr id='ld8hN'><dt id='ld8hN'><q id='ld8hN'><span id='ld8hN'><b id='ld8hN'><form id='ld8hN'><ins id='ld8hN'></ins><ul id='ld8hN'></ul><sub id='ld8hN'></sub></form><legend id='ld8hN'></legend><bdo id='ld8hN'><pre id='ld8hN'><center id='ld8hN'></center></pre></bdo></b><th id='ld8hN'></th></span></q></dt></tr></i><div id='ld8hN'><tfoot id='ld8hN'></tfoot><dl id='ld8hN'><fieldset id='ld8hN'></fieldset></dl></div>

      <bdo id='ld8hN'></bdo><ul id='ld8hN'></ul>
    <tfoot id='ld8hN'></tfoot>

      OpenGL - 具有多个纹理的蒙版

      时间:2023-09-18

      <legend id='bJo9G'><style id='bJo9G'><dir id='bJo9G'><q id='bJo9G'></q></dir></style></legend>
    1. <i id='bJo9G'><tr id='bJo9G'><dt id='bJo9G'><q id='bJo9G'><span id='bJo9G'><b id='bJo9G'><form id='bJo9G'><ins id='bJo9G'></ins><ul id='bJo9G'></ul><sub id='bJo9G'></sub></form><legend id='bJo9G'></legend><bdo id='bJo9G'><pre id='bJo9G'><center id='bJo9G'></center></pre></bdo></b><th id='bJo9G'></th></span></q></dt></tr></i><div id='bJo9G'><tfoot id='bJo9G'></tfoot><dl id='bJo9G'><fieldset id='bJo9G'></fieldset></dl></div>

      <small id='bJo9G'></small><noframes id='bJo9G'>

            <bdo id='bJo9G'></bdo><ul id='bJo9G'></ul>

                <tbody id='bJo9G'></tbody>

                <tfoot id='bJo9G'></tfoot>
                本文介绍了OpenGL - 具有多个纹理的蒙版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我已经根据以下概念在 OpenGL 中实现了遮罩:

                I have implemented masking in OpenGL according to the following concept:

                • 面具由黑白两色组成.
                • 前景纹理应该只在蒙版的白色部分可见.
                • 背景纹理应该只在遮罩的黑色部分可见.

                我可以使用 glBlendFunc() 使白色部分或黑色部分按预期工作,但不能同时使用两者,因为前景层不仅混合到蒙版上,还混合到背景层上.

                I can make the white part or the black part work as supposed by using glBlendFunc(), but not the two at the same time, because the foreground layer not only blends onto the mask, but also onto the background layer.

                有没有人知道如何以最好的方式完成这项工作?我一直在网上搜索并阅读有关片段着色器的内容.这是要走的路吗?

                Is there anyone who knows how to accomplish this in the best way? I have been searching the net and read something about fragment shaders. Is this the way to go?

                推荐答案

                这应该有效:

                glEnable(GL_BLEND);
                // Use a simple blendfunc for drawing the background
                glBlendFunc(GL_ONE, GL_ZERO);
                // Draw entire background without masking
                drawQuad(backgroundTexture);
                // Next, we want a blendfunc that doesn't change the color of any pixels,
                // but rather replaces the framebuffer alpha values with values based
                // on the whiteness of the mask. In other words, if a pixel is white in the mask,
                // then the corresponding framebuffer pixel's alpha will be set to 1.
                glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO);
                // Now "draw" the mask (again, this doesn't produce a visible result, it just
                // changes the alpha values in the framebuffer)
                drawQuad(maskTexture);
                // Finally, we want a blendfunc that makes the foreground visible only in
                // areas with high alpha.
                glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
                drawQuad(foregroundTexture);
                

                这相当棘手,所以如果有任何不清楚的地方,请告诉我.

                This is fairly tricky, so tell me if anything is unclear.

                不要忘记请求 alpha 缓冲区创建 GL 上下文.否则有可能在没有 alpha 缓冲区的情况下获得上下文.

                Don't forget to request an alpha buffer when creating the GL context. Otherwise it's possible to get a context without an alpha buffer.

                在这里,我做了一个插图.

                Here, I made an illustration.

                自从写下这个答案,我了解到有更好的方法来做到这一点:

                Since writing this answer, I've learned that there are better ways to do this:

                • 如果您仅限于 OpenGL 的固定功能管道,请使用纹理环境
                • 如果您可以使用着色器,请使用片段着色器.

                此答案中描述的方法有效,并且在性能上并不比这 2 个更好的选项差,但不够优雅且不那么灵活.

                The way described in this answer works and is not particularly worse in performance than these 2 better options, but is less elegant and less flexible.

                这篇关于OpenGL - 具有多个纹理的蒙版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:为什么精灵不能在 OpenGL 中渲染? 下一篇:OpenGL以像素为单位定义顶点位置

                相关文章

                最新文章

                  <bdo id='bncqX'></bdo><ul id='bncqX'></ul>

                1. <small id='bncqX'></small><noframes id='bncqX'>

                2. <legend id='bncqX'><style id='bncqX'><dir id='bncqX'><q id='bncqX'></q></dir></style></legend>
                  <i id='bncqX'><tr id='bncqX'><dt id='bncqX'><q id='bncqX'><span id='bncqX'><b id='bncqX'><form id='bncqX'><ins id='bncqX'></ins><ul id='bncqX'></ul><sub id='bncqX'></sub></form><legend id='bncqX'></legend><bdo id='bncqX'><pre id='bncqX'><center id='bncqX'></center></pre></bdo></b><th id='bncqX'></th></span></q></dt></tr></i><div id='bncqX'><tfoot id='bncqX'></tfoot><dl id='bncqX'><fieldset id='bncqX'></fieldset></dl></div>
                  <tfoot id='bncqX'></tfoot>