55
<title>Contributing to OpenGL-ctypes</title><link rel="stylesheet" type="text/css" href="style/tutorial.css">
76
<meta name="author" content="Mike C. Fletcher"></head>
60
<title>Contributing to OpenGL-ctypes</title>
61
<link rel="stylesheet" type="text/css" href="style/tutorial.css">
84
<meta name="author" content="Mike C. Fletcher">
887
964
<li>Portability (note, we are
888
965
limited to ctypes ported platforms,
889
966
but that should grow faster than we grow, given that ctypes is now part
1027
1116
<li>ctypes library objects for
1028
1117
GL, GLU, GLUT and possibly GLE. How we
1029
1118
find these libraries, the names of the libraries, flags needed for
1137
1234
<li>function safeGetError() to retrieve OpenGL's error state if doing
1138
1235
so would be safe (i.e. we have a valid context or the platform can
1139
handle having a call to glGetError when there is no valid context)</li><li>functions/methods
1236
handle having a call to glGetError when there is no valid context)</li>
1237
<li>functions/methods
1140
1238
to create/retrieve function pointers from libraries (createBaseFunction
1141
1239
and createExtensionFunction), which insulate us from changes in
1142
1240
ctypes as well as giving us a convenient
1143
place to add functionality to any function.<pre><code>def createBaseFunction( <br> functionName, dll=OpenGL, <br> resultType=ctypes.c_int, argTypes=(),<br> doc = None, argNames = (),<br>):</code><br></pre>
1165
<pre><code>def createExtensionFunction( <br> functionName, dll=OpenGL,<br> resultType=ctypes.c_int, <br> argTypes=(),<br> doc = None, argNames = (),<br>):</code></pre>
1241
place to add functionality to any function.
1242
<pre><code>def createBaseFunction( <br> functionName, dll=OpenGL, <br> resultType=ctypes.c_int, argTypes=(),<br> doc = None, argNames = (),<br>):</code><br></pre>
1266
<pre><code>def createExtensionFunction( <br> functionName, dll=OpenGL,<br> resultType=ctypes.c_int, <br> argTypes=(),<br> doc = None, argNames = (),<br>):</code></pre>
1222
1328
<p>There are two major wrapper generator systems available for use with
1223
1329
ctypes. Originally OpenGL-ctypes used the ctypes generator module
1224
1330
(based on GCC-XML) to produce its wrappers. We are switching to
1225
1331
using the <code>pyglet/tools/wraptypes</code> module. Extension
1226
1332
modules are currently created via a regex-based generator, eventually
1227
we'll switch to using wraptypes for that work as well.</p><h4>wraptypes Generator (new method)</h4><p>The
1333
we'll switch to using wraptypes for that work as well.</p>
1334
<h4>wraptypes Generator (new method)</h4>
1228
1336
primary value of wraptypes is that it is easy to install and configure,
1229
1337
and allows for parsing headers which are not "native" to the platform
1230
1338
on which they are being run. The wrapper generator (<code>gengl.py</code>) is not as advanced/finished as the <code>openglgenerator.py</code>
1231
1339
module, but it can generate the platform-specific module quite nicely,
1232
1340
and the underlying code is under active development with a focus on
1233
GL-related operations.</p><p>To run this generator, simple check out pyglet's svn repository and add the tools/wraptypes package to your <code>PYTHONPATH</code>, then run the <code>src/gengl.py</code> module in PyOpenGL's source tree.</p><h4>ctypes Wrapper Generator (old method)</h4><p>ctypes includes a mechanism
1341
GL-related operations.</p>
1342
<p>To run this generator, simple check out pyglet's svn repository and add the tools/wraptypes package to your <code>PYTHONPATH</code>, then run the <code>src/gengl.py</code> module in PyOpenGL's source tree.</p>
1343
<h4>ctypes Wrapper Generator (old method)</h4>
1344
<p>ctypes includes a mechanism
1234
1345
based on GCC-XML which will autogenerate
1235
1346
wrappers for many C libraries. OpenGL-ctypes uses an
1236
1347
extended version of this autogenerator (in the src subdirectory of
1324
1444
<p>which produces an XML file in your local directory (here glx.xml). The <code>-c</code>
1325
1445
flag tells GCC-XML to attempt to include preprocessor definitions in
1326
1446
the XML file, which is normally desirable for GL-related systems, as
1348
1470
<p class="technical">Autogeneration has gone through many revisions
1349
1471
over the course of the project. The newest version requires a
1350
1472
heavily restructured version of the ctypes codegenerator module to work.</p>
1354
1477
<h4>OpenGL Extension Generation</h4>
1506
1640
<p>If you remove the autogenerated
1507
1641
comment then further autogeneration
1508
1642
passes will not process the module, keep in mind, however, that
2636
2866
<li>numpy module is
2637
2867
implemented in Python using a stable API</li>
2638
2869
<li>Numeric module is implemented in Python using a bit of a hack</li>
2639
2871
<li>Numarray currently requires a C extension and, at the
2640
2872
moment, is not built by default</li>
3038
<p>OpenGL-ctypes uses the setuptools/pkg_resources entry_points API to
3039
register FormatHandlers. The format handlers provided in
3040
OpenGL-ctypes are all set up by the setupegg.py script. Each
3041
binds a name (such as 'numpy' to a FormatHandler sub-class's
3042
name). You can register your own FormatHandler sub-class using
3043
code similar to this in your project's setuptools setup script:</p>
3054
<pre>from setuptools import setup, find_packages<br>if __name__ == "__main__":<br> setup(<br> ...<br> entry_points = {<br> 'OpenGL.arrays.formathandler':[<br> 'numpy = OpenGL.arrays.numpymodule:NumpyHandler',<br> ],<br> },<br> )<br></pre>
3309
<p>OpenGL-ctypes uses the simplistic OpenGL.plugins module which allows
3310
you to register a plugin instance which defines a class which is to be
3311
loaded to handle a given data format.</p>
3312
<pre>from OpenGL.plugins import FormatHandler<br>FormatHandler( 'numpy', 'OpenGL.arrays.numpymodule.NumpyHandler', ['numpy.ndarray'] )</pre>
3313
<p>The first parameter is just a name used to refer to the plugin.
3314
The second is the actual class to load. If there is not
3315
third parameter, then the plugin will automatically load. If
3316
there is a value, then the value is a list of module.classname
3317
values which will be matched against incoming array-parameter values.</p>
3065
3318
<p>OpenGL-ctypes delays resolving the FormatHandler set until the last
3066
3319
possible moment (i.e. the first call is made which requires a
3067
3320
FormatHandler). Any time before this you can use code like this
3233
3498
<p>You can override the error-handler, either to provide your own
3234
3499
custom functionality, or to disable checking entirely. For
3235
3500
instance, if you will always have a valid context, you could register
3310
3581
<p>Because of the way OpenGL and
3311
3582
ctypes handle, for instance, pointers, to array data, it is often
3312
3583
necessary to ensure that a Python data-structure is retained (i.e. not
3985
</ul><p class="footer">
4317
<p class="footer">
3986
4318
<a href="http://pyopengl.sourceforge.net/"><img alt="PyOpenGL" src="images/pyopengl_icon.jpg" style="border: 0px solid ; width: 32px; height: 32px;" align="middle"></a>A
3987
4319
SourceForge Open-Source project: <a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=5988&type=1" style="border: 0px solid ; width: 88px; height: 31px;" alt="SourceForge" align="middle"></a></p>