Add preliminary opengl widget
This commit is contained in:
parent
da721d13f4
commit
a1d1f93843
|
@ -6,6 +6,7 @@ import gi
|
|||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk # noqa
|
||||
import cairo # noqa
|
||||
from OpenGL.GL import glClearColor, glClear, glFlush, GL_COLOR_BUFFER_BIT
|
||||
|
||||
|
||||
class TestWin(Gtk.Window):
|
||||
|
@ -15,10 +16,18 @@ class TestWin(Gtk.Window):
|
|||
Gtk.Window.__init__(self, type=self.WINDOW_POPUP)
|
||||
|
||||
self._default_monitor = 0
|
||||
self.make_fullscreen()
|
||||
self.label = Gtk.Label(label="Hallo! :)")
|
||||
self.label.show()
|
||||
self.add(self.label)
|
||||
self.set_window_geometry()
|
||||
|
||||
self.layout = Gtk.Box()
|
||||
self.layout.show()
|
||||
self.add(self.layout)
|
||||
|
||||
self.gl = Gtk.GLArea()
|
||||
self.gl.connect("render", self.gl_render)
|
||||
self.gl.connect("realize", self.gl_realize)
|
||||
# self.gl.connect('create-context', self.gl_context)
|
||||
self.gl.show()
|
||||
self.layout.pack_end(self.gl, True, True, 0)
|
||||
|
||||
self.make_rgba()
|
||||
self.set_app_paintable(True)
|
||||
|
@ -38,7 +47,7 @@ class TestWin(Gtk.Window):
|
|||
else:
|
||||
self.set_visual(self.visual)
|
||||
|
||||
def make_fullscreen(self):
|
||||
def set_window_geometry(self):
|
||||
geo = self.get_screen_size(self._default_monitor)
|
||||
scale = (1.05, 6)
|
||||
x, y, w, h = (
|
||||
|
@ -57,7 +66,7 @@ class TestWin(Gtk.Window):
|
|||
def on_draw(self, widget, cr):
|
||||
# make everything transparent
|
||||
cr.set_source_rgba(1.0, 1.0, 1.0, 0.1)
|
||||
cr.set_operator(cairo.OPERATOR_SOURCE)
|
||||
# cr.set_operator(cairo.OPERATOR_SOURCE)
|
||||
cr.paint()
|
||||
cr.set_operator(cairo.OPERATOR_OVER)
|
||||
|
||||
|
@ -72,6 +81,23 @@ class TestWin(Gtk.Window):
|
|||
def make_untouchable(self):
|
||||
self.input_shape_combine_region(cairo.Region(cairo.RectangleInt(0, 0, 0, 0)))
|
||||
|
||||
def gl_realize(self, gl_area):
|
||||
error = gl_area.get_error()
|
||||
if error != None:
|
||||
print(f"ERROR: No OpenGL ({error})")
|
||||
|
||||
def gl_context(self, gl_area):
|
||||
c = gl_area.get_context()
|
||||
print(c, "context")
|
||||
return c
|
||||
|
||||
def gl_render(self, area, context):
|
||||
glClearColor(1.0, 0.5, 0.5, 1.0)
|
||||
glClear(GL_COLOR_BUFFER_BIT)
|
||||
glFlush()
|
||||
print("rendering... done")
|
||||
return True
|
||||
|
||||
def run(self):
|
||||
Gtk.main()
|
||||
return 0
|
||||
|
|
Loading…
Reference in New Issue