Freestyle integration into Blender

May 1, 2008

Freestyle: canvas/stroke rendering reviewed

Filed under: Notes, Update — The dev team @ 7:37 PM

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).


1 Comment »

  1. About the libQGLViewer replacement, i would advise you to look at the blender imbuf support. By using those, you would guarantee easier later integration, and less code for you.

    png is probaly the simplest to use.

    later, you will want to fit in the composite space, which means one plane of the exr render buffers but it is more complex and can wait

    Comment by jean-luc — May 5, 2008 @ 11:13 AM

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: