Code

By Gene Turnbow, August 31, 2010

A very very small OpenGL engine.

I wrote this thing ages ago for a commercial project for the now-defunct subsidiary of Sony, Sony Development.  We were trying to make a giant pinball machine where you tilted the entire machine to play.  To test the physical controller hardware as they worked the kinks out of the design, they needed a little 3D engine to hook up to them so they could see what it would do.  So in about a week, I wrote one.

It’s a little odd as engines go in that it loads Lightwave 6.x (or greater) scene and model files and renders them, and then lets you fly a camera around and look at them. It lights the scene according to whatever lights you put in the scene, but all lights are translated as point lights. I never got spotlights or area lights working. It does respect global ambience settings in the scene, though, as well as maintain the hierarchical relationship between all the scene elements (i.e., parenting of scene elements is preserved at runtime.

It eventually ended up being listed in the news section on Flay.com, one of the world’s more important Lightwave 3D web sites, and OpenGL.Org also had my listing. I even found a web site in Japan that linked to the original page.  Too bad I can’t read Japanese! The engine has been downloaded tens of thousands of  times since I posted it after SIGGRAPH 2001.

Special thanks to artist and animator Aaron Estrada for the 3D scan of his head.

The engine does do texture maps, but only UV textures, and there are a few ways to apply the textures in Lightwave that don’t actually work. The best approach seems to be to convert whatever conventional texture mapping you might have on your models into UV maps using the “Make UVs” tool in the “Map” toolset in modeler. Since the loader doesn’t handle DMAP chunks, models using cylindrical or spherical mapping need to have the vertices split at the seam, or you’ll get mapping errors.

The source code will compile under either Windows, using Microsoft Visual C++ 6.x or greater, or under Linux using GCC. Yup, it’s cross-platform code!

Download the source code, binaries and sample data here. It’s pretty tiny by modern standards – only 3 megs, even though it includes all the model files and textures and whatnot that you get with it. It’s a fairly modest example of a 3D engine. Once I got the object and scene loaders working, the rest of the engine was done in about five days. It does give some good example code for reading objects in native Lightwave LWO2 format, though. By the way, in the ‘credit where credit is due’ department, I started with the example ‘C’ loader code written by Yoshiaki Tazaki at D-Storm.

Once you’ve gotten it to compile (it shouldn’t be difficult if you know how to use the compiler at all), run it by giving a parameter of either a model file or a scene file. If you give it a scene file as a parameter, it’ll assume all the assets are right there in the same directory with you, even if the scene file says otherwise. If you give it a model file as a parameter, it’ll just load the model file and let you spin it around and look at it from different angles. If you can’t compile the project or don’t want to bother, binary executables are included for both Linux and Windows.

A comment: this project was set up to compile from KDevelop in versions prior to 2.x. If your version is more recent than that, you’re going to have a few problems getting to compile as a project using KDevelop. I’ll may revisit this and make a newer version with new project files (thought I can’t promise when.)

Interestingly, the Linux version runs significantly faster than the Windows version does, even though it’s exactly the same code. I think Linux just works better from the standpoint of interfacing the OpenGL API with the hardware. I know I could do a lot more about optimizing the rendering pipeline, though. Right now the only thing I do is sort the polygons by material; this cuts down on having to use the GL material commands for every single darned polygon, and it sped things up a lot. It’s still not a really quick engine as engines go, but it’s quicker than it first was.

I’ve absolutely got to offer a caveat here as well: I wrote this engine as an exercise, and I stopped before I finished it. There are leftovers and leavings of various ideas in it that I never implemented. The object and scene loading classes themselves are fairly clean, however, and I did my best to keep that functionality as encapsulated as possible so they could be reused by somebody else if needed.

Could I write the same code now?  No. If you don’t use linear algebra for 3D for a few years, you forget how.  Could I learn to write the same code now?  Absolutely.  I did it before.  I can do it again.

— Gene Turnbow

Let’s start with Rio, which again validated that the Olympics are the most valuable and most consumed property in wholesale nfl jerseys media. NBC won all 17 nights of primetime, and the NBC Sports Network was the number one sports cable network in primetime over the 14 days that it presented live coverage of the games. Cheap Oakleys In fact, in the 18 to 49 demo, NBC’s primetime’s ratings more than quadrupled the other broadcast networks combined and were nearly five times greater with Millennials. Moreover, that lead widened versus prior Olympics. The audience for the Rio Olympics was enormous, NFL Jerseys China encompassing almost 200 million Americans on television alone, not to mention those who also engaged on our other platforms.During this period, yellow fever killed more American soldiers than died in the Spanish American War and claimed the lives of 52,000 French workers constructing the Panama Canal . It wasn’t until 1901 that the North American scientists, following the lead of their colleagues in Mexico , Cuba and Europe, finally confirmed Dr. Finlay’s theory.Those in Cheap NFL Jerseys China the S 500 are trading at 14.4 times their projected earnings over the next 12 months. That makes them less expensive than health care stocks, which are priced at 16.7 times expected earnings, and industrial companies, which are valued at 16.1 times earnings.ON A REDUCTION OF FED STIMULUSInvestors have been obsessed with the Fed all year and the stock http://www.FakeOakLeysForSale.com market’s biggest setbacks have come when they thought that policymakers were poised to cut back on economic stimulus.The S 500 has dropped in only two months this year, June and August. As is also traditional, the San Diego financing plan comes dressed up with predictions of all sorts of economic development ripples from events at the new stadium: monster truck jams, concerts, rodeos, dog shows, bar mitzvahs (yes, bar mitzvahs). Last I checked, Qualcomm could accommodate any and all of these, sometimes several at once.Tingle is infamous for writing dinosaur on man sex that people of all political stripes can enjoy, but here he takes a firm stance against Britain’s decision to leave the European Union. In Pounded, an everyday British man named Alex is taken one month into the future of Brexit by a giant sentient coin with an “incredible set of chiseled metallic abs” and a “thick golden rod,” which is British for “thick golden penis.”Thanks, Lachlan. It’s John and good afternoon. At the outset I’ll remind you that because of the sale this past November of our DBS businesses to Sky, our reported financial results for the year and for the fourth quarter are not like to like. So to continue to present a more meaningful comparison, we are providing and commenting on, total company adjusted revenue and EBITDA, which excludes the DBS businesses in all periods.

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

This blog is kept spam free by WP-SpamFree.