OpenGL: glPolygonOffset解决两个面共面

来源:互联网 发布:网络热门词汇英语 编辑:程序博客网 时间:2024/06/06 02:11
摘自http://www.gamergroup.cn/html/78/n-3078.html
当两个面共面时,会出现十分难看的z - fighting 问题,要解决此问题可以使用, Polygon Offset, 方法如下:
drawSomething();
//同一位置绘制另一个东西
glEnable( GL_POLYGON_OFFSET_FILL ); // This is the one we need...
glPolygonOffset( g_OffsetFactor, g_OffsetUnit );
drawOtherthing();
glPolygonOffset( 0.0f, 0.0f );
glDisable( GL_POLYGON_OFFSET_FILL );
其中
g_OffsetFactor代表 factor,
g_OffsetUnit 代表 units,
关于factor, units 的解释如下:
When GL_POLYGON_OFFSET is enabled, each fragment's depth value will be offset after it is interpolated from the depth values of the appropriate vertices. The value of the offset is factor * DZ + r * units, where DZ is a measurement of the change in depth relative to the screen area of the polygon, and r is the smallest value that is guaranteed to produce a resolvable offset for a given implementation. The offset is added before the depth test is performed and before the value is written into the depth buffer.
glPolygonOffset is useful for rendering hidden-line images, for applying decals to surfaces, and for rendering solids with highlighted edges.

这个函数以后可能用得到,tutorial04里面画阴影的时候用到了,不过阴影还是很难看
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 租的房子太吵怎么办 苹果手机音量键坏了怎么办 xp系统声音没了怎么办 柿子烂到窗台上怎么办 小窗户厨房太暗怎么办 抬东西把腰闪了怎么办 搬重东西后腰疼怎么办 闪了腰怎么办一动就疼 窗户的把手断了怎么办 窗户寸漏不了水怎么办 窗户打开关不上怎么办 新装修的房子有甲醛怎么办 橄榄核上油花了怎么办 虫子飞到耳朵里怎么办 手被虫子咬肿了怎么办 梦见牙掉出血该怎么办 黑户急需5万块钱怎么办 家里欠了好多钱怎么办 欠好多网贷我该怎么办 外面欠了很多钱怎么办 欠了好多网贷怎么办 欠那么多钱我该怎么办 急用钱怎么办谁给指条路 晚上睡不着觉怎么办白天又醒不来 胃疼了好几天怎么办 手机移动卡怎么办副卡 大学我好累我怎么办 感觉婚姻很累了怎么办 一个人的心累了怎么办 头被凉水激着了怎么办 人一但懒惰了怎么办 太懒了怎么办都不想活 和老公和不来该怎么办 摩拜忘记关锁怎么办 绿萝叶子变软了怎么办 水痘疫苗打了3次怎么办 免疫组化p16阳性怎么办 乙肝五项25为阳怎么办 苏宁快递丢件了怎么办 新房苯超标10倍怎么办 结婚后遇到真爱怎么办