Opengl 镜像变换背面剔除
在 openGL 中,我有一个沿轴缩放 -1 的对象...这会导致该对象无法正确渲染,因为所有正面现在都是背面。如果不禁用剔除,我该如何让这个对象正确渲染?有没有办法在不修改构成模型的纹理法线顶点的情况下做到这一点?
In openGL, I've got an object that I scale by -1 along an axis... this results in the object not rendering properly because all the front faces are now back faces. Short of disabling culling, how would I get this object to render right? Is there a way to do it without modifying the textured normal vertices that make up my model?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以简单地切换剔除模式。您可以使用glCullFace(mode)来决定应剔除哪些三角形。提供 GL_BACK 参数表示仅渲染正面多边形,而提供 GL_FRONT 参数表示仅渲染背面多边形。因此,如果您的转换意味着“背面”多边形实际上是正面,则调用
glCullFace(GL_FRONT)
应该可以解决问题。作为替代方案,您还可以使用
glFrontFace(dir)
控制哪些多边形被视为正面/背面,参数为GL_CW
(顺时针)或GL_CCW
>(逆时针)(默认为逆时针,因此如果将其设置为时钟,原始背面多边形将被视为正面)。You can simply switch the culling mode. You can use
glCullFace(mode)
to decide which triangles should be culled. Supplying a parameter ofGL_BACK
means that only front-facing polygons are rendered, while a parameter of GL_FRONT means that only backfacing polygons are rendered. So if your transformation means that the "backfacing" polygons are in fact frontfacing, callingglCullFace(GL_FRONT)
should do the trick.As an alternative you can also control which polygons are considered front/backfacing using
glFrontFace(dir)
, with a parameter ofGL_CW
(clockwise) orGL_CCW
(counterclockwise) (default is counterclockwise so if you set it to clocksie originaly backfacing polygons would be considered frontfacing).