Blending with glPolygonOffset

glPolygonOffset() is used to offset the polygon being rendered, and thus the pixels in the polygon, from the others currently in the displaybuffer. This does not actually effect the values written to the ZBuffer and is useful when blending two textures or polygons together.

The following images give an example of the problem and the effect of using glPolygonOffset. There are two polygons are rendered, the first being red, with the second being yellow blended over it in the same position in 3D space. The aim of the blending is to make a clean transition between red and yellow, or between 2 textures, in an animation. The second yellow polygon is a little bigger that the first red polygon be show the effect more clearly. In the first image, the "popping" of the red polygon through the yellow polygon occurs because the pixels values of the yellow polygon do not exactly match the Z buffer values of the first.

By enabling polygon offset the second polygon depth tests are performed using the following calculation...

"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 *" OpenGL Reference Documentation

The result is that the second yellow polygon gives the desired result and blends nicely over the red polygon. This effect is very useful when blended between textures, for example, when changing a models level of detail. It is important when using this method that the polygons are drawn in a particular order. The offset yellow polygon must be draw original red polygon otherwise the effect does not work.

// Render first polygon
gl.glEnable(GL.GL_POLYGON_OFFSET_FILL) ;
gl.glPolygonOffset(-1.0f, 1.0f) ;
// Render second polygon
gl.glDisable(GL.GL_POLYGON_OFFSET_FILL) ;

Note that offsets can be used for the lines and the points in a polygon as well by enabling GL.GL_POLYGON_OFFSET_LINE and/or GL.GL_POLGON_OFFSET_POINT.

Labels

Web Search Gmail Google Docs Mobile YouTube Google Maps Google Chrome User interface Tips iGoogle Social Google Reader Traffic Making Devices cpp programming Ads Image Search Google Calendar tips dan trik Google Video Google Translate web programming Picasa Web Albums Blogger Google News Google Earth Yahoo Android Google Talk Google Plus Greasemonkey Security software download info Firefox extensions Google Toolbar Software OneBox Google Apps Google Suggest SEO Traffic tips Book Search API Acquisitions InOut Visualization Web Design Method for Getting Ultimate Traffic Webmasters Google Desktop How to Blogging Music Nostalgia orkut Google Chrome OS Google Contacts Google Notebook SQL programming Google Local Make Money Windows Live GDrive Google Gears April Fools Day Google Analytics Google Co-op visual basic Knowledge java programming Google Checkout Google Instant Google Bookmarks Google Phone Google Trends Web History mp3 download Easter Egg Google Profiles Blog Search Google Buzz Google Services Site Map for Ur Site game download games trick Google Pack Spam cerita hidup Picasa Product's Marketing Universal Search FeedBurner Google Groups Month in review Twitter Traffic AJAX Search Google Dictionary Google Sites Google Update Page Creator Game Google Finance Google Goggles Google Music file download Annoyances Froogle Google Base Google Latitude Google Voice Google Wave Google Health Google Scholar PlusBox SearchMash teknologi unik video download windows Facebook Traffic Social Media Marketing Yahoo Pipes Google Play Google Promos Google TV SketchUp WEB Domain WWW World Wide Service chord Improve Adsence Earning jurnalistik sistem operasi AdWords Traffic App Designing Tips and Tricks WEB Hosting linux How to Get Hosting Linux Kernel WEB Errors Writing Content award business communication ubuntu unik