
Converting AC3D Files into OpenGL Source Code.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
               by Steve Baker <sjbaker1@airmail.net>

There are two possible approaches to making use
of models built in AC3D within an OpenGL program.

* Write a loader for AC3D files that is linked into
  the application program.

* Convert each AC3D file into a chunk of C/C++ code
  that can be compiled into the application.

This package takes the second approach.

The 'ac_to_gl' program reads an '.ac' file from
standard input and emits a C++ file on standard
output:

  eg

     ac_to_gl <folly.ac >folly.c++

The resulting file can be compiled into a '.o' file
that will render the object when linked into a suitable
program.

The calling program need simply call:

   void draw_ac3d_model ( void (*func)( char * ) ) ;

The parameter is the address of a function that
will load the provided texture map into OpenGL.
If the parameter is NULL then no texture will be
loaded.

Files in this package:

  * load_sgi_textures.cxx : A suitable function for loading
    SGI images (the kind used by default by AC3D).

  * harness.cxx : A demonstration test harness (using GLUT).
                  (Hit any key to end the demo)

  * ac_to_gl.cxx : The program to convert AC3D files into
    OpenGL/C++ source.

  * folly.ac : A demonstration AC3D file.

  * ice.rgb  : A texture map for folly.ac.

  * Makefile : A sample makefile.

Hence, you can write a custom viewer for AC3D file
by compiling and linking harness.cxx, load_sgi_textures.cxx
and the result of running ac_to_gl on your AC3D '.ac'
file.

Known Bugs:
~~~~~~~~~~~

AC_TO_GL: does not yet take account of the 'smooth' flag and
only computes surface normals for entire polygons rather
than at each vertex. This - together with some confusion
on my behalf (probably) - over the lighting used inside
the main AC3D program - means that some models don't
illuminate in quite the same way as they do in AC3D.

Notably, the 'glider.ac' model that comes with AC3D
has different illumination on one wing than the other
when displayed with ac_to_gl - but both are blue in
AC3D. The simplest way to fix this is to stick with
single-sided polygons.

There is nothing in the spec for '.ac' files to
prohibit you from storing concave on non-planar
polygons. However, ac_to_gl doesn't do anything
with your polygons except pass them on to OpenGL -
which does not permit concave or non-flat polygons.

HARNESS: uses only the 'load_sgi_texture' code to
load texture maps - but since you can add plugins
to AC3D to load other image file formats, it's
possible for a '.ac' file to contain references to
other texture map file formats.

Efficiency:
~~~~~~~~~~~

Using GL_POLYGON to draw polygons is really not
the most efficient method of drawing in OpenGL.
Ideally, one should split all polygons (including
quadrilaterals) into triangles and then build up
triangle strips and fans. Bad luck - this tool
doesn't do that.

Rendering polygons and lines in the order that
AC3D happens to emit them isn't the best option.
Ideally, one should sort by texture and material
to minimise the number of texture/material changes -
and you need to render translucent polygons last
(in back-to-front order) to avoid incorrect Z
buffer effects. However, AC3D gets that wrong too,
so I don't have to feel too bad about it!






