Re: [PyOpenGL-Users] Request for help for updating OpenGL view
Brought to you by:
mcfletch
|
From: Mike C. F. <mcf...@ro...> - 2003-01-24 03:06:53
|
I'm assuming you're using Tkinter with Togl (because that's the only
auto-spin functionality I'm aware of). What you'll want to do is trigger
redraws:
When the robot changes values (if the robot is always changing
values, then just ignore updates more recent than the maximum frame-rate
would suggest (there are more professional ways, involving timers, but
if the robot is always changing, it doesn't really matter)).
When the window changes size/shape.
When the user requests a viewing-position change (these will likely
be mouse-generated callbacks, so you normally don't worry about them).
Most GUI libraries have something simple like window.Refresh() to cause
a window to refresh it's contents (including the OpenGL windows). I
don't remember the Tk version's name.
You can find code in OpenGLContext that does multiple-thread negotiation
(though it doesn't discard update requests to enforce a maximum
frame-rate) using standard threading primitives (Locks, Events,
etceteras). It supports dropping CPU use if there's no pending renders
under wx and GLUT (not Pygame, however). Particularly, see the
context.py module, with focus on:
Context.setupThreading,
Context.triggerRedraw,
Context.shouldRedraw, and
Context.drawPoll.
That code appears to work (though slowly (it uses entire-scenegraph
locking, which causes pretty high rates of blocking)) under GLUT,
Pygame, and wxPython, but hasn't had extensive testing even there. I
haven't used Tkinter more than glancingly in... well... it's been a
while :) , so you can imagine how much testing it's had there ;) .
There are people who've apparently used Twisted (asynchronous event
framework) with PyOpenGL, that might be useful for your task instead of
threading, but I've got nothing to go on other than that the Twisted
project describes it in their testimonials.
Hope that's some help,
Mike
Douglas S. Blank wrote:
>PyOpenGL-users,
>
>I was wondering if someone could point me to some example code, or give me
>some hints. Here's what I need to do:
>
>I have a GUI that has one Python thread updating some values (a robot's
>sensors actually), and I'd like to have an OpenGL view of the robot updated as
>often as possible without stressing the computer too much. The OpenGL should
>draw the robot and sensors, but also allow rotating/zooming/etc the view of
>the robot via the mouse, or programmatically.
>
>I have a hacky version working that uses the do_AutoSpin method, but sets
>xspin and yspin to 0 so that it doesn't really spin it, but it does update the
>window:
>
> def refresh(self):
> self.win.autospin = 1
> self.win.xspin = 0
> self.win.yspin = 0
> self.win.after(500, self.win.do_AutoSpin)
>
>Besides being hacky, this has some problems:
>
> 1. it uses about 98% of a CPU
> 2. If you change the view (rotate/zoom the robot) in the OpenGL window, you
>have to run the above refresh() method again
>
>Can any help point me to the proper way of having this functionality?
>
>Thanks in advance!
>
>-Doug
>
>
_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
|