An MFC OpenGL Polygon Tessellation Demo

An MFC OpenGL Polygon Demo App

Recently, I had some trouble with malformed polygons in one of my OpenGL scientific visualization workbenches. After some research and lots of help from the folks here and, I found the problem—some of my objects were 'non-simple' polygons with at least one interior angle greater than 180 degrees (in other words, some part of the polygon is concave vs. convex), and the OpenGL rendering of non-convex polygons is undefined. To correctly render a concave polygon, I needed to tell OpenGL to "tessellate" the polygon (tessellation is the process of breaking a complex polygon into two or more simpler polygons, each of which is entirely convex) and then render the resulting all-convex polygons.

Fortunately, tessellation isn't that hard to do, and there are lots of general resources such as,, and "The OpenGL Programming Guide" (aka The Red Book) to draw upon. There are a number of "gluTess..." API calls like glTessBeginPolygon() and glTessEndPolygon that parallel the normal "gl" calls for polygons, and so forth. Setting up rendering with tessellation is pretty much the same as setting it up for non-tessellated polygons except for the CALLBACK functions and memory leak issues. After researching the basics, I started looking for example code, only to discover there really wasn't much out there dealing with the details of an MFC implementation. There was lots of C code (including Tess.c from the Red Book), but nothing that showed specifically how to implement the required CALLBACK functions in MFC, and how to deal with the potential for memory leaks. So, after getting my application working, I decided to build a sample MFC app called MFCTess to demonstrate at least one technique for making tessellation work in an MFC app.

Starting with a generic MSVC++ V6 MFC Appwizard-generated SDI app, I ported the necessary OpenGL tessellation routines from my other (now working) project and added facilities for generating and displaying a single polygon with one or more contours. I also added the ability to save generated contours in an ASCII .DAT file rather than using MFC's binary serialization facilities (see the included help file for the .DAT file format).

The purpose of MFCTess is to demonstrate polygon tessellation in MFC. Only one polygon can be displayed at a time, but that one polygon can have any number of contours. The active polygon's contours are defined by means of a Polygon Definition dialog box (it has its own help topic, accessed by clicking on the Help button in that dialog). Only the X and Y coordinates of the polygon are considered—the Z coordinate information is ignored for purposes of display. The color for each vertex can be defined independently. A right-click context menu is available in the main display window to allow the user to explore the effect of several different OpenGL "Winding" rules.

Polygon contours can be saved to and/or loaded from comma or space-delimited ASCII *.DAT files. It would have been much easier to use the MFC binary serialization facilities but I much prefer ASCII files because you can easily tell whether or not what got saved was actually what you intended to save. The file format and an example are shown in the on-line help topic. Note that the per-contour header string "CONTOUR:" is required. Vertex data is comma or space (either one or both will do) delimited 6-tuples (X,Y,Z, R,G,B). The RGB values are normalized to 255.

A screenshot is shown below, and the VC++ V6 MFC project files (zipped), can be downloaded.



  • Fake Oakley Forsake for sale

    Posted by clvbmgwvc on 06/24/2013 12:14pm

    ray ban outlet ,The sunglasses also referred to as sun mirror (or sunglasses) generally must prevent glare, UV and glare. The legend of Oakley glasses, making use of their beauty and complexity, is an effective personal preferences. Most of these in the sunshine, often initially portrayed the VIP. Cheap Oakley Sunglasses ,For style forward even Oakley at the summit. Oakley standby time with the latest model generated glasses. Oakley shade with the application can be quite a major celebrity list. Over time, the Oakley Sunglasses has become to further improve outside frontier of the lens structure, thus preventing the entire field of vision field athletes down frame RIM like running and cycling. Fake Oakley Mens ,You'll be able to go traditional, and get some good respite for ones Oakley Jupiter, you are able to pick the leading glasses or contact lenses with Oakley sunglasses. Oakley sunglasses lenses are incredibly safe, no pressure, may customize the optical pause, which means you has to be truthful, accurate vision premium clarity. Know used sheet metal sunglasses, employed for time could be slightly deformed, the normal phenomenon. Dealer Executive to adjust to. Oakley sports sunglasses better sunglasses sold to uncover. You will discover a framework and coated lenses to adapt to every face type. Wearing Oakley sunglasses often take advantage of the tools including a drill or saw in order to avoid harm to your skills area speeding allergens. Oakley sunglasses gives you 100% of harmful UV protection, since the design of such lenses not only supply you with the best convergence, but the highest amount of security, performance and comfort. Oakley has been perfecting the lens structure from the open frontier, thereby preventing the entire field of vision field in the down frame RIM like running and cycling athletes. Addition, plutonite contacts offers a many ultra-violet sun rays of the sun 100% protection, and special protection of influence. Besides these specific polarization picture bonding strategy is a significant lead, and employ of injection so as to put the two materials. Under normal circumstances, it reduces the anxiety of the eyes and retention of girl squinting. Oakley sunglasses in the best quality sales that you sensible choice into the future here to buy it's going to never regret it. So not hesitate, we Oakley designer products.

  • please help me

    Posted by lizhiyuan on 07/18/2007 03:38am

    Dear friend
    I need to finish a design of cube and cylinder using vc++ 6.0. but i already finished part of my project using Single document, now just remain cube and sylinder design and past an image on them. that is all. i found your article is very nice for me. can you provide me any other source code.

  • Glutess alternative tessellator

    Posted by Ska77 on 07/08/2005 04:07am

    I've just finished to write my own tessellator, you can find it at as a part of Amanith Framework, it's Opensource so you can look to the code.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Entire organizations suffer when their networks can't keep up and new opportunities are put on hold. Waiting on service providers isn't good business. In these examples, learn how to simplify network management so that your organization can better manage costs, adapt quickly to business demands, and seize market opportunities when they arise.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date