glBlendFunc

Let's say you have already rendered a blue quad, and right now you're rendering a red quad on top of it, with blending on. For each pixel rendered, there are 2 values: the color which is currently stored in the buffer(blue) and the color which is about to be written to the buffer(red). The first is called "destination color", the second is called "source color". Without blending, the source color would overwrite completely the destination color, but with blending on, the final color is computed as follows:
Col=src_color*src_factor+dst_color*dst_factor;
src_factor and dst_factor is the variables you set using glBlendFunc. For example glBlendFunc(GL_ONE,GL_ONE) gives:
Col=src_color*1+dst_color*1
So, after rendering the 2 quads, you'll get pixels with color=red+blue(purple)
Now, if you also give the red quad an alpha value, say glColor4f(1,0,0,0.8) and set glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) you'll have:
Col=src_color*0.8+dst_color*(1-0.8)=src_color*0.8+dst_color*0.2
So you'll get pixels which are 80% red and 20% blue, which is basically how you render transparent objects, like glass and such.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值