Getting GtkD working with OpenGL

Mike Wey via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Sep 18 14:41:45 PDT 2016


On 09/18/2016 09:36 PM, Chalix wrote:
> Hi All!
>
> This weekend I explored Dlang and I think it's very promising. So I
> wanted to create some projects I've created with C++ already - for the
> sake of comparison.
>
> I wanted to create a new class which inherits from DrawingArea (from the
> Gtk library). This will be my OpenGL-Widget with functions like
> "drawGL", which I have to override.
>
> So I downloaded the "GtkD-3.3.0.zip" from here:
> http://gtkd.org/download.html and compiled it successfully (with "make
> all").
>
> Now I've got the libraries gstreamerd-3, gtkd-3, gtkdgl-3, gtkdsv-3 and
> vted-3. I also got the module files for the import at
> "/usr/local/include/d/gtkd-3/", after I did a "make install".
>
> Now I tested a little example I found somewhere in the web, which looks
> like:
>
> import gtk.MainWindow;
> import gtk.Label;
> import gtk.Main;
> import gtk.GLArea;
> void main(string[] args)
> {
>     Main.init(args);
>     MainWindow win = new MainWindow("Hello World");
>     GLArea area = new GLArea();
>     win.add(area);
>     win.setDefaultSize(200, 100);
>     win.showAll();
>     Main.run();
> }
>
> This compiles fine and I get an empty black window. (I compiled with the
> options: "dmd main.d -I/usr/local/include/d/gtkd-3
> -L/pathToLib/libgtkd-3.a")
>
>
>
> Now I scanned through the demos at the GtkD Library and I found one,
> that fits my needs perfectly. It is located at
> ".../GtkD-3.3.0/demos/gl/simple/SimpleGL.d" (I post the source code in
> an extra answer, since it is a bit lengthy...)
>
> This demo compiles fine (with "dmd main.d -c -I/...", -c tells the
> compiler not to link).
> But the linker gives an error here (command was: "dmd main.o
> -L/libgtkd-3.a -L/libgtkdgl-3.a ...", I linked to all the libs mentioned
> above).
> I get a very lengthy error message, and I cant figure out, why the
> reference to all the gl stuff is missing. Would be really great, if some
> one could give me a hint!
>
> Ah, yeah, just do avoid the answer "make it with dub!": Actually I did
> it also with dub and I get the same error messages... If you are
> interested, I can provide you also my .json file. But I like to know
> whats going on behind, so I prefer the way to install my libs manually.
> Would be great, if I get this working.
>

The demo still uses the old GtkGLExt binding, which usually isn't 
available in de distributions repositories.

The newer GLArea is easier to use since it's part of GTK.

As for the linker errors, you'll need to link with the OpenGL libraries:
"-L-lGL -L-lGLU"

-- 
Mike Wey


More information about the Digitalmars-d-learn mailing list