GLUGG - OpenGL Utilities for Geometry Generation

Proudly presenting: GLUGG!


GLUGG stands for OpenGL Utilities for Geometry Generation. This is a source-only package, one C file and one header file plus demos, that will make it easier for you to generate geometry directly from code. You specify one vertex at a time, optionally with normal vector and texture coordinates, and GLUGG will return a VAO that you can use to draw the shape, or get the date for other purposes, like save it to disc. GLUGG supports primitives like triangle fans and triangle strips which will help you by remembering previous vertices to make the actual triangles easier to manage, and can even generate Bézier patches.


Ever since OpenGL deprecated the immediate mode and display lists, the art of procedural generation of geometry has fallen out of view. Old demos are tedious to port to the new style, and writing new code for procedural geometry generation is totally up to you, OpenGL having no support for it any more.


In order to modernize the old “gears” demo (glutGears, glxGears), I wrote some utility functions for collecting vertices procedurally. This felt quite useful, and I expanded it to dealing with Bézier curves, from which I generated the Utah Teaset from code as well as a demo for fitting Bézier patches together.


Then it sat on my disc for a long time, just being the code for these demos.


But recently, 2021, I got the responsibility to handle the TNM084 course, which is about procedural methods. Hey, how about using GLUGG for that? I have also ran into some cases where I could see how this package could help students with problems in their projects.


So I picked it up to dust it off. It needed documentation and at least one simpler demo. Sure thing! But then I got inspired and added multiple demos and, maybe most importantly, extended it to multiple modes which simplifies the generation even further.


Here is the current package, with demos and documentation, version 1.0 as of 2021-05-07:


Download version 1.0.


Demos


All demos are included in the package above.


Triangle


We start with not one but three simple demos, the standard white triangle, now generated from code instead of arrays, plus a color version of it, but also the “gluggModes” demo that demonstrates the four different data collection modes.

Skärmavbild 2021-05-07 kl. 11.04.35


The white triangle


Color triangle


This is a small step from the white triangle, using the normal vectors to pass on colors.

Skärmavbild 2021-05-07 kl. 11.04.50


The color triangle


gluggModes


This is yet another very simple demo, demonstrating the different recording modes in GLUGG.


Skärmavbild 2021-05-07 kl. 11.05.04


gluggModes, with GLUGG_TRIANGLES (red), GLUGG_QUADS (green), GLUGG_TRIANGLE_STRIP (yellow) and GLUGG_TRIANGLE_FAN (cyan).


GLUGG shapes


Here you can see how different shapes can be generated with GLUGG. The demo is based on code from FreeGLUT, but converted to GLUGG, and thereby to more modern code.


Skärmavbild 2021-05-07 kl. 11.06.01


GLUGG shapes


GLUGG more shapes


The previous demo skipped over a number of shapes that were provided by GLU in those days, so I made these too, this time from scratch. This includes cylinder, sphere, cone and ellipsoid.


Skärmavbild 2021-05-07 kl. 11.07.00


More shapes


Sphere


What, another sphere? Unlike the slice-based sphere above, this is made by tesselating a tetrahedron, another way to generate a sphere. It is based on code that I no longer know the origin of. But what is that red mess? It is what you get when you don’t tesselate enough.


Skärmavbild 2021-05-07 kl. 11.07.29


The “sphere” demo


GLUGG gears


glxGears is the standard demo for GLX, that is Mesa on Linux and similar platforms, the one that all Linux users run to check that Mesa has been correctly installed. AFAIK it originated as glutGears, which is nowhere to be found but I recreated it in modernized form, which was the very starting point for GLUGG. GLUGG as such did not exist yet but my glutGears included some routines that would eventually become the first version. That makes this demo the one that I am the most fond of, second to the teaset.


Skärmavbild 2021-05-07 kl. 11.08.01


GLUGG gears


Boing


Boing was originally a demo for Amiga, made at a time when 3D animation of this quality was unheard of. Later, it was recreated as GLboing. This demo seems to be lost, but a port of it can be found as a GLFW demo, as very old-fashioned immediate mode code. From that, I ported it to MicroGlut, but it was still old-fashioned. Now, using GLUGG, it is much more modern, uploading the data properly to GPU buffers like all GLUGG code does.


Skärmavbild 2021-05-07 kl. 11.08.32


boing!


GLUGG sweeper


GLUGG sweeper shows how you can generate rotation symmetric shapes from a set of points.


Skärmavbild 2021-05-07 kl. 11.09.01


GLUGG sweeper


Surface


“surface” demonstrates how you fit together Bézier patches. It makes 4 Bzier patches, with the center vertices kept in a plane to ensure continuity.


Skärmavbild 2021-05-07 kl. 11.09.24


surface


The UTAH Teaset!


And finally, the proud #1 demo, my favorite, the dream for anyone who has been messing around with the Utah Teapot for years without knowing that it was a whole set, the Utah teaset! This is generated from a slightly extended version of the original data (and the changes are documented in the code). The code is also able to save the models as OBJ files.


Skärmavbild 2021-05-07 kl. 11.10.19


UTAH Teaset


Note: Several of these demos are based on code from other sources. I have done my best to document this appropriately. Original copyright notices are kept.

This page is maintained by Ingemar Ragnemalm.