pre_- and post_draw

hi everyone,

i’ve been browsing the python api and found the pre_draw and post_draw properties of
the description says: post_draw: A list of callables to be run after the render step.

can anyone give an example how to use them or tell me what elements are supposed to
be in these lists?

thx in advance,


been searching in the source and found this:

void KX_Scene::RunDrawingCallbacks(PyObject* cb_list)
int len;

if (cb_list && (len=PyList_GET_SIZE(cb_list)))
    PyObject* args= PyTuple_New(0); // save python creating each call
    PyObject* func;
    PyObject* ret;
    // Iterate the list and run the callbacks
    for (int pos=0; pos < len; pos++)
        func= PyList_GET_ITEM(cb_list, pos);
        ret= PyObject_Call(func, args, NULL);
        if (ret==NULL) {
        else {


this is the function for pre and post-drawing.
both are python lists which elements are functions…
i unfortunately dont know where to find the source code for PyObject_Call yet.
so if anyone knows what kind of function is required, it would be awesome :slight_smile:

maybe i just gonna try out a fragment_program.


KX_Scene.post_draw and KX_Scene.pre_draw exist to allow you to run raw OpenGL calls if you want. For example, I can create a function to draw 2d shapes (i.e., a GUI) over the screen and add it to the post_draw of the current scene. If the function was called without using the callback, nothing would show up because the screen is cleared between when Python is (normally) run and when the drawing actually happens. In Python, a “callable” is any object that implements the call() method, which all functions do. In this case, the function should take no arguments.

Moguri’s put together a great GUI system for the BGE (BGUI) which utilizes the scene’s post_draw variable. If you take a peek at it, perhaps you’ll get a little more knowledge about the variable.

------------------------------:stuck_out_tongue: wrong

Moguri, SolarLune…awesome help!^^ immediately bookmarked your bgui page.
though, one question left: hwat is the advantage using modules instead of python scripts? are modules just compiled once in the beginning?

Well, for one thing, it’s a lot easier to manage, as you can use an external script editor. Blender’s text editor is alright, but it isn’t as powerful as it could be - I use Notepad++, which has folding, project management (through an add-on), and pretty interesting code-completion, as well.

Another good thing is that by using external modules, you can reuse the same code across projects. For example, if I made my Python module, BGHelper, a collection of scripts, I would have to append the scripts I want to the scene, which is slow. In addition, not all functions of the external module can be used as scripts, like number clamping functions or list generation scripts.

Finally, by using external modules, I can put libraries like BGHelper in the Blender Foundation folder (for Windows, this works), edit it, and have the changes affect all projects (which can break working with some games, LOL :S).

Anyway, it’s just easier to me to work with external modules. It’s a lot more flexible than the text editor. :smiley:

thx SolarLune, for your detailed help again^^