Search code examples
pythonopenglgtkpygtkpyopengl

Python, OpenGL, and GTK.


I want a GTK GUI with two OpenGL areas that will have different scenes drawn onto them. Does anyone know of an example of code that does this?

This blog post offers an full working example but when I try to add a second OpenGL drawing area, it seems that OpenGL draws both scenes to the same widget. This, of course, is wrong.


Solution

  • You can use any number of those:

        widget = self.gtkBuilder.get_object('OpenGLDrawAreaOpenGLFuBar')
        self.OpenGLGizmo['fubar'] = OPenGLFuBar()
        glarea = gtk.gtkgl.DrawingArea( glconfig=self.glconfig,
                                        share_list=None,
                                        render_type=gtk.gdkgl.RGBA_TYPE)
        self.OpenGLWidget['fubar'] = glarea
        glarea.set_size_request(333, 333)
        red = (1.0, 0.0, 0.0, 0.0)
        glarea.connect_after('realize', self.OpenGLGizmo['fubar'].realize_main)
        glarea.connect('configure_event', self.OpenGLGizmo['fubar'].configure_event)
        glarea.connect('expose_event', self.OpenGLGizmo['fubar'].expose_event)
        glarea.set_flags(gtk.HAS_FOCUS | gtk.CAN_FOCUS)
        glarea.add_events(gtk.gdk.KEY_PRESS_MASK)
        glarea.connect('key_press_event', self.OpenGLGizmo['fubar'].key_callback)
        widget.add(glarea)
        glarea.show()
        glarea.realize()
        glarea.grab_focus()