Today, I studied how the Canvas::Draw() method is implemented (see stroke/ folder). I wasn’t expected to dive so deep in the code. I was introduced to Freestyle’s stroke representation organization. This allows the user to render the result in different “formats”: OpenGL for live interaction (which can be saved to bitmap by the libQGLViewer widget), Postscript saving and text-format saving.
I now grasp the whole chain of command of rendering, from the canvas, to the layers, to the strokes. The first time a stroke is to be rendered, a stroke representation is created, which in turn generates the stroke’s underlying strip (the transformation of the stroke’s parameters into a OpenGL-friendly format). To get a better idea of how Freestyle’s abstract stroke model is transformed into triangle strips, I also studied the strip creation and strip cleaning code in detail. The stroke representation is then used by the stroke renderer to produce the end graphical result.
In Freestyle’s interface, the main canvas uses GLStrokeRenderer (found in rendering/) for the triangle strips rendering. Two rendering functions can be used (RenderStrokeRep and RenderStrokeRepBasic). So far, the only difference that I have found between them is that RenderStrokeRep allows for different stroke types (essentially different OpenGL blending models). The actual rendering is pretty straightforward: it sets up the appropriate OpenGL settings and then renders the stroke as a GL_TRIANGLE_STRIP, using the previously calculated color, alpha and texture.
Now that I understand how rendering is set up (cf. Controller.cpp) and implemented, I see where work needs to start. The most critical aspect of the first phase will be to make Freestyle independent of the libQGLViewer widget. The easy part is that I won’t need to replace libQGLViewer’s mouse/keyboard/view interaction capabilities. The hard part will be to recreate a new view that doesn’t break Freestyle’s internals and which can be saved to disk (Freestyle uses libQGLViewer’s saveSnapshot method for image saving).
I intend to proceed by first rendering a simple fixed scene (fixed camera, fixed object) using Freestyle’s code directly through the Blender UI. I’ll then need to insert Blender’s information (camera parameters and model data) into that pipeline, using Blender’s 3ds export capability. I can also sense that I will have quite a few problems to set up Freestyle’s compilation within Blender (dependency problems).