OpenGl:模板缓冲区问题(“墙+窗口")? [英] OpenGl: Stencil buffer problem (Wall + Window)?

查看:343
本文介绍了OpenGl:模板缓冲区问题(“墙+窗口")?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用模板缓冲区创建一面带有窗口的墙. 我的代码如下:

I want to create a wall with a window inside, using stencil buffer. My code looks like this:

glEnable(GL_STENCIL_TEST);
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilMask(1);
glStencilFunc(GL_ALWAYS, 1, 1);

glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glDisable(GL_DEPTH_TEST);   
glColor3f(1,1,1);

//Window
glBegin(GL_POLYGON);
glVertex3d(-5,0,-20);
glVertex3d(-5,0,40);
glVertex3d(-20,0,40);
glVertex3d(-20,0,-20);
glEnd();

glEnable(GL_DEPTH_TEST);
glStencilFunc(GL_NOTEQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

glEnable(GL_CLIP_PLANE0);                       
glClipPlane(GL_CLIP_PLANE0, eqr);   
glBindTexture(GL_TEXTURE_2D,texture[1]);
glBegin(GL_POLYGON);
glNormal3f(0.0f,-1.0,0.0f);

//Wall
glTexCoord2f(0.0f, 0.0f);glVertex3d(20,0,-20);
glTexCoord2f(1.0f, 0.0f);glVertex3d(20,0,40);
glTexCoord2f(1.0f, 0.0f);glVertex3d(-20,0,40);
glTexCoord2f(1.0f, 0.0f);glVertex3d(-20,0,-20);

glEnd();
glDisable(GL_STENCIL_TEST);

但是那行不通,我得到了整个填充墙,没有窗户在里面,有什么建议吗?

But that doesn't work out, I got the whole fill wall without the window in it, any suggestions??

推荐答案

我尚未测试您的代码,但我认为您应该更改

I haven't tested your code, but I think that you should change

glStencilFunc(GL_NOTEQUAL, 1, 1);

glStencilFunc(GL_EQUAL, 1, 1);

这篇关于OpenGl:模板缓冲区问题(“墙+窗口")?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆