www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Getting GtkD working with OpenGL

reply Chalix <anonymous www.org> writes:
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.

$ dmd main.o -L/.../GtkD-3.3.0/libgtkd-3.a 
-L/.../GtkD-3.3.0/libgtkdgl-3.a 
-L/.../GtkD-3.3.0/libgstreamerd-3.a 
-L/.../GtkD-3.3.0/libgtkdsv-3.a -L/.../GtkD-3.3.0/libvted-3.a
main.o:
In function 
`_D8simpleGL8SimpleGL8SimpleGL8__mixin712realizeFrameMFC3gtk6Widget6WidgetZv':
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL8__mixin712realizeFrameMFC3gtk6Wi
get6WidgetZv+0xcf): undefined reference to `glFlush'
main.o: In function 
`_D8simpleGL8SimpleGL8SimpleGL8__mixin79drawFrameMFC5cairo7Context7ContextC3gtk6Widget6WidgetZb':
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL8__mixin79drawFrameMFC5cairo7Context7ContextC3gtk6Wi
get6WidgetZb+0xc0): undefined reference to `glFlush'
main.o: In function 
`_D8simpleGL8SimpleGL8SimpleGL8__mixin714configureFrameMFC3gdk5Event5EventC3gtk6Widget6WidgetZb':
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL8__mixin714configureFrameMFC3gdk5Event5EventC3gtk6Wid
et6WidgetZb+0x11a): undefined reference to `glFlush'
main.o: In function 
`_D8simpleGL8SimpleGL8SimpleGL8__mixin78mapFrameMFC3gtk6Widget6WidgetZv':
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL8__mixin78mapFrameMFC3gtk6Wi
get6WidgetZv+0xbb): undefined reference to `glFlush'
main.o: In function 
`_D8simpleGL8SimpleGL8SimpleGL8__mixin710unmapFrameMFC3gtk6Widget6WidgetZv':
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL8__mixin710unmapFrameMFC3gtk6Wi
get6WidgetZv+0xbb): undefined reference to `glFlush'
main.o:main.d:(.text._D8simpleGL8SimpleGL8SimpleGL8__mixin715visibilityFrameMFC3gdk5Event5EventC3gtk6Wi
get6WidgetZb+0xc8): more undefined references to `glFlush' follow
main.o: In function `_D8simpleGL8SimpleGL8SimpleGL6drawGLMFZb':
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL6drawGLMFZb+0x45): 
undefined reference to `glClear'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL6drawGLMFZb+0x4a): 
undefined reference to `glLoadIdentity'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL6drawGLMFZb+0xa9): 
undefined reference to `gluLookAt'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL6drawGLMFZb+0xb7): 
undefined reference to `glBegin'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL6drawGLMFZb+0xdb): 
undefined reference to `glColor3f'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL6drawGLMFZb+0xff): 
undefined reference to `glVertex3f'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL6drawGLMFZb+0x123): 
undefined reference to `glColor3f'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL6drawGLMFZb+0x142): 
undefined reference to `glVertex3f'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL6drawGLMFZb+0x166): 
undefined reference to `glColor3f'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL6drawGLMFZb+0x18a): 
undefined reference to `glVertex3f'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL6drawGLMFZb+0x18f): 
undefined reference to `glEnd'
main.o: In function 
`_D8simpleGL8SimpleGL8SimpleGL8resizeGLMFC3gdk5Event5EventZb':
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL8resizeGLMFC3gdk5E
ent5EventZb+0x112): undefined reference to `glViewport'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL8resizeGLMFC3gdk5E
ent5EventZb+0x11c): undefined reference to `glMatrixMode'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL8resizeGLMFC3gdk5E
ent5EventZb+0x121): undefined reference to `glLoadIdentity'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL8resizeGLMFC3gdk5E
ent5EventZb+0x153): undefined reference to `gluPerspective'
main.d:(.text._D8simpleGL8SimpleGL8SimpleGL8resizeGLMFC3gdk5E
ent5EventZb+0x15d): undefined reference to `glMatrixMode'
collect2: error: ld returned 1 exit status
--- errorlevel 1
Sep 18 2016
next sibling parent Chalix <anonymous www.org> writes:
Here the code I actually wanted to compile (SimpleGL.d):

/*
  * This file is part of gtkD.
  *
  * dui is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as 
published by
  * the Free Software Foundation; either version 3 of the License, 
or
  * (at your option) any later version.
  *
  * dui is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General 
Public License
  * along with dui; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 
02110, USA
  */

module simpleGL.SimpleGL;

private import gdk.Event;
private import gtk.DrawingArea;
private import gtk.Main;
private import gtk.MainWindow;
private import gtk.Widget;
private import glgdk.GLConfig;
private import glgdk.GLContext;
private import glgdk.GLdInit;
private import glgdk.GLWindow;
private import glgtk.GLCapability;
private import gtkglc.glgdktypes;

private import gtkglc.gl;
private import gtkglc.glu;

/**
  * This is a Simple class extending the DrawingArea widget.
  * A really simple Demo illustrating OpenGL with GtkD
  * It uses the GLCapability mixin to add the GL capabilities to 
the widget.
  * This example is provided under the terms of the GPL License.
  * Note the initialization of the GLCapabilities on the 
constructor.
  *
  *  author pac tuxfamily.org
  */
class SimpleGL : DrawingArea
{

	GLfloat width;
	GLfloat height;
	
	/** need to include the mixin to add GL capabilities to this 
widget */
	mixin GLCapability;

	/**
	 * Construct a simple DrawingArea and sets the GLCapabilities
	 */
	this()
	{
		super(300, 300);
		setGlCapability();	// set the GL capabilities for this widget
	}

	/**
	 * put any gl initializations here
	 * returns true to consume the event
	 */
	void initGL()
	{
		resizeGL(null);
	}
	
	/**
	 * This method is called every time the window must be paint or 
repaint
	 * This is where you put the OpenGL call to draw something.
	 * This method call be called directly by the application 
without an event object
	 * to force redrawing of the scene.
	 * returns true to consume the event
	 */
	bool drawGL()
	{
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glLoadIdentity ();

		gluLookAt(0, 0, 10, 0, 0, 0, 0, 1,0); //Set the camera position

		//Just Draw a tri-colored triangle
		glBegin(GL_TRIANGLES);
		glColor3f(1.0f,0.0f,0.0f);
		glVertex3f( 0.0f, 1.0f, 0.0f);
		glColor3f(0.0f,1.0f,0.0f);
		glVertex3f(-1.0f,-1.0f, 0.0f);
		glColor3f(0.0f,0.0f,1.0f);
		glVertex3f( 1.0f,-1.0f, 0.0f);
		glEnd();
			
		return true;
	}

	/**
	 * This method is called when the window is resized
	 * returns true to consume the event
	 */
	bool resizeGL(Event event = null)
	{
		GLfloat w;
		GLfloat h;
		
		if ( event is null || event.type != GdkEventType.CONFIGURE )
		{
			w = getWidth();
			h = getHeight();
		}
		else
		{
			w = event.configure.width;
			h = event.configure.height;
		}
		
		width = w;
		height = h;
		
		glViewport (0, 0, cast(int)w, cast(int)h); //Adjust the 
viewport according to new window dimensions

		/*
		 * Update the projection Matrix accoding to the new dimension
		 * and reset the OpenGL state to MODELVIEW
		 */
		glMatrixMode (GL_PROJECTION);
		glLoadIdentity ();
		gluPerspective(20, w/h, 0.1, 10);
		glMatrixMode (GL_MODELVIEW);

		return true;
	}
}

void main(string[] args)
{
	Main.init(args);

	GLdInit.init(args);
	
	SimpleGL simpleGL = new SimpleGL();
	MainWindow window = new MainWindow("Simplest OpenGL Example");
	window.add(simpleGL);
	window.showAll();
		
	Main.run();
}
Sep 18 2016
prev sibling parent reply Mike Wey <mike-wey example.com> writes:
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
Sep 18 2016
parent reply Chalix <chalix anonymous.org> writes:
On Sunday, 18 September 2016 at 21:41:45 UTC, Mike Wey wrote:
 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"
Hey, thanks for your fast answer! I had a lot of other work to do, so I could only continue working on this project now. Yeah, that solved my problem :) Now it links. Although if I execute the program, it complains about the missing GtkGLExt library, like expected... Library load failed: libgdkglext-3.0.so.0 So I wanted to install this library from here: https://projects.gnome.org/gtkglext/download.html but the ./configure script tells me, No package 'pangox' found (pangox >= 1.0.0) I looked at the folder /usr/lib/x86_64-linux-gnu/ and there is a file called "libpangox-1.0.so.0.0.0". So I don't know, why this is not working... Anyway, I want to follow Mikes advice and use GLArea instead, so if there is not a quick fix available, lets skip the problems with the GtkGLExt library... But, sadly enough, I did not get GLArea working, too. The documentation https://developer.gnome.org/gtk3/stable/GtkGLArea.html says, I have to connect my render function to the widget like this: g_signal_connect (gl_area, "render", G_CALLBACK (render), NULL); But, my compiler can't find the g_signal_connect method (and the GL Methods...): main.d(22): Error: undefined identifier 'g_signal_connect' main.d(39): Error: undefined identifier 'glClearColor' main.d(40): Error: undefined identifier 'glClear' There might some include files (or import files, as you say in D) missing, but I could not figure out, where to find them for D... Could you tell me, where this g_signal_connect method can be found? And what I have to include for the GL functionality? Simply "import gtk.GLArea;" does not do the trick... Btw, is g_signal_connect a GTK method? I intend to use my program platform independent, so if this is dependent on gnome, it would not be good. Or is there any other way to get the GLArea working? I am used to the Qt Libraries, where you create a QGLWidget and simply override the init and render functions. Thanks for reading this far, would be great if we could solve this problem :D
Oct 03 2016
parent reply Mike Wey <mike-wey example.com> writes:
On 10/03/2016 01:50 PM, Chalix wrote:
 On Sunday, 18 September 2016 at 21:41:45 UTC, Mike Wey wrote:
 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"
Hey, thanks for your fast answer! I had a lot of other work to do, so I could only continue working on this project now. Yeah, that solved my problem :) Now it links. Although if I execute the program, it complains about the missing GtkGLExt library, like expected... Library load failed: libgdkglext-3.0.so.0 So I wanted to install this library from here: https://projects.gnome.org/gtkglext/download.html but the ./configure script tells me, No package 'pangox' found (pangox >= 1.0.0) I looked at the folder /usr/lib/x86_64-linux-gnu/ and there is a file called "libpangox-1.0.so.0.0.0". So I don't know, why this is not working...
You will need the Gtk3 port of gtkglext: https://github.com/tdz/gtkglext Last time i tried compiling it i needed to remove the documentation generation from the make files.
 Anyway, I want to follow Mikes advice and use GLArea instead, so if
 there is not a quick fix available, lets skip the problems with the
 GtkGLExt library...



 But, sadly enough, I did not get GLArea working, too. The documentation
 https://developer.gnome.org/gtk3/stable/GtkGLArea.html
 says, I have to connect my render function to the widget like this:
 g_signal_connect (gl_area, "render", G_CALLBACK (render), NULL);
 But, my compiler can't find the g_signal_connect method (and the GL
 Methods...):
 main.d(22): Error: undefined identifier 'g_signal_connect'
 main.d(39): Error: undefined identifier 'glClearColor'
 main.d(40): Error: undefined identifier 'glClear'

 There might some include files (or import files, as you say in D)
 missing, but I could not figure out, where to find them for D...

 Could you tell me, where this g_signal_connect method can be found? And
 what I have to include for the GL functionality? Simply "import
 gtk.GLArea;" does not do the trick...
The signal functions can be found in the gobject.Signals module. But you should use the GLArea.addOnCreateContext / addOnRender / addOnResize functions to attach a D delegate to the signal. You will still need to link with the OpenGL libraries or use someting like Derelict.
 Btw, is g_signal_connect a GTK method? I intend to use my program
 platform independent, so if this is dependent on gnome, it would not be
 good.
It's a GLib/GObject method, it's available on any platform GTK runs on.
 Or is there any other way to get the GLArea working? I am used to the Qt
 Libraries, where you create a QGLWidget and simply override the init and
 render functions.


 Thanks for reading this far, would be great if we could solve this
 problem :D
-- Mike Wey
Oct 03 2016
parent reply Chalix <chalix anonymous.org> writes:
On Monday, 3 October 2016 at 18:00:53 UTC, Mike Wey wrote:
 The signal functions can be found in the gobject.Signals module.

 But you should use the GLArea.addOnCreateContext / addOnRender 
 / addOnResize functions to attach a D delegate to the signal.
 You will still need to link with the OpenGL libraries or use 
 someting like Derelict.
Hi Mike, thanks for your fast answer again! I just read about this delegates and I liked the concept. I experimented with it for a while and read a bit on the Internet, but I still don't get it working... My minimal example looks like this: import gtk.Main; import gtk.MainWindow; import gtk.GLArea; import glgdk.GLContext; void main(string[] args) { bool render(GLContext context, GLArea area) { return true; } Main.init(args); MainWindow win = new MainWindow("Hello World"); GLArea area = new GLArea(); area.addOnRender(&render,cast(GConnectFlags)0); win.add(area); win.showAll(); Main.run(); } If I compile it, I get this error: $ dmd main.d -I/usr/local/include/d/gtkd-3 -L-lgtkd-3 main.d(27): Error: function gtk.GLArea.GLArea.addOnRender (bool delegate(GLContext, GLArea) dlg, GConnectFlags connectFlags = cast(GConnectFlags)0) is not callable using argument types (bool delegate(GLContext context, GLArea area), GConnectFlags) I cant see, what I am doing wrong... Someone else sees the error? Tomorrow I try to subclass the GLArea, if this works I am happy :) But I'd like to use the handler stuff. Ah, and I know now, that I have to link against the GL and GLU library, but which module do I have to import, to make the functions visible for the compiler? Or do I need another binding therefore?
Oct 03 2016
parent reply Mike Wey <mike-wey example.com> writes:
On 10/03/2016 11:46 PM, Chalix wrote:
 On Monday, 3 October 2016 at 18:00:53 UTC, Mike Wey wrote:
 The signal functions can be found in the gobject.Signals module.

 But you should use the GLArea.addOnCreateContext / addOnRender /
 addOnResize functions to attach a D delegate to the signal.
 You will still need to link with the OpenGL libraries or use someting
 like Derelict.
Hi Mike, thanks for your fast answer again! I just read about this delegates and I liked the concept. I experimented with it for a while and read a bit on the Internet, but I still don't get it working... My minimal example looks like this: import gtk.Main; import gtk.MainWindow; import gtk.GLArea; import glgdk.GLContext; void main(string[] args) { bool render(GLContext context, GLArea area) { return true; } Main.init(args); MainWindow win = new MainWindow("Hello World"); GLArea area = new GLArea(); area.addOnRender(&render,cast(GConnectFlags)0); win.add(area); win.showAll(); Main.run(); } If I compile it, I get this error: $ dmd main.d -I/usr/local/include/d/gtkd-3 -L-lgtkd-3 main.d(27): Error: function gtk.GLArea.GLArea.addOnRender (bool delegate(GLContext, GLArea) dlg, GConnectFlags connectFlags = cast(GConnectFlags)0) is not callable using argument types (bool delegate(GLContext context, GLArea area), GConnectFlags) I cant see, what I am doing wrong... Someone else sees the error? Tomorrow I try to subclass the GLArea, if this works I am happy :) But I'd like to use the handler stuff. Ah, and I know now, that I have to link against the GL and GLU library, but which module do I have to import, to make the functions visible for the compiler? Or do I need another binding therefore?
Replace "import glgdk.GLContext;" with "import gdk.GLContext;" The error is a bit confusing without the fully qualified names of the types, but GLArea depends on the OpenGL functionality build in to GDK, and doesn't depend on gtkglext. -- Mike Wey
Oct 04 2016
parent reply Chalix <chalix anonymous.org> writes:
On Tuesday, 4 October 2016 at 17:00:34 UTC, Mike Wey wrote:
 Replace "import glgdk.GLContext;" with "import gdk.GLContext;"
Hey Mike, you've been a great help so far! Thank you :) I thought now I am ready to draw something, but I struggle with the GLContext and GdkGlContext. Where do I get a valid Context, or how do I make it valid? My program crashes always with segmentation fault, as soon as I call a GL function except glClear. It must be a problem with the Context... Btw, what exactly is a GLContext and what is it used for? I am not used to it, since neither Qt nor glut uses or needs a GLContext-like structure. Would be great, if you see the error again... I think I am only missing an initialization function in my "initGL". I didn't find anything on the Internet. Here my code: import gtk.Main; import gtk.MainWindow; import gtk.GLArea; import gdk.GLContext; import derelict.opengl3.gl; import std.functional : toDelegate; GLContext initGL(GLArea area) { DerelictGL3.load(); /* Error happens somewhere here: */ GdkGLContext *gdkCon; /* where do I get a valid "struct GdkGLContext"?*/ GLContext context = new GLContext(gdkCon); /*needs GdkGLContext pointer for Initialization*/ context.realize(); /*which of these two functions do I need really, and why?*/ context.makeCurrent(); /* Runtime Warnings: */ /* Gdk-CRITICAL **: gdk_gl_context_realize:assertion 'GDK_IS_GL_CONTEXT (context)' failed */ /*same for ...make_current...*/ return context; } bool renderGL(GLContext context, GLArea area) { glClearColor (0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); /*Here the program crashes with Segmentation Fault (Some pointer is NULL)*/ glLoadIdentity(); glColor3f(1.0, 1.0, 0.0); glBegin(GL_TRIANGLES); glVertex3f(0, 0, -2); glVertex3f(1, 0, -2); glVertex3f(0, 1, -2); glEnd(); return true; } void main(string[] args) { Main.init(args); MainWindow win = new MainWindow("Hello GL"); GLArea area = new GLArea(); area.addOnCreateContext(toDelegate(&initGL)); area.addOnRender(toDelegate(&renderGL)); //area.addOnResize(toDelegate(&resizeGL)); win.add(area); win.showAll(); Main.run(); }
Oct 06 2016
parent reply Mike Parker <aldacron gmail.com> writes:
On Thursday, 6 October 2016 at 10:49:40 UTC, Chalix wrote:

 	glMatrixMode(GL_MODELVIEW); /*Here the program crashes with
There are two things wrong with your use of Derelict. First, though you are correctly importing derelict.opengl3.gl to get the deprecated functions (which the gl3 module does not expose), you are calling DerelictGL3.load and not DerelictGL.load. The former loads only the core 1.1 functions. To load the deprecated 1.1 functions, you need the latter instead. Second, once the context is created and activated, you need to call DerelictGL3.reload to load all of the functions available in the context for OpenGL 1.2 and higher as well all available extensions supported by Derelict. So, change DerelictGL3.load to DerelictGL.load, then add a call to DerelictGL.reload after creating and activating the context.
Oct 06 2016
parent reply Chalix <chalix anonymous.org> writes:
On Thursday, 6 October 2016 at 13:35:01 UTC, Mike Parker wrote:
 So, change DerelictGL3.load to DerelictGL.load, then add a call 
 to DerelictGL.reload after creating and activating the context.
Thank you! That fixed the segmentation fault problem and the crash :) But I still struggle with the right Context... if I do something like this DerelictGL.load(); area.makeCurrent(); DerelictGL.reload(); I get an (runtime) error (on the terminal where I run my application): (LibraryTest:2984): Gtk-CRITICAL **: gtk_gl_area_make_current: assertion 'gtk_widget_get_realized (widget)' failed derelict.util.exception.DerelictException gl3.d(85): DerelictGL3.reload failure: An OpenGL context is not currently active. [...] After all, I really don't know, what a GLContext is, what I need it for and how to use it. If somebody can explain it to me, I would be happy! I didn't find anything about it on the Internet, but I like to know, whats going on behind my code... I will keep on playing around with all the context functions, maybe I find something by accident that works xD
Oct 06 2016
parent Mike Wey <mike-wey example.com> writes:
On 10/06/2016 05:18 PM, Chalix wrote:
 On Thursday, 6 October 2016 at 13:35:01 UTC, Mike Parker wrote:
 So, change DerelictGL3.load to DerelictGL.load, then add a call to
 DerelictGL.reload after creating and activating the context.
Thank you! That fixed the segmentation fault problem and the crash :) But I still struggle with the right Context... if I do something like this DerelictGL.load(); area.makeCurrent(); DerelictGL.reload(); I get an (runtime) error (on the terminal where I run my application): (LibraryTest:2984): Gtk-CRITICAL **: gtk_gl_area_make_current: assertion 'gtk_widget_get_realized (widget)' failed derelict.util.exception.DerelictException gl3.d(85): DerelictGL3.reload failure: An OpenGL context is not currently active. [...] After all, I really don't know, what a GLContext is, what I need it for and how to use it. If somebody can explain it to me, I would be happy! I didn't find anything about it on the Internet, but I like to know, whats going on behind my code... I will keep on playing around with all the context functions, maybe I find something by accident that works xD
When you don't register an callback for the createContext signal (addOnCreateContext), gtk does the following internally: ``` context = area.getWindow().createGlContext(); ``` to get an context that renders to the GLArea. gdk.GLContext is an platform independent abstraction for the context you would normally use with openGL. like the one's returned by wglCreateContext or glxCreateContext. makeCurrent() sets that context as the one that is rendered to. realize() i think makes sure the context is initialized, but makeCurrent() also calls realize, so makeCurrent is probably the one you want to use. -- Mike Wey
Oct 06 2016