Newbiw - PypenGL and OpenGLContext

Mike C. Fletcher mcfletch at rogers.com
Wed Mar 30 15:25:59 EST 2005


Steve T wrote:

>I have been searching for a language to help with a product I am
>developing - last week I discovered PYOpenGL - looks really useful.  I
>found some demos which I studied to create part of what I need (a heap
>of boxes) but when I try and add an image to the box faces it looks as
>if I have to delve into OpenGLContext.  Now from here drawing boxes is
>no longer as simple.  My main driver is speed of _development_ (not
>graphics speed) so I would really like to be able to say
>box(position_vector, size_vector,texture_file).
>
>Am I on the wrong track entirely here, should I pursue OpenGLContext
>or am I misusing the visual.* parts of PYOpenGL?
>  
>
If you are really just drawing boxes, then raw PyOpenGL *may* be
appropriate, but you'll need to figure out the wonders of texturing. 
You can find some pretty good code for that in the NeHe demos (I believe
around the 6th or 7th).  They create a rotating textured, lit box, so if
that's all you need, you're golden.

If your goal is to eventually produce a more involved scene, you will
likely want one of the scenegraph engines.  Obviously I'm biased toward
OpenGLContext, but it's visual-alike package (i.e. a simplified
scenegraph model) is not yet ready for prime time, so you'd have to use
the full VRML97 model to create your boxes.  That would look something
like this:

    from OpenGLContext import testingcontext
    BaseContext, MainFunction = testingcontext.getInteractive()
    from OpenGLContext.scenegraph.basenodes import *

    class TestContext( BaseContext ):
        def OnInit( self ):
            """Initialise and set up the scenegraph"""
            self.sg = sceneGraph(
                children = [
                    Transform(
                        rotation = (0,1,0,.8),
                        children = [
                            Shape(
                                geometry = Box( size=(4,4,2) ),
                                appearance = Appearance(
                                    material = Material(
                                        diffuseColor =(1,1,1)
                                    ),
                                    texture = ImageTexture(
                                        url =
    "http://blog.vrplumber.com/images/ruminations.jpg",
                                    ),
                                ),
                            ),
                        ],
                    ),
                ],
            )
        def getSceneGraph( self ):
            """With older OpenGLContext versions need to explicitly
    return this"""
            return self.sg

    if __name__ == "__main__":
        MainFunction( TestContext )

There are other retained-mode/scenegraph engines available besides
OpenGLContext, you can find a listing of some of them here:

    http://www.vrplumber.com/py3d.py?category=retained

HTH,
Mike

________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com




More information about the Python-list mailing list