예제 #1
0
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
예제 #2
0
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)
예제 #3
0
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
예제 #4
0
 def __enter__(self):
     #self.context = GtkGLExt.widget_create_gl_context(self.widget)
     assert GtkGLExt.widget_begin_gl(self.widget)
예제 #5
0
# -*- coding: utf-8 -*-
# This file is part of Xpra.
# Copyright (C) 2011-2018 Antoine Martin <*****@*****.**>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from xpra.gtk_common.gobject_compat import is_gtk3
from xpra.log import Logger

log = Logger("gtk", "util", "opengl")

if is_gtk3():
    from gi.repository import Gtk, GdkGLExt, GtkGLExt  #@UnresolvedImport
    gtk = Gtk
    GdkGLExt.init_check(0, "")
    GtkGLExt.init_check(0, "")
    MODE_DEPTH = GdkGLExt.ConfigMode.DEPTH
    MODE_RGBA = GdkGLExt.ConfigMode.RGBA
    MODE_ALPHA = GdkGLExt.ConfigMode.ALPHA
    MODE_RGB = GdkGLExt.ConfigMode.RGB
    MODE_DOUBLE = GdkGLExt.ConfigMode.DOUBLE
    MODE_SINGLE = GdkGLExt.ConfigMode.SINGLE

    RGBA_TYPE = GdkGLExt.RenderType.RGBA_TYPE

    def get_info():
        return {
            "gdkgl": {
                "version": GdkGLExt._version
            },  #pylint: disable=protected-access
            "gtkgl": {
예제 #6
0
파일: gtk_compat.py 프로젝트: ljmljz/xpra
 def __enter__(self):
     #self.context = GtkGLExt.widget_create_gl_context(self.widget)
     assert GtkGLExt.widget_begin_gl(self.widget)
예제 #7
0
파일: gtk_compat.py 프로젝트: ljmljz/xpra
# Copyright (C) 2011-2014 Antoine Martin <*****@*****.**>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.


from xpra.gtk_common.gobject_compat import is_gtk3

from xpra.log import Logger
log = Logger("gtk", "util", "opengl")


if is_gtk3():
    from gi.repository import Gtk, GdkGLExt, GtkGLExt    #@UnresolvedImport
    gtk = Gtk
    GdkGLExt.init_check(0, "")
    GtkGLExt.init_check(0, "")
    MODE_DEPTH  = GdkGLExt.ConfigMode.DEPTH
    MODE_RGBA   = GdkGLExt.ConfigMode.RGBA
    MODE_ALPHA  = GdkGLExt.ConfigMode.ALPHA
    MODE_RGB    = GdkGLExt.ConfigMode.RGB
    MODE_DOUBLE = GdkGLExt.ConfigMode.DOUBLE
    MODE_SINGLE = GdkGLExt.ConfigMode.SINGLE

    RGBA_TYPE   = GdkGLExt.RenderType.RGBA_TYPE

    def get_info():
        return {
                "gdkgl"     : {"version"    : GdkGLExt._version},
                "gtkgl"     : {"version"    : GtkGLExt._version},
                }
    gdkgl = GdkGLExt
예제 #8
0
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