[GtkGLExt] GObject Introspection



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I made a patch for
git://github.com/tdz/gtkglext.git
to create *.gir and *.typelib
This is based on the branch from Anton Gorenko:
https://github.com/ex-rzr/gtkglext.git

I also ported the example rotating-square.c to Python.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJPu3zDAAoJEEDg0A3D0GN4bdYP/01xJeDqMeDjO8w+67QjGDvd
VSBC+gGxIcjeHkImemaVL5lo3m/4Q5SBZP/ak/mNM+Lw5EDtp6xVUaXjH+lF1UTh
iDnnlzDJHFun798gUyez51WxlIGv2GKL0mLwa579s0Bo2+sdOFDQet+SBq+7Omp3
gzu0BUKxNHIrRaLUcY9ZzGetelrlyrK05/nwL0Xq45d5n3e9PKkNaUGeifjsgw28
G0BxQT5YO3OXZXN2BgQaR9QoKKVpltBe0qyMMqoMBvIPWnLU0ul5/rjliHDkalSA
aKT19RRmlrSRWZrZIbxHz2vyCHiaRmgKVCSeBMSVE3sJRutPHaSP9HG+BtuMDGFs
3MxGVlZ2/DSYxzKox0Qij+mM3IILiYkLjV40px+TARJalgQR+OFjqbvyb506g8OW
8Fse6avjwmhTvsWLjrdyiOuQRsXC0H1vhyqKrk3oOqz5X4NBet1XmQFV2A5BUfBe
EKM8EQciuxVraaoE9qNLBv0YaHKKB0tIQA0l4lR/DcKpuXtIGEqzn4mK+Yq5PDAm
hbZsUbC8fWxGnjA5gv0+KrKL8IWEL9UaAFhWZw1x/w3rED3/GNMAol4PfGSOQFxb
9J/cP3NN8H6HCxDk0Zf9OMfHZN4XHovqj2rgFK5Rezzs7I3ZyCeFf2xdd+PZfEV/
yr7exAkoDrEMvFRRC1ox
=vWgE
-----END PGP SIGNATURE-----

=== modified file 'Makefile.am'
--- Makefile.am	2012-03-13 20:40:48 +0000
+++ Makefile.am	2012-05-22 09:22:18 +0000
@@ -4,7 +4,7 @@
 SUBDIRS = gdk gtk docs examples
 
 ACLOCAL_AMFLAGS = -I m4macros
-DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc
+DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc --enable-introspection
 
 EXTRA_DIST = \
 	README.win32			\

=== modified file 'configure.ac'
--- configure.ac	2012-03-13 20:40:48 +0000
+++ configure.ac	2012-05-22 09:22:18 +0000
@@ -114,6 +114,12 @@
 AC_PATH_PROGS([PERL], [perl5 perl])
 
 ##################################################
+# GObject introspection
+##################################################
+
+GOBJECT_INTROSPECTION_CHECK([1.30.0])
+
+##################################################
 # Checks for gtk-doc and docbook-tools
 ##################################################
 

=== modified file 'gdk/Makefile.am'
--- gdk/Makefile.am	2012-03-26 18:49:10 +0000
+++ gdk/Makefile.am	2012-05-22 09:22:18 +0000
@@ -4,6 +4,8 @@
 SUBDIRS = $(GDKGLEXT_BACKENDS)
 DIST_SUBDIRS = x11 win32
 
+CLEANFILES =
+
 EXTRA_DIST = \
 	gdkglversion.h.in	\
 	gdkglext.def
@@ -177,5 +179,49 @@
   gtkglenumtypes.c.template
 
 #
+# Introspection
+#
+
+-include $(INTROSPECTION_MAKEFILE)
+INTROSPECTION_GIRS =
+INTROSPECTION_SCANNER_ARGS =
+INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir)
+
+if HAVE_INTROSPECTION
+introspection_sources = \
+	$(filter-out gdkgldebug.h gdkglglext.h, $(gdkglext_headers)) \
+	$(gdkglext_c_sources) \
+	$(gdkglext_built_c_sources)
+
+if USE_X11
+introspection_sources += \
+	x11/gdkglconfig-x11.c	\
+	x11/gdkglcontext-x11.c	\
+	x11/gdkglquery-x11.c	\
+	x11/gdkglwindow-x11.c
+endif # USE_X11
+
+GdkGLExt-1.0.gir: $(gdkglext_targetlib)
+GdkGLExt_1_0_gir_INCLUDES = Gdk-3.0
+GdkGLExt_1_0_gir_SCANNERFLAGS = \
+	--warn-all \
+	--identifier-prefix=GdkGL \
+	--symbol-prefix=gdk_gl \
+	--symbol-prefix=gdk
+GdkGLExt_1_0_gir_CFLAGS = $(common_includes)
+GdkGLExt_1_0_gir_LIBS = $(gdkglext_targetlib)
+GdkGLExt_1_0_gir_FILES = $(introspection_sources)
+INTROSPECTION_GIRS += GdkGLExt-1.0.gir
+
+girdir = $(datadir)/gir-1.0
+gir_DATA = $(INTROSPECTION_GIRS)
+
+typelibdir = $(libdir)/girepository-1.0
+typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
+
+CLEANFILES += $(gir_DATA) $(typelib_DATA)
+endif # HAVE_INTROSPECTION
+
+#
 # Extra rules
 #

=== modified file 'gtk/Makefile.am'
--- gtk/Makefile.am	2012-03-13 20:40:48 +0000
+++ gtk/Makefile.am	2012-05-22 09:22:18 +0000
@@ -1,6 +1,8 @@
 ## -*- Makefile -*-
 ## Makefile.am for gtkglext/gtk
 
+CLEANFILES =
+
 EXTRA_DIST = \
 	gtkglversion.h.in	\
 	gtkglext.def
@@ -84,3 +86,38 @@
 libgtkglext_@API_MJ@_@API_MI@_la_SOURCES = $(gtkglext_sources)
 libgtkglext_@API_MJ@_@API_MI@_la_LDFLAGS = $(common_ldflags)
 libgtkglext_@API_MJ@_@API_MI@_la_LIBADD = $(common_libadd)
+
+#
+# Introspection
+#
+
+-include $(INTROSPECTION_MAKEFILE)
+INTROSPECTION_GIRS =
+INTROSPECTION_SCANNER_ARGS = --add-include-path=../gdk
+INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir) --includedir=../gdk
+
+if HAVE_INTROSPECTION
+introspection_sources = \
+	$(gtkglext_public_h_sources) \
+	$(gtkglext_c_sources)
+
+GtkGLExt-1.0.gir: $(gtkglext_targetlib)
+GtkGLExt_1_0_gir_INCLUDES = Gtk-3.0 GdkGLExt-1.0
+GtkGLExt_1_0_gir_SCANNERFLAGS = \
+	--warn-all \
+	--identifier-prefix=GtkGL \
+	--symbol-prefix=gtk_gl \
+	--symbol-prefix=gtk
+GtkGLExt_1_0_gir_CFLAGS = $(common_includes)
+GtkGLExt_1_0_gir_LIBS = $(gtkglext_targetlib)
+GtkGLExt_1_0_gir_FILES = $(introspection_sources)
+INTROSPECTION_GIRS += GtkGLExt-1.0.gir
+
+girdir = $(datadir)/gir-1.0
+gir_DATA = $(INTROSPECTION_GIRS)
+
+typelibdir = $(libdir)/girepository-1.0
+typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
+
+CLEANFILES += $(gir_DATA) $(typelib_DATA)
+endif # HAVE_INTROSPECTION

=== modified file 'gtk/gtkglwidget.c'
--- gtk/gtkglwidget.c	2012-03-22 17:42:49 +0000
+++ gtk/gtkglwidget.c	2012-05-22 09:26:58 +0000
@@ -235,7 +235,7 @@
  * gtk_widget_set_gl_capability:
  * @widget: the #GtkWidget to be used as the rendering area.
  * @glconfig: a #GdkGLConfig.
- * @share_list: the #GdkGLContext with which to share display lists and texture
+ * @share_list: (allow-none): the #GdkGLContext with which to share display lists and texture
  *              objects. NULL indicates that no sharing is to take place.
  * @direct: whether rendering is to be done with a direct connection to
  *          the graphics system.

#!/usr/bin/python
# -*- coding: utf-8 -*-

# rotatingSquare.py
# A simple animation to demonstrate GtkGLExt.
#
# Copyright © 2012  B. Clausius <barcc gmx de>
# This program is in the public domain and you are using it at your own risk.
#
# This program is a port of rotatingSquare.c by
# Alif Wahid <awah005 users sourceforge net> and
# Naofumi Yasufuku  <naofumi users sourceforge net>

import sys

from gi.repository import Gtk, Gdk, GLib
from gi.repository import GtkGLExt, GdkGLExt
from OpenGL import GL


DEFAULT_WIDTH = 200
DEFAULT_HEIGHT = 200
DEFAULT_TITLE = "Rotating Square"


animate = True
spin = 0.


# The following section contains all the callback function definitions.

def realize(widget, data):
    '''The "realize" signal handler. All the OpenGL initialization
    should be performed here, such as default background colour,
    certain states etc.'''

    # OpenGL BEGIN
    if not GtkGLExt.widget_begin_gl(widget):
        return

    GL.glClearColor(0., 0., 0., 0.)
    GL.glShadeModel(GL.GL_FLAT)

    GtkGLExt.widget_end_gl(widget, False)
    # OpenGL END

def configure_event(widget, event, data):
    '''The "configure_event" signal handler. Any processing required when
    the OpenGL-capable drawing area is re-configured should be done here.
    Almost always it will be used to resize the OpenGL viewport when
    the window is resized.'''

    allocation = widget.get_allocation()
    w = allocation.width
    h = allocation.height

    # OpenGL BEGIN
    if not GtkGLExt.widget_begin_gl(widget):
        return False

    GL.glViewport(0, 0, w, h)
    GL.glMatrixMode(GL.GL_PROJECTION)
    GL.glLoadIdentity()
    GL.glOrtho(-50., 50., -50., 50., -1., 1.)
    GL.glMatrixMode(GL.GL_MODELVIEW)
    GL.glLoadIdentity()

    GtkGLExt.widget_end_gl(widget, False)
    # OpenGL END

    return True

def draw (widget, cr, data):
    '''The "draw" signal handler. All the OpenGL re-drawing should
    be done here. This is repeatedly called as the painting routine
    every time the 'draw' event is signalled.'''

    # OpenGL BEGIN
    if not GtkGLExt.widget_begin_gl(widget):
        return False

    GL.glClear(GL.GL_COLOR_BUFFER_BIT)

    GL.glPushMatrix()
    GL.glRotatef(spin, 0., 0., 1.)
    GL.glColor3f(1., 1., 1.)
    GL.glRectf(-25., -25., 25., 25.)
    GL.glPopMatrix()

    GtkGLExt.widget_end_gl(widget, True)
    # OpenGL END

    return True

def idle(widget):
    '''The idle function. Often in animations,
    idle functions are suitable for continous
    frame updates.'''

    global spin

    window = widget.get_window()
    allocation = widget.get_allocation()

    spin += 2.
    if spin > 360.:
        spin -= 360.

    # Invalidate the whole window.
    window.invalidate_rect(allocation, False)

    # Update synchronously.
    window.process_updates(False)

    return True

def motion_notify_event(widget, event, data):
    '''The "motion_notify_event" signal handler. Any processing required when
    the OpenGL-capable drawing area is under drag motion should be done here.'''

    # Fill in the details here.
    return False

def button_press_event(widget, event, data):
    '''The "button_press_event" signal handler. Any processing required when
    mouse buttons (only left and middle buttons) are pressed on the OpenGL-
    capable drawing area should be done here.
    
    Starts/Stops animation according mouse button clicks.
    '''
    if event.button == 1:
        toggle_animation(widget)
        return True
    return False

def button_press_event_popup_menu(widget, event):
    '''For popup menu.'''
    
    if event.button == 3:
        # Popup menu.
        widget.popup(None, None, None, None, event.button, event.time)
        return True
    return False

def key_press_event(widget, event):
    '''The "key_press_event" signal handler. Any processing required when key
    presses occur should be done here.'''
    
    global spin

    window = widget.get_window()
    allocation = widget.get_allocation()

    if event.keyval == Gdk.KEY_Left:
        # Rotate left.
        if not animate:
            spin += 2.
            if spin > 360.:
                spin -= 360.
            window.invalidate_rect(allocation, False)
    elif event.keyval == Gdk.KEY_Right:
        # Rotate right.
        if not animate:
            spin -= 2.
            if spin < 360.:
                spin += 360.
            window.invalidate_rect(allocation, False)
    elif event.keyval == Gdk.KEY_a:
        # Toggle animation.
        toggle_animation(widget)
    elif event.keyval == Gdk.KEY_Escape:
        # Quit.
        Gtk.main_quit()
    else:
        return False

    return True

def unrealize(widget, data):
    '''The "unrealize" signal handler. Any processing required when
    the OpenGL-capable window is unrealized should be done here.'''
    
    # Fill in the details here
    pass


#
# The following section contains the idle function management routines.
#

# Helper functions to add or remove the idle function.

idle_id = 0

def idle_add(widget):
    global idle_id
    if idle_id == 0:
        #idle_id = GLib.idle_add(idle, widget, priority=Gdk.PRIORITY_REDRAW+100)
        idle_id = GLib.timeout_add(8, idle, widget, priority=Gdk.PRIORITY_REDRAW+100)

def idle_remove(widget):
    global idle_id
    if idle_id != 0:
        GLib.source_remove(idle_id)
        idle_id = 0

def map_event(widget, event, data):
    '''The "map_event" signal handler. Any processing required when the
    OpenGL-capable drawing area is mapped should be done here.'''
    
    if animate:
        idle_add(widget)
    return True

def unmap_event(widget, event, data):
    '''The "unmap_event" signal handler. Any processing required when the
    OpenGL-capable drawing area is unmapped should be done here.'''
    
    idle_remove(widget)
    return True

def visibility_notify_event(widget, event, data):
    '''The "visibility_notify_event" signal handler. Any processing required
    when the OpenGL-capable drawing area is visually obscured should be
    done here.'''
    
    if animate:
        if event.state == Gdk.VisibilityState.FULLY_OBSCURED:
            idle_remove(widget)
        else:
            idle_add(widget)
    return True


#
#  The following section contains some miscellaneous utility functions.
#

def toggle_animation(widget):
    '''Toggle animation.'''
    
    global animate
    animate = not animate

    if animate:
        idle_add(widget)
    else:
        idle_remove(widget)
        allocation = widget.get_allocation()
        widget.get_window().invalidate_rect(allocation, False)


#
# The following section contains the GUI building function definitions.
#

def create_popup_menu(drawing_area):
    '''Creates the popup menu to be displayed.'''
    
    menu = Gtk.Menu()

    # Toggle animation
    menu_item = Gtk.MenuItem.new_with_label("Toggle Animation")
    menu.append(menu_item)
    menu_item.connect_object("activate", toggle_animation, drawing_area)
    menu_item.show()

    # Quit
    menu_item = Gtk.MenuItem.new_with_label("Quit")
    menu.append(menu_item)
    menu_item.connect("activate", Gtk.main_quit)
    menu_item.show()

    return menu

def create_window(glconfig):
    '''Creates the simple application window with one
    drawing area that has an OpenGL-capable visual.'''

    ## Top-level window.

    window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
    window.set_title(DEFAULT_TITLE)

    # Get automatically redrawn if any of their children changed allocation.
    window.set_reallocate_redraws(True)

    # Connect signal handlers to the window
    window.connect("delete_event", Gtk.main_quit)

    ## VBox.

    vbox = Gtk.VBox(False, 0)
    window.add(vbox)
    vbox.show()

    ## Drawing area to draw OpenGL scene.

    drawing_area = Gtk.DrawingArea()
    drawing_area.set_size_request(DEFAULT_WIDTH, DEFAULT_HEIGHT)

    # Set OpenGL-capability to the widget
    GtkGLExt.widget_set_gl_capability(drawing_area,
                  glconfig,
                  None,
                  True,
                  GdkGLExt.RenderType.RGBA_TYPE)
    drawing_area.add_events(
               Gdk.EventMask.BUTTON1_MOTION_MASK    |
               Gdk.EventMask.BUTTON2_MOTION_MASK    |
               Gdk.EventMask.BUTTON_PRESS_MASK      |
               Gdk.EventMask.VISIBILITY_NOTIFY_MASK)

    # Connect signal handlers to the drawing area
    drawing_area.connect_after("realize", realize, None)
    drawing_area.connect("configure_event", configure_event, None)
    drawing_area.connect("draw", draw, None)

    drawing_area.connect("motion_notify_event", motion_notify_event, None)
    drawing_area.connect("button_press_event", button_press_event, None)
    drawing_area.connect("unrealize", unrealize, None)

    # key_press_event handler for top-level window
    window.connect_object("key_press_event", key_press_event, drawing_area)

    # For idle function.
    drawing_area.connect("map_event", map_event, None)
    drawing_area.connect("unmap_event", unmap_event, None)
    drawing_area.connect("visibility_notify_event", visibility_notify_event, None)

    vbox.pack_start(drawing_area, True, True, 0)
    drawing_area.show()

    # Popup menu.

    menu = create_popup_menu(drawing_area)
    drawing_area.connect_object("button_press_event", button_press_event_popup_menu, menu)

    ## Simple quit button.

    button = Gtk.Button.new_with_label("Quit")
    button.connect("clicked", Gtk.main_quit)
    vbox.pack_start(button, False, False, 0)
    button.show()

    return window


#
# The following section contains utility function definitions.
#

def configure_gl():
    '''Configure the OpenGL framebuffer.'''

    # Try double-buffered visual
    glconfig = GdkGLExt.Config.new_by_mode(GdkGLExt.ConfigMode.RGB |
                                           GdkGLExt.ConfigMode.DEPTH |
                                           GdkGLExt.ConfigMode.DOUBLE)
    if glconfig == None:
        print "\n*** Cannot find the double-buffered visual."
        print "\n*** Trying single-buffered visual."

        # Try single-buffered visual
        glconfig = GdkGLExt.Config.new_by_mode(GdkGLExt.ConfigMode.RGB |
                                               GdkGLExt.ConfigMode.DEPTH)
        if glconfig == None:
            print "*** No appropriate OpenGL-capable visual found."
            sys.exit(1)

    return glconfig


#
# The main function is rather trivial.
#

def main(argv):
    # Configure OpenGL framebuffer.
    glconfig = configure_gl()

    # Create and show the application window.
    window = create_window(glconfig)
    window.show()

    Gtk.main()
    return 0


if __name__ == '__main__':
    sys.exit(main(sys.argv))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]