Browse Source

Add preliminary opengl widget

Jakob 9 months ago
parent
commit
a1d1f93843
1 changed files with 32 additions and 6 deletions
  1. 32
    6
      transparent.py

+ 32
- 6
transparent.py View File

@@ -6,6 +6,7 @@ import gi
6 6
 gi.require_version("Gtk", "3.0")
7 7
 from gi.repository import Gtk  # noqa
8 8
 import cairo  # noqa
9
+from OpenGL.GL import glClearColor, glClear, glFlush, GL_COLOR_BUFFER_BIT
9 10
 
10 11
 
11 12
 class TestWin(Gtk.Window):
@@ -15,10 +16,18 @@ class TestWin(Gtk.Window):
15 16
         Gtk.Window.__init__(self, type=self.WINDOW_POPUP)
16 17
 
17 18
         self._default_monitor = 0
18
-        self.make_fullscreen()
19
-        self.label = Gtk.Label(label="Hallo! :)")
20
-        self.label.show()
21
-        self.add(self.label)
19
+        self.set_window_geometry()
20
+
21
+        self.layout = Gtk.Box()
22
+        self.layout.show()
23
+        self.add(self.layout)
24
+
25
+        self.gl = Gtk.GLArea()
26
+        self.gl.connect("render", self.gl_render)
27
+        self.gl.connect("realize", self.gl_realize)
28
+        # self.gl.connect('create-context', self.gl_context)
29
+        self.gl.show()
30
+        self.layout.pack_end(self.gl, True, True, 0)
22 31
 
23 32
         self.make_rgba()
24 33
         self.set_app_paintable(True)
@@ -38,7 +47,7 @@ class TestWin(Gtk.Window):
38 47
         else:
39 48
             self.set_visual(self.visual)
40 49
 
41
-    def make_fullscreen(self):
50
+    def set_window_geometry(self):
42 51
         geo = self.get_screen_size(self._default_monitor)
43 52
         scale = (1.05, 6)
44 53
         x, y, w, h = (
@@ -57,7 +66,7 @@ class TestWin(Gtk.Window):
57 66
     def on_draw(self, widget, cr):
58 67
         # make everything transparent
59 68
         cr.set_source_rgba(1.0, 1.0, 1.0, 0.1)
60
-        cr.set_operator(cairo.OPERATOR_SOURCE)
69
+        # cr.set_operator(cairo.OPERATOR_SOURCE)
61 70
         cr.paint()
62 71
         cr.set_operator(cairo.OPERATOR_OVER)
63 72
 
@@ -72,6 +81,23 @@ class TestWin(Gtk.Window):
72 81
     def make_untouchable(self):
73 82
         self.input_shape_combine_region(cairo.Region(cairo.RectangleInt(0, 0, 0, 0)))
74 83
 
84
+    def gl_realize(self, gl_area):
85
+        error = gl_area.get_error()
86
+        if error != None:
87
+            print(f"ERROR: No OpenGL ({error})")
88
+
89
+    def gl_context(self, gl_area):
90
+        c = gl_area.get_context()
91
+        print(c, "context")
92
+        return c
93
+
94
+    def gl_render(self, area, context):
95
+        glClearColor(1.0, 0.5, 0.5, 1.0)
96
+        glClear(GL_COLOR_BUFFER_BIT)
97
+        glFlush()
98
+        print("rendering... done")
99
+        return True
100
+
75 101
     def run(self):
76 102
         Gtk.main()
77 103
         return 0

Loading…
Cancel
Save