我想在openGL立方体上做一个洞,我已经尝试过一些方法,比如使用模板和αblending.but问题,用模板来划分和显示,只有一半的part.My要求我必须堆叠立方体,并且应该使用户指定数量的孔(矩形/椭圆形状)到顶部对象,我能够堆叠对象,但如果需要的话,我不能造一个洞。我是openGL的新手,我没有为this.can找到任何直接的解决方案,有人给出了这个需求的示例程序吗?
模板代码:
glClear(GL_STENCIL_BUFFER_BIT);
glColorMask(false, false, false, false);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL, 0, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glDisable(GL_DEPTH_TEST);
glColor4f(0,0,1,1.0f);
//code for cube
glEnable(GL_DEPTH_TEST);
glColorMask(true, true, true, true);
glStencilFunc(GL_ALWAYS,0, 1);
glStencilOp(GL_REPLACE,GL_KEEP, GL_ZERO);
//code for cylinder
glDisable(GL_STENCIL_TEST);发布于 2014-03-20 08:06:58
在你的样本中,你为什么要在立方体之后呈现洞呢?如果你想要你的模具做一些事情,你应该做相反的事情。
用这个伪码,孔应该是平面网格或接近。
-enable depth test if not already done; (depth test should not be disabled, if the point of view place hole on back faces, you dont want to have it reflected in front...)
-Enable stencil test;
-set colormask to false;
-set stencil op replace; (if your hole are rendered and maybe moving each frame,
use replace to update the stencil)
-set stencil func always 1 1; (if you wants your hole to be rendered into the stencil
buffer you have to pass always)
-render your hole mesh with your current model view matrices;
-restore colormask to true;
-set stencilfunc notequal 1 1; (dont draw if something appear in stencil at this place)
-set stencil op keep:; (keep in any case)
-draw your scene: holes will be masked;https://stackoverflow.com/questions/22526534
复制相似问题