[wxPython] wxGLCanvas

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] wxGLCanvas

Bob Tolbert-2
I have been playing around with the OpenGL canvas for some simple visualization I need and I am impressed with the simple implementation. I can either leave it in Python or port it to C/C++ if I need the speed.  BUT, I am having a problem understanding how to send arrays to OpenGL methods via the SWIG interface in wxPython. For a specific example, say I want to place a light.
 
in C:
 
GLfloat light_position[] = {1.0,1.0,1.0,0.0};
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
 
in wxPython I have seen other examples such that I might expect this to work:
 
light_position = (1.0, 1.0, 1.0, 0.0)
glLightfv(GL_LIGHT0, GL_POSITION, light_position)
 
so the the position is sent as a tuple.  This however gives the an argument type error. Expected type for argument 3 is _GLfloat_p.
 
I've noticed that the demo OpenGL program doesn't have any of these OpenGL calls that require an array of values. Any ideas or pointers to more detailed examples.
 
Thanks,
Bob
 
 
Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] wxGLCanvas

Robin Dunn
I have been playing around with the OpenGL canvas for some simple visualization I need and I am impressed with the simple implementation. I can either leave it in Python or port it to C/C++ if I need the speed.  BUT, I am having a problem understanding how to send arrays to OpenGL methods via the SWIG interface in wxPython. For a specific example, say I want to place a light.
 
in C:
 
GLfloat light_position[] = {1.0,1.0,1.0,0.0};
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
 
in wxPython I have seen other examples such that I might expect this to work:
 
light_position = (1.0, 1.0, 1.0, 0.0)
glLightfv(GL_LIGHT0, GL_POSITION, light_position)
 
so the the position is sent as a tuple.  This however gives the an argument type error. Expected type for argument 3 is _GLfloat_p.
 
This is because the glcanvas module was done very quickly (pretty much all cut and paste) and with very little understanding of OpenGL. 
 
There are two paths I can take here.  I can add some typemaps so things like this work, but still not knowing much about OpenGL will probably get in the way.  (Should all the pointer parameters be changed to allow a tuple of values?  What about the GLvoid*'s?) 
 
The second option is to drop my wrappers of all the GL functions and make the glue that will allow the wxGLCanvas to be useable from David Ascher's OpenGL Python module. (http://starship.python.net:9673/crew/da/Code/PyOpenGL/)
 
Preferences?
 
--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!
Reply | Threaded
Open this post in threaded view
|

RE: [wxPython] wxGLCanvas

Mike  Fletcher
In reply to this post by Bob Tolbert-2
Attached uses wxPython with PyOpenGL.  This is just the cone demo from
PyOpenGL combined with the wxGLCanvas demo from wxPython.  Effectively, it
demonstrates that there's no "glue" required for the PyOpenGL stuff.  Once
you have an OpenGL canvas, call set-current on that canvas, then do the
regular OpenGL calls (thanks to David Ascher for confirming that
assumption).

Cheers,
Mike


-----Original Message-----
From: Robin Dunn [mailto:[hidden email]]
Sent: Monday, December 13, 1999 1:00 PM
To: Bob Tolbert; [hidden email]
Subject: Re: [wxPython] wxGLCanvas
 ...
This is because the glcanvas module was done very quickly (pretty much all
cut and paste) and with very little understanding of OpenGL.  

There are two paths I can take here.  I can add some typemaps so things like
this work, but still not knowing much about OpenGL will probably get in the
way.  (Should all the pointer parameters be changed to allow a tuple of
values?  What about the GLvoid*'s?)  

The second option is to drop my wrappers of all the GL functions and make
the glue that will allow the wxGLCanvas to be useable from David Ascher's
OpenGL Python module.
(http://starship.python.net:9673/crew/da/Code/PyOpenGL/)
...


wxglcanvas.py (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] wxGLCanvas

Robin Dunn
> Attached uses wxPython with PyOpenGL.  This is just the cone demo from
> PyOpenGL combined with the wxGLCanvas demo from wxPython.  Effectively, it
> demonstrates that there's no "glue" required for the PyOpenGL stuff.  Once
> you have an OpenGL canvas, call set-current on that canvas, then do the
> regular OpenGL calls (thanks to David Ascher for confirming that
> assumption).
>

That's good news, but unfortunately it's not working for me.  I see the cone
when the window is first displayed, but on the next paint event the window
clears and nothing ever comes back.  Any ideas?

This is on NT with PyOpenGL (from the OpenGL.exe installer) downloaded today.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] wxGLCanvas

Robin Dunn
In reply to this post by Bob Tolbert-2
Nope.  Still no luck for me.  I thought maybe it was some difference between
the released 2.1.11 and my current workspace, but I tried it on another
machine with 2.1.11 installed and it behaves the same way.

BTW, you shouldn't call OnPaint from OnSize because OnPaint creates a
wxPaintDC which should only be created when an EVT_PAINT is active.  To
request that a window be repainted you should use self.Refresh().  But then
again, there should be a paint event generated by the system automatically
when the window is sized.

Ah, I found the problem, though I'm not sure why it works for you...  It's
the little OnPaint trick you did with OnPaintGeneral.  Since wxPython event
handlers store a reference to the handler function instead of looking it up
each time it will always call the original, so self.GLInit was being called
on each paint event.

Attached is what works for me.

BTW, if you want to come up with a cooler sample GL drawing for the demo,
maybe with some mouse interaction (rotating, scaling, etc.) I would
appreciate it.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!




----- Original Message -----
From: "Mike Fletcher" <[hidden email]>
To: "'Robin Dunn'" <[hidden email]>
Sent: Monday, December 13, 1999 8:34 PM
Subject: RE: [wxPython] wxGLCanvas


> Hmm, could be I sent a previous version (which displayed the same problem
> due to an incorrectly placed pushmatrix (in essence, when the redraw was
> done, the cone had moved out of the viewing frustrum, so you just get a
> blank black screen))... try the attached (which is working correctly on NT
> with the PyOpenGL also downloaded this evening as an installer).
>
> Enjoy,
> Mike
>
> -----Original Message-----
> From: Robin Dunn [mailto:[hidden email]]
> Sent: Monday, December 13, 1999 11:17 PM
> To: Mike Fletcher; Bob Tolbert
> Cc: [hidden email]
> Subject: Re: [wxPython] wxGLCanvas
>
>
> > Attached uses wxPython with PyOpenGL.  This is just the cone demo from
> > PyOpenGL combined with the wxGLCanvas demo from wxPython.  Effectively,
it
> > demonstrates that there's no "glue" required for the PyOpenGL stuff.
Once
> > you have an OpenGL canvas, call set-current on that canvas, then do the
> > regular OpenGL calls (thanks to David Ascher for confirming that
> > assumption).
> >
>
> That's good news, but unfortunately it's not working for me.  I see the
cone

> when the window is first displayed, but on the next paint event the window
> clears and nothing ever comes back.  Any ideas?
>
> This is on NT with PyOpenGL (from the OpenGL.exe installer) downloaded
> today.
>
> --
> Robin Dunn
> Software Craftsman
> [hidden email]
> http://AllDunn.com/robin/
> http://AllDunn.com/wxPython/  Check it out!
>
>
>
> _______________________________________________
> wxPython-users maillist  -  [hidden email]
> http://starship.python.net/mailman/listinfo/wxpython-users
>
>

wxglcanvas.py (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: [wxPython] wxGLCanvas

Mike  Fletcher
In reply to this post by Bob Tolbert-2
Will be a while (couple of weeks?) before I have a chance to get to creating
a more advanced demo due to work on my primary project.  If someone wants to
do it in the meantime, they should feel free.  Even when I do get to it, I'm
more interested in trying to port a sceneGraph engine in (which would
include the cool manipulation stuff, of course) than mucking around with the
low-level OpenGL stuff.  Still, if there's a need, I suppose I can steal
someone's code for the low-level stuff :) .

Okay, I'm off to bed.  Night all,
Mike

-----Original Message-----
From: Robin Dunn [mailto:[hidden email]]
Sent: Tuesday, December 14, 1999 12:09 AM
To: Mike Fletcher
Cc: wxPython-users
Subject: Re: [wxPython] wxGLCanvas


...
BTW, if you want to come up with a cooler sample GL drawing for the demo,
maybe with some mouse interaction (rotating, scaling, etc.) I would
appreciate it.
...

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users