Python from C/SDL

Mike C. Fletcher mcfletch at rogers.com
Sat Sep 7 06:38:43 EDT 2002


I'll just deal with the OpenGL stuff.  Basically, PyOpenGL-based apps 
should be able to work like this:

c draw():
	context = new MyContext;
	context.set_current();
	err = Py*_Call*( size );

	python:
		def render( dimensions ):
			do_your_rendering_here()
			return

c:
	swap_buffers();
	context.unset_current();

So, you'd likely need to find, somewhere in pymol, a function to call 
which is _after_ the Python context setup and set_current() which you 
can call.  Depending on the architecture of pymol, that's likely to 
require at least sub-classing, and possibly some re-writing, as most 
rendering libs go out of their way to be sure they're using the "right" 
context before any attempt to render, and most apps assume they'll be 
using a context they set up.  You'll likely need to pass size of the 
window from your code, as some renderers assume they know the current 
size of the rendering context (which they won't if they aren't getting 
their resize events).

For example, in OpenGLContext, you'd subclass a Context and override 
setCurrent and unsetCurrent to do nothing (or more professionally, you'd 
create C "extending" functions that set the appropriate context for your 
app, which would allow the Python system to have its own contexts 
alongside yours if you wished).  In other frameworks those calls aren't 
actually split out into easily overridable methods (it's only required 
if you're targetting multiple GUI libs), so you might have to re-write 
anywhere you see "set current" methods called.    Would suggest 
contacting the creator of PyMol for suggestions where to apply your lever.

For a "full" job of creating a PyOpenGL embedded system, you'd also 
provide initialisation/creation functions to allow Python code to create 
a context within your app (e.g. setting display modes).

There are similar questions asked once in a while, but not particularly 
with pymol AFAIK.  "How do I embed PyOpenGL apps" is the basic template. 
  Suppose I should create a tutorial for it, but I've never done it 
directly myself (though conceptually every context in OpenGLContext is 
"embedded" in the GUI library it uses, since those are all C libs, it's 
just that I do the "calling into Python" from the libs own Python wrappers).

HTH,
Mike
BTW: out of town in a few minutes, so won't be available to clarify 
anything 'til Monday, sorry.

Chris Gonnerman wrote:
> ----- Original Message ----- 
> From: "Gib Bogle" <bogle at ihug.co.nz>
> 
> 
>>Hi,
>>
>>I am a complete beginner with Python.  My interest in it is focussed on
>>a great piece of open-source software called pymol, a system for
>>visualization of molecules that uses Python and OpenGL.  I'd like to get
>>access to pymol's graphical functions from my own program, which is
>>built from C, SDL and OpenGL.
> 
...
>>I will not want to use the GUI at all.  SDL would
>>create the surface(s), and handle the buffer swapping.  My goal is to be
>>able to send a request to the pymol API asking for a frustum view to be
>>rendered on the provided surface.
>>
>>Sorry if my question is one that gets asked and answered frequently.  If
>>there is a place where this has been dealt with please direct me.
> 
> 
> Never heard this one before...
> 
> Good luck!
> 
> 
> Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net
> http://newcenturycomputers.net
> 
> 

-- 
_______________________________________
   Mike C. Fletcher
   Designer, VR Plumber, Coder
   http://members.rogers.com/mcfletch/






More information about the Python-list mailing list