node-gtk icon indicating copy to clipboard operation
node-gtk copied to clipboard

How to use GLArea in node-gtk?

Open kevinJ045 opened this issue 1 year ago • 1 comments

I keep trying a few codes but it's not working at all.

I have been trying this:

const gi = require('node-gtk');
const Gtk = gi.require('Gtk', '3.0');

Gtk.init();

const win = new Gtk.Window({
  type: Gtk.WindowType.TOPLEVEL,
  title: 'Gtk.GLArea Example',
});
win.setDefaultSize(800, 600);
win.on('destroy', () => Gtk.mainQuit());

const glArea = new Gtk.GLArea();

glArea.on('realize', () => {
  glArea.makeCurrent();

  console.log('done');
});

glArea.on('render', () => {
  const gl = glArea.getContext();

  gl.clearColor(0.0, 0.0, 0.0, 1.0);
  gl.clear(gl.COLOR_BUFFER_BIT);

  return true;
});

win.add(glArea);
win.showAll();

Gtk.main();

the gl seems to be an instance of GdkWaylandGLContext but it keeps saying TypeError: gl.clearColor is not a function. How am i supposed to actually use GLArea inside of node-gtk and is it even possible?

kevinJ045 avatar Jul 25 '24 09:07 kevinJ045

The functions need to be bound through GObject-Introspection for C objects to be usable in javascript. Is this example working for any other GIR library such as pygobject or GJS?

romgrk avatar Jul 25 '24 12:07 romgrk