Revision: 19588
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19588
Author:   campbellbarton
Date:     2009-04-07 20:55:35 +0200 (Tue, 07 Apr 2009)

Log Message:
-----------
BGE Py API
- Added OpenGL access to the game engine as a module so you can import BGL 
directly.

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/BGL.c
    trunk/blender/source/blender/python/api2_2x/BGL.h
    trunk/blender/source/blender/python/api2_2x/Blender.c
    trunk/blender/source/blender/python/api2_2x/modules.h
    trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
    trunk/blender/source/gameengine/GamePlayer/ActiveX/BlenderPlayerCtl.cpp
    trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
    
trunk/blender/source/gameengine/GamePlayer/netscape/src/ketsji/KXH_ketsji_hooks.cpp
    trunk/blender/source/gameengine/Ketsji/CMakeLists.txt
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.h
    trunk/blender/source/gameengine/Ketsji/SConscript

Modified: trunk/blender/source/blender/python/api2_2x/BGL.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/BGL.c   2009-04-07 18:38:23 UTC 
(rev 19587)
+++ trunk/blender/source/blender/python/api2_2x/BGL.c   2009-04-07 18:55:35 UTC 
(rev 19588)
@@ -35,7 +35,6 @@
 #include "BGL.h" /*This must come first */
 
 #include "MEM_guardedalloc.h"
-#include "gen_utils.h"
 
 static int type_size( int type );
 static Buffer *make_buffer( int type, int ndimensions, int *dimensions );
@@ -121,8 +120,6 @@
 
 /* #endif */
 
-PyObject *BGL_Init( void );
-
 /********/
 static int type_size(int type)
 {
@@ -185,12 +182,12 @@
        int i, type;
        int *dimensions = 0, ndimensions = 0;
        
-       if (!PyArg_ParseTuple(args, "iO|O", &type, &length_ob, &template))
-               return EXPP_ReturnPyObjError(PyExc_AttributeError,
-                               "expected an int and one or two PyObjects");
-
+       if (!PyArg_ParseTuple(args, "iO|O", &type, &length_ob, &template)) {
+               PyErr_SetString(PyExc_AttributeError, "expected an int and one 
or two PyObjects");
+               return NULL;
+       }
        if (type!=GL_BYTE && type!=GL_SHORT && type!=GL_INT && type!=GL_FLOAT 
&& type!=GL_DOUBLE) {
-               PyErr_SetString(PyExc_AttributeError, "type");
+               PyErr_SetString(PyExc_AttributeError, "invalid first argument 
type, should be one of GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT or GL_DOUBLE");
                return NULL;
        }
 
@@ -1088,19 +1085,19 @@
        {NULL, NULL, 0, NULL}
 };
 
-PyObject *BGL_Init(void) 
+PyObject *BGL_Init(const char *from) 
 {
-       PyObject *mod= Py_InitModule("Blender.BGL", BGL_methods);
+       PyObject *mod= Py_InitModule(from, BGL_methods);
        PyObject *dict= PyModule_GetDict(mod);
-       
+       PyObject *item;
        if( PyType_Ready( &buffer_Type) < 0)
                Py_RETURN_NONE;
 
-#define EXPP_ADDCONST(x) EXPP_dict_set_item_str(dict, #x, 
PyInt_FromLong((int)x))
+#define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, 
item=PyInt_FromLong((int)x)); Py_DECREF(item)
 
 /* So, for example:
  * EXPP_ADDCONST(GL_CURRENT_BIT) becomes
- * EXPP_dict_set_item_str(dict, "GL_CURRENT_BIT", 
PyInt_FromLong(GL_CURRENT_BIT)) */
+ * PyDict_SetItemString(dict, "GL_CURRENT_BIT", 
item=PyInt_FromLong(GL_CURRENT_BIT)); Py_DECREF(item) */
 
        EXPP_ADDCONST(GL_CURRENT_BIT);
        EXPP_ADDCONST(GL_POINT_BIT);

Modified: trunk/blender/source/blender/python/api2_2x/BGL.h
===================================================================
--- trunk/blender/source/blender/python/api2_2x/BGL.h   2009-04-07 18:38:23 UTC 
(rev 19587)
+++ trunk/blender/source/blender/python/api2_2x/BGL.h   2009-04-07 18:55:35 UTC 
(rev 19588)
@@ -43,6 +43,7 @@
 #include <Python.h>
 #include "BIF_gl.h"
 
+PyObject *BGL_Init( const char *from );
 
 /*@ Buffer Object */
 /*@ For Python access to OpenGL functions requiring a pointer. */

Modified: trunk/blender/source/blender/python/api2_2x/Blender.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Blender.c       2009-04-07 
18:38:23 UTC (rev 19587)
+++ trunk/blender/source/blender/python/api2_2x/Blender.c       2009-04-07 
18:55:35 UTC (rev 19588)
@@ -1074,7 +1074,7 @@
 
        PyDict_SetItemString(dict, "Armature", Armature_Init());
        PyDict_SetItemString(dict, "BezTriple", BezTriple_Init());
-       PyDict_SetItemString(dict, "BGL", BGL_Init());
+       PyDict_SetItemString(dict, "BGL", BGL_Init("Blender.BGL"));
        PyDict_SetItemString(dict, "CurNurb", CurNurb_Init());
        PyDict_SetItemString(dict, "Constraint", Constraint_Init());
        PyDict_SetItemString(dict, "Curve", Curve_Init());

Modified: trunk/blender/source/blender/python/api2_2x/modules.h
===================================================================
--- trunk/blender/source/blender/python/api2_2x/modules.h       2009-04-07 
18:38:23 UTC (rev 19587)
+++ trunk/blender/source/blender/python/api2_2x/modules.h       2009-04-07 
18:55:35 UTC (rev 19588)
@@ -52,7 +52,7 @@
 and cannot be #included until it is cleaned up.
 ****************************************************************************/
 
-PyObject *BGL_Init( void );
+PyObject *BGL_Init( const char *from );
 
 PyObject *Library_Init( void );
 PyObject *Noise_Init( void );

Modified: 
trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
===================================================================
--- trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp     
2009-04-07 18:38:23 UTC (rev 19587)
+++ trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp     
2009-04-07 18:55:35 UTC (rev 19588)
@@ -368,6 +368,7 @@
                        initGameKeys();
                        initPythonConstraintBinding();
                        initMathutils();
+                       initBGL();
 #ifdef WITH_FFMPEG
                        initVideoTexture();
 #endif
@@ -666,6 +667,7 @@
                        initGameKeys();
                        initPythonConstraintBinding();
                        initMathutils();
+                       initBGL();
 #ifdef WITH_FFMPEG
                        initVideoTexture();
 #endif

Modified: 
trunk/blender/source/gameengine/GamePlayer/ActiveX/BlenderPlayerCtl.cpp
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/ActiveX/BlenderPlayerCtl.cpp     
2009-04-07 18:38:23 UTC (rev 19587)
+++ trunk/blender/source/gameengine/GamePlayer/ActiveX/BlenderPlayerCtl.cpp     
2009-04-07 18:55:35 UTC (rev 19588)
@@ -672,6 +672,7 @@
                        initGameKeys();                 
                        initPythonConstraintBinding();
                        initMathutils();
+                       initBGL();
                        
                        m_sceneconverter->ConvertScene(
                                startscenename,

Modified: trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.cpp        
2009-04-07 18:38:23 UTC (rev 19587)
+++ trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.cpp        
2009-04-07 18:55:35 UTC (rev 19588)
@@ -689,6 +689,7 @@
                initGameKeys();
                initPythonConstraintBinding();
                initMathutils();
+               initBGL();
 #ifdef WITH_FFMPEG
         initVideoTexture();
 #endif

Modified: 
trunk/blender/source/gameengine/GamePlayer/netscape/src/ketsji/KXH_ketsji_hooks.cpp
===================================================================
--- 
trunk/blender/source/gameengine/GamePlayer/netscape/src/ketsji/KXH_ketsji_hooks.cpp
 2009-04-07 18:38:23 UTC (rev 19587)
+++ 
trunk/blender/source/gameengine/GamePlayer/netscape/src/ketsji/KXH_ketsji_hooks.cpp
 2009-04-07 18:55:35 UTC (rev 19588)
@@ -571,6 +571,7 @@
                initGameKeys();
                initPythonConstraintBinding();
                initMathutils();
+               initBGL();
                
                KXH_log_entry("APH_initialize_gameengine:: will enter kx 
engine");
                

Modified: trunk/blender/source/gameengine/Ketsji/CMakeLists.txt
===================================================================
--- trunk/blender/source/gameengine/Ketsji/CMakeLists.txt       2009-04-07 
18:38:23 UTC (rev 19587)
+++ trunk/blender/source/gameengine/Ketsji/CMakeLists.txt       2009-04-07 
18:55:35 UTC (rev 19588)
@@ -36,6 +36,7 @@
   ../../../source/blender/python/api2_2x/quat.c
   ../../../source/blender/python/api2_2x/vector.c
   ../../../source/blender/python/api2_2x/bpy_internal_import.c
+  ../../../source/blender/python/api2_2x/BGL.c
 )
 
 SET(INC

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp    2009-04-07 
18:38:23 UTC (rev 19587)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp    2009-04-07 
18:55:35 UTC (rev 19588)
@@ -78,6 +78,7 @@
 extern "C" {
        #include "Mathutils.h" // Blender.Mathutils module copied here so the 
blenderlayer can use.
        #include "bpy_internal_import.h"  /* from the blender python api, but 
we want to import text too! */
+       #include "BGL.h"
 }
 
 #include "marshal.h" /* python header for loading/saving dicts */
@@ -1168,7 +1169,7 @@
        /* quick hack for GamePython modules 
                TODO: register builtin modules properly by ExtendInittab */
        if (!strcmp(name, "GameLogic") || !strcmp(name, "GameKeys") || 
!strcmp(name, "PhysicsConstraints") ||
-               !strcmp(name, "Rasterizer") || !strcmp(name, "Mathutils")) {
+               !strcmp(name, "Rasterizer") || !strcmp(name, "Mathutils") || 
!strcmp(name, "BGL")) {
                return PyImport_ImportModuleEx(name, globals, locals, fromlist);
        }
        
@@ -1357,6 +1358,8 @@
        clearModule(modules, "Rasterizer");     
        clearModule(modules, "GameKeys");       
        clearModule(modules, "VideoTexture");   
+       clearModule(modules, "Mathutils");      
+       clearModule(modules, "BGL");    
        PyErr_Clear(); // incase some of these were alredy removed.
 }
 
@@ -1596,6 +1599,11 @@
        return Mathutils_Init("Mathutils"); // Use as a top level module in BGE
 }
 
+PyObject* initBGL()
+{
+       return BGL_Init("BGL"); // Use as a top level module in BGE
+}
+
 void KX_SetActiveScene(class KX_Scene* scene)
 {
        gp_KetsjiScene = scene;

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.h      2009-04-07 
18:38:23 UTC (rev 19587)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.h      2009-04-07 
18:55:35 UTC (rev 19588)
@@ -45,6 +45,7 @@
 PyObject*      initRasterizer(class RAS_IRasterizer* rasty,class RAS_ICanvas* 
canvas);
 PyObject*      initGamePlayerPythonScripting(const STR_String& progname, 
TPythonSecurityLevel level, struct Main *maggie);
 PyObject*      initMathutils();
+PyObject*      initBGL();
 PyObject*      initVideoTexture(void); 
 void           exitGamePlayerPythonScripting();
 PyObject*      initGamePythonScripting(const STR_String& progname, 
TPythonSecurityLevel level, struct Main *maggie);

Modified: trunk/blender/source/gameengine/Ketsji/SConscript
===================================================================
--- trunk/blender/source/gameengine/Ketsji/SConscript   2009-04-07 18:38:23 UTC 
(rev 19587)
+++ trunk/blender/source/gameengine/Ketsji/SConscript   2009-04-07 18:55:35 UTC 
(rev 19588)
@@ -22,6 +22,11 @@
        '#source/blender/python/api2_2x/bpy_internal_import.c'
 ])
 
+
+sources.extend([\
+       '#source/blender/python/api2_2x/BGL.c'
+])
+
 incs = '. #source/blender/python/api2_2x' # Only for Mathutils! and 
bpy_internal_import.h, be very careful
 
 incs += ' #source/kernel/gen_system #intern/string #intern/guardedalloc'


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to