Re: [GtkGLExt] Ubuntu Packages for gtkglext 3.0 available
- From: "B. Clausius" <barcc gmx de>
- To: gtkglext-list gnome org
- Subject: Re: [GtkGLExt] Ubuntu Packages for gtkglext 3.0 available
- Date: Tue, 05 Jun 2012 13:15:18 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
sorry for the delay.
Am 29.05.2012 21:35, schrieb Thomas Zimmermann:
> Hi
>
>>> One more note. The second patch consists of changes like the
>>> one below.
>>>
>>>> + * @attrib_list: (array zero-terminated=1): a list of
>>>> attribute/value pairs.
>>>
>>> I'm wondering if it couldn't happen that one of the
>>> attribute's values is zero for a call to the annotated
>>> function, and the binding code assumes, the array has already
>>> been terminated.
>>>
>> When i created this patch, I got a segmentation fault without
>> the zero-terminated=1 when I run my Python test script
>> [attachment]. But it seams it was a bug (maybe 674271 ? [2]) in
>> pygobject 3.2.0 and fixed in 3.2.2, With the update meanwhile the
>> segmentation fault is gone. So maybe this zero-terminated=1
>> should be removed.
>
> Yes, but this certainly needs an API change.
>
> int attrib[] = { GDK_GL_DOUBLEBUFFER, FALSE, GDK_GL_RED_SIZE, 8,
> GDK_GL_GREEN_SIZE, 8, GDK_GL_BLUE_SIZE, 8, 0 };
>
> FALSE is equal to 0, so the binding code will abort there and
> never reach the RGB sizes. The only solution is to pass the array
> length as an extra parameter to the C function.
I don't think this code is correct. GDK_GL_DOUBLEBUFFER does not has
an argument, so the FALSE will be interpreted as the terminating
GDK_GL_ATTRIB_LIST_NONE in the C code anyway.
attribs = [ GdkGLExt.ConfigAttrib.DEPTH_SIZE , 0,
GdkGLExt.ConfigAttrib.RGBA,
GdkGLExt.ConfigAttrib.DOUBLEBUFFER,
GdkGLExt.ConfigAttrib.RED_SIZE, 1,
GdkGLExt.ConfigAttrib.GREEN_SIZE, 1,
GdkGLExt.ConfigAttrib.BLUE_SIZE, 1,
GdkGLExt.ATTRIB_LIST_NONE
]
With this attributes works the same whether or not the
zero-terminated=1 is there, so the array is passed by the binding to
the C function altogether without looking into it.
I dont think an API change is needed and made an new patch with the
zero-terminated removed.
>
> If you don't have a better idea, I think we should do this and
> deprecate the zero-termination completely.
>
>
>> Btw, are you interested in Python examples in your git tree?
>> They demonstrate the usage of g-i, as bindings like
>> python-gtkglext1 are not needed any more.
>
> I won't have the resources for maintaining the code, but I wouldn't
> mind putting the sources of some small, self-contained examples
> into my tree (e.g., into examples/python/).
Attached an patch with an example.
>
> Best regards Thomas
>
>
Best regards, BC
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQIcBAEBAgAGBQJPzepGAAoJEEDg0A3D0GN4epEQAJQrJcMHaVd2js+KZ2+K49+R
UaAyYNhusB1+W6AVVGhEIQoERJk15/JK3hatl1bkCyz66qRpM6gHTRqiXz59TDLG
Qo0EtQ3JDxzcQxpjVLIwU2omHuOPeP4cqYpVoJN0mQM/OyFroi+bkbQ7IFW4JjQp
kVR9mQr4Oug2QkaD9iH1F/XrlZPkCF85DlRjgmu7GkDNCd/KhDDDkHD7UCb1fvZe
95NR+LPeoAg9iQ/9aJcQjY1p88X1m9t7dMJrmLh8IcTAFT9UPNqF00XXVX0DP5MD
z6UZQW66N0UKmpm5u3ejXzE0A7hiVlKlsKoQroETfIdnTYQZLtWXfog6d8SarHIP
hEobfKN6wLW2aq4J9eaOBVRdRNC3cNuMtKzMxg3mH9M10AeLfS5/FXaSnvV5Kfg5
IwTceHYlLxcdzPBzJGL8VtSrkzpe2vuBpLOWgAJj6UGOUx++8UoQ9ix0APoIpcoS
E+CEiAb0Hn+0cy0UbwpCrrwT6W3VXGdPmB0o5j0WnSh0omDJJqfB8cejzq4emQP8
FbWlk1/COSpDuM9yVpMjT/AdRY4eJuMZRuBuA49erk2qT8l5DL6kEh1h3Pefuf2X
Dte3ofzWNHrdkFaghcVSeTCSgQxUAvgJYDms+4HORSdHVJ8UA6VY6sFTT0a7RoZo
WTPRqP8locU+211cqqVg
=FDc9
-----END PGP SIGNATURE-----
>From 317d3959b230554aa371d924a5a009c5ebf4b47e Mon Sep 17 00:00:00 2001
From: "B. Clausius" <barcc gmx de>
Date: Tue, 5 Jun 2012 12:33:06 +0200
Subject: [PATCH] Added Python example to demonstrate the gobject
introspection
The example is a port of examples/rotating-square.c
---
examples/python/rotating-square.py | 396 ++++++++++++++++++++++++++++++++++++
1 file changed, 396 insertions(+)
create mode 100755 examples/python/rotating-square.py
diff --git a/examples/python/rotating-square.py b/examples/python/rotating-square.py
new file mode 100755
index 0000000..5d63a7b
--- /dev/null
+++ b/examples/python/rotating-square.py
@@ -0,0 +1,396 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# rotating-square.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 rotating-square.c by
+# Alif Wahid <awah005 users sourceforge net> and
+# Naofumi Yasufuku <naofumi users sourceforge net>
+
+from __future__ import print_function
+
+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
+ try:
+ glconfig = GdkGLExt.Config.new_by_mode(GdkGLExt.ConfigMode.RGB |
+ GdkGLExt.ConfigMode.DEPTH |
+ GdkGLExt.ConfigMode.DOUBLE)
+ except TypeError:
+ print("*** Cannot find the double-buffered visual.")
+ print("*** Trying single-buffered visual.")
+
+ # Try single-buffered visual
+ try:
+ glconfig = GdkGLExt.Config.new_by_mode(GdkGLExt.ConfigMode.RGB |
+ GdkGLExt.ConfigMode.DEPTH)
+ except TypeError:
+ print("*** No appropriate OpenGL-capable visual found.")
+ sys.exit(1)
+
+ return glconfig
+
+
+#
+# The main function is rather trivial.
+#
+
+def main():
+ # 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())
+
--
1.7.9.5
>From c72b1c605fb14be1d87327f6bad67ca848953935 Mon Sep 17 00:00:00 2001
From: "B. Clausius" <barcc gmx de>
Date: Tue, 5 Jun 2012 12:37:21 +0200
Subject: [PATCH] Fixed filename in comment
---
examples/rotating-square.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/rotating-square.c b/examples/rotating-square.c
index 9b765a2..5ae0fac 100644
--- a/examples/rotating-square.c
+++ b/examples/rotating-square.c
@@ -1,5 +1,5 @@
/**************************************************************************
- * rotatingSquare.c
+ * rotating-square.c
*
* Copyright (c) 2002 Alif Wahid <awah005 users sourceforge net>
*
--
1.7.9.5
>From b74b05916849657f66c394bfddbc86faf9a33858 Mon Sep 17 00:00:00 2001
From: "B. Clausius" <barcc gmx de>
Date: Sat, 26 May 2012 18:30:07 +0200
Subject: [PATCH] Fixed gdk_gl_config_* annotations for gobject introspection
---
gdk/gdkglconfig.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/gdk/gdkglconfig.c b/gdk/gdkglconfig.c
index a66abd5..af0d0cd 100644
--- a/gdk/gdkglconfig.c
+++ b/gdk/gdkglconfig.c
@@ -400,8 +400,8 @@ gdk_gl_config_has_accum_buffer (GdkGLConfig *glconfig)
/**
* gdk_gl_config_new:
- * @attrib_list: a list of attribute/value pairs. The last attribute must
- * be GDK_GL_ATTRIB_LIST_NONE.
+ * @attrib_list: (array): a list of attribute/value pairs.
+ * The last attribute must be GDK_GL_ATTRIB_LIST_NONE.
*
* Returns an OpenGL frame buffer configuration that match the specified
* attributes.
@@ -426,8 +426,8 @@ gdk_gl_config_new (const int *attrib_list)
/**
* gdk_gl_config_new_for_display:
* @screen: target display.
- * @attrib_list: a list of attribute/value pairs. The last attribute must
- * be GDK_GL_ATTRIB_LIST_NONE.
+ * @attrib_list: (array): a list of attribute/value pairs.
+ * The last attribute must be GDK_GL_ATTRIB_LIST_NONE.
*
* Returns an OpenGL frame buffer configuration that match the specified
* attributes.
@@ -471,8 +471,8 @@ gdk_gl_config_new_for_display (GdkDisplay *display, const int *attrib_list)
/**
* gdk_gl_config_new_for_screen:
* @screen: target screen.
- * @attrib_list: a list of attribute/value pairs. The last attribute must
- * be GDK_GL_ATTRIB_LIST_NONE.
+ * @attrib_list: (array): a list of attribute/value pairs.
+ * The last attribute must be GDK_GL_ATTRIB_LIST_NONE.
*
* Returns an OpenGL frame buffer configuration that match the specified
* attributes.
@@ -543,7 +543,7 @@ gdk_gl_config_get_screen (GdkGLConfig *glconfig)
* gdk_gl_config_get_attrib:
* @glconfig: a #GdkGLConfig.
* @attribute: the attribute to be returned.
- * @value: returns the requested value.
+ * @value: (out): returns the requested value.
*
* Gets information about a OpenGL frame buffer configuration.
*
--
1.7.9.5
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]