OpenGL绘制纹理,缩放相机导致纹理闪烁的解决方法gluPerspective ()
2016-01-28 16:32
781 查看
做项目的时候,对三维场景中的物体进行了纹理贴图。但是奇怪的是,缩放相机或者是左右移动视角,变换视图矩阵时,纹理贴图会出现大范围的闪烁现象。查了好久,最后发现问题出在投影视景体的参数设置上。我们的投影视景体用的方法是:gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
glPerspective:用于透视投影,功能和glFrustum非常相似(这个函数的具体用法可以自己去看一下),参数不一样。相对于glFrustum来说不常用。百度百科的解释如下:
void gluPerspective(
GLdouble fovy, //角度
GLdouble aspect,//视景体的宽高比
GLdouble zNear,//沿z轴方向的两裁面之间的距离的近处
GLdouble zFar //沿z轴方向的两裁面之间的距离的远处
)
PARAMETERS(参数含义)
fovy
Specifies the field of view angle, in degrees, in the y direction.
指定视景体的视野的角度,以度数为单位,y轴的上下方向
aspect
Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height).
指定你的视景体的宽高比(x 平面上)
zNear
Specifies the distance from the viewer to the near clipping plane (always positive).
指定观察者到视景体的最近的裁剪面的距离(必须为正数)
zFar
Specifies the distance from the viewer to the far clipping plane (always positive).
与上面的参数相反,这个指定观察者到视景体的最远的裁剪面的距离(必须为正数)
问题关键在于:透视投影可能会导致深度精度的损失。在显示设备中该问题很明显。问题出在深度缓存中深度的限制以及由透视投影引起的非线性比例变换。当近裁剪面非常靠近投影中心的时候,误差就非常大。就是说,当zNears设置的过于接近0时(投影中心),OpenGL就不知道如何去处理这种情况了,然后就会导致深度精度的损失。而刚开始我们项目中zNear设置成了0.1,调整为1以后,纹理闪烁的问题就消失了。
以下两张图片,左边是zNear为0.1时的效果图,右边是zNear为1时的效果图。
以上是对gluPerspective()的一些理解,其中有一些参考,连接如下:
http://bbs.gameres.com/thread_106693_1_1.html http://blog.csdn.net/tan_handsome/article/details/47321385 http://bbs.gameres.com/forum.php?mod=viewthread&tid=23660&extra=&page=2 http://www.cppblog.com/COOOOOOOOL/archive/2009/12/28/104255.html
欢迎指正,共同进步。
glPerspective:用于透视投影,功能和glFrustum非常相似(这个函数的具体用法可以自己去看一下),参数不一样。相对于glFrustum来说不常用。百度百科的解释如下:
void gluPerspective(
GLdouble fovy, //角度
GLdouble aspect,//视景体的宽高比
GLdouble zNear,//沿z轴方向的两裁面之间的距离的近处
GLdouble zFar //沿z轴方向的两裁面之间的距离的远处
)
PARAMETERS(参数含义)
fovy
Specifies the field of view angle, in degrees, in the y direction.
指定视景体的视野的角度,以度数为单位,y轴的上下方向
aspect
Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height).
指定你的视景体的宽高比(x 平面上)
zNear
Specifies the distance from the viewer to the near clipping plane (always positive).
指定观察者到视景体的最近的裁剪面的距离(必须为正数)
zFar
Specifies the distance from the viewer to the far clipping plane (always positive).
与上面的参数相反,这个指定观察者到视景体的最远的裁剪面的距离(必须为正数)
问题关键在于:透视投影可能会导致深度精度的损失。在显示设备中该问题很明显。问题出在深度缓存中深度的限制以及由透视投影引起的非线性比例变换。当近裁剪面非常靠近投影中心的时候,误差就非常大。就是说,当zNears设置的过于接近0时(投影中心),OpenGL就不知道如何去处理这种情况了,然后就会导致深度精度的损失。而刚开始我们项目中zNear设置成了0.1,调整为1以后,纹理闪烁的问题就消失了。
以下两张图片,左边是zNear为0.1时的效果图,右边是zNear为1时的效果图。
以上是对gluPerspective()的一些理解,其中有一些参考,连接如下:
http://bbs.gameres.com/thread_106693_1_1.html http://blog.csdn.net/tan_handsome/article/details/47321385 http://bbs.gameres.com/forum.php?mod=viewthread&tid=23660&extra=&page=2 http://www.cppblog.com/COOOOOOOOL/archive/2009/12/28/104255.html
欢迎指正,共同进步。
相关文章推荐
- linux硬盘分区格式化及挂载
- 再谈如何学习Linux,一线Linux专家学习经验谈
- LaTeX中绘图工具包PGFPlots(1.13)的安装
- iOS开发笔记--iOS应用架构谈 view层的组织和调用方案
- C++程序Windows移植Linux注意事项
- Hadoop在Windows下的安装配置
- Linux 安装Mysql
- Linux cgroup机制分析之框架分析
- Linux下jdk配置环境变量
- Linux环境下JDK的卸载与安装
- 卸载linux自带的mysql
- linux 配置 ip 地址
- windows server2008 iis 7部署及网站部署完整步骤
- webform网站相关数据控件和其他
- Linux中的常用符号解释
- 一个不错的linux学习资料下载的网址
- 数据验证框架 Apache BVal 简介
- Hadoop 4、Hadoop MapReduce的工作原理
- Tomcat7.0.22在Windows下详细配置过程
- linux命令之wc(word count)命令