[Note: this post was flagged as spam. There is no such thing in this post, it actually seems to be due to the filters set which consider posting messages of certain length within a certain amount of time, specially if there are links in them. Below is the original message without further edits]
Hello,
I’ve tried to use moderngl https://github.com/moderngl/moderngl/tree/main with GTK4. The closest thing they have to an example is at https://github.com/moderngl/moderngl/issues/84 with GTK3 where a cairo GTK.DrawingArea is drawing function is used to call moderngl rendering functions
I’ve tried to do the same, using a DrawingArea with GTK4 unsuccessfully, even though I can draw with cairo just fine; I’ve also tried using a GTK.GLArea but I suspect it won’t work because moderngl creates it’s own framebuffer which ends up not being the framebuffer used by GTK4 for display, but that’s really just an educated guess
When moderngl creates it’s context it does so based on an existing pure OpenGL context, and it doesn’t complain when I call it from the GTK.ApplicationWindow realize callback, so I’m guessing that’s not the problem
Any pointers about how to get GTK4 and moderngl to play nice with each other?
This is my minimal non-working code so far:
import gi
gi.require_version('Gtk', '4.0'); from gi.repository import Gtk
import moderngl
def on_activate(app):
drawing_area = Gtk.DrawingArea()
drawing_area.connect('realize', on_realize)
drawing_area.set_draw_func(on_draw)
win = Gtk.ApplicationWindow(application=app)
win.set_child(drawing_area)
win.present()
def on_realize(gldrawingarea):
# global gl_context
# gl_context = glarea.get_display().create_gl_context()
# gl_context.make_current()
global ctx
ctx = moderngl.create_context()
def on_draw(glarea, cairorender, w, h):
ctx.clear(0, 1, 0)
gl_context = None
ctx = None
app = Gtk.Application()
app.connect('activate', on_activate)
app.run(None)