opengL glBlendFunc

介紹gbBlendFunc


It's quite simple. 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*1So, 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.2So you'll get pixels which are 80% red and 20% blue, which is basically how you render transparent objects, like glass and such.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章