diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-11-22 17:42:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-11-22 17:42:22 +0300 |
commit | c36f78dd41b8d2c714b2a94c43eabe928afea26a (patch) | |
tree | 48856d51a20eb4024f142e1fb68a9d345a291aeb /source/gameengine/Ketsji/KX_Scene.h | |
parent | f4a0c9239ff21a75a336ed3f496dd88d3997d28e (diff) |
[#19258] [patch] Adding drawing capabilities to BGE Python
patch from Mitchell Stokes (moguri)
simple use case
scene.post_draw = [pyOpenGLFunc]
this only needs to be set once, then the funcion runs each redraw.
note, this patch also changes how python scripts run (not modules): Dont clear the namespace after running a script, since functions still use the namespace, BGE API is now better when dealing with stale data.
made some changes to this patch.
- assigning a list didnt decrement the existing list.
- initialize as NULL rather then a blank list
- dont use string comparisons for the callbacks, pass the python list to use instead.
- dont check the list items are callable. python will display an error if they are not.
- use python list macros that dont do any type checking sine blender does this when assigning the list
---- from tracker, edited since an updated patch changes some things.
Here is a patch to be able to draw to the screen with BGE Python. This will be very handy for GUI stuff. This patch
works by having the user register a callback in the scene. Two options are available KX_Scene.pre_draw
and KX_Scene.post_draw. The difference between these is when Python draws to the screen (before or after the BGE).
Each can take a list of functions. Here is an example that draws a blue semi-transparent
Diffstat (limited to 'source/gameengine/Ketsji/KX_Scene.h')
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.h | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 4b01ab39d95..602e919b58d 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -95,6 +95,8 @@ class KX_Scene : public PyObjectPlus, public SCA_IScene #ifndef DISABLE_PYTHON PyObject* m_attr_dict; + PyObject* m_draw_call_pre; + PyObject* m_draw_call_post; #endif struct CullingInfo { @@ -102,7 +104,6 @@ class KX_Scene : public PyObjectPlus, public SCA_IScene CullingInfo(int layer) : m_layer(layer) {} }; - protected: RAS_BucketManager* m_bucketmanager; CListValue* m_tempObjectList; @@ -287,6 +288,12 @@ public: void RenderBuckets(const MT_Transform& cameratransform, RAS_IRasterizer* rasty, RAS_IRenderTools* rendertools); + + /** + * Run the registered python drawing functions. + */ + void RunDrawingCallbacks(PyObject* cb_list); + /** * Update all transforms according to the scenegraph. */ @@ -544,6 +551,10 @@ public: static PyObject* pyattr_get_cameras(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_active_camera(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_drawing_callback_pre(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_drawing_callback_pre(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_drawing_callback_post(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_drawing_callback_post(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); virtual PyObject* py_repr(void) { return PyUnicode_FromString(GetName().ReadPtr()); } @@ -551,6 +562,8 @@ public: static PyMappingMethods Mapping; static PySequenceMethods Sequence; + PyObject* GetPreDrawCB() { return m_draw_call_pre; }; + PyObject* GetPostDrawCB() { return m_draw_call_post; }; #endif /** |