bind Irrlicht with an X window

A forum to store posts deemed exceptionally wise and useful
Post Reply
Bellaz89
Posts: 4
Joined: Thu Aug 31, 2006 7:26 pm

bind Irrlicht with an X window

Post by Bellaz89 »

I wrote a new .diff patch based (at 99 % is stef_ work :P) from the stef_ code that you can find in this topic : http://irrlicht.sourceforge.net/phpBB2/ ... af31c7110d

Now opengl driver works better and I removed some global variabiles.

Code: Select all

--- SIrrCreationParameters.h.orig	2007-02-01 15:43:55.000000000 +0100
+++ SIrrCreationParameters.h	2007-02-02 14:07:59.000000000 +0100
@@ -4,7 +4,11 @@
 
 #ifndef __I_IRRLICHT_CREATION_PARAMETERS_H_INCLUDED__
 #define __I_IRRLICHT_CREATION_PARAMETERS_H_INCLUDED__
-
+#ifdef  _IRR_COMPILE_WITH_X11_
+  #define WindowIdType long int
+#else
+  #define WindowIdType s32 
+#endif
 namespace irr
 {
 	//! Structure for holding advanced Irrlicht Device creation parameters.
@@ -24,7 +28,10 @@
 			HighPrecisionFPU = false;
 			EventReceiver = 0;
 			WindowId = 0;
-			SDK_version_do_not_use = IRRLICHT_SDK_VERSION;
+			#ifdef _IRR_COMPILE_WITH_X11_
+                        DisplayPointer = NULL; // only X systems "know" the mean of this parameter
+                        #endif
+                        SDK_version_do_not_use = IRRLICHT_SDK_VERSION;
 		}
 
 		//! Type of the device. 
@@ -125,7 +132,13 @@
 		\endcode
 		However, there is no need to draw the picture this often. Just do it how you like.
 		*/
-		s32 WindowId;
+
+                WindowIdType WindowId;
+                
+
+                #ifdef _IRR_COMPILE_WITH_X11_
+                void* DisplayPointer;// pass here the display pointer (only for X11 capable OS) 
+                #endif
 
 		//! Don't use or change this parameter. 
 		/** Always set it to IRRLICHT_SDK_VERSION, which is done by default.

Code: Select all

--- CIrrDeviceLinux.h.orig	2007-02-01 15:43:36.000000000 +0100
+++ CIrrDeviceLinux.h	2007-02-02 13:15:54.000000000 +0100
@@ -51,7 +51,8 @@
 		CIrrDeviceLinux(video::E_DRIVER_TYPE deviceType,
 			const core::dimension2d<s32>& windowSize, u32 bits,
 			bool fullscreen, bool stencilbuffer, bool vsync, bool antiAlias, IEventReceiver* receiver,
-			const char* version);
+			XID WindowId, Display* DisplayPointer,
+                        const char* version);
 
 		//! destructor
 		virtual ~CIrrDeviceLinux();
@@ -277,7 +278,7 @@
 		bool UseXVidMode;
 		bool UseXRandR;
 		bool UseGLXWindow;
-
+                bool isUserSuppliedWindow; // it indicate if the rendering surface will be included in a user supplied window.If true Fullscreen is set false and ignored
 		struct SKeyMap
 		{
 			SKeyMap() {}

Code: Select all

--- CIrrDeviceLinux.cpp.orig	2007-01-31 21:36:34.000000000 +0100
+++ CIrrDeviceLinux.cpp	2007-02-02 14:10:11.000000000 +0100
@@ -42,7 +42,9 @@
 	u32 bits, bool fullscreen,
 	bool sbuffer, bool vsync, bool antiAlias,
 	IEventReceiver* receiver,
-	const char* version)
+	XID WindowId,
+        Display* DisplayPointer,
+        const char* version)
  : CIrrDeviceStub(version, receiver),
 #ifdef _IRR_COMPILE_WITH_X11_
 	display(0), screennr(0), window(0), SoftwareImage(0),
@@ -78,7 +80,14 @@
 	// create window
 	if (driverType != video::EDT_NULL)
 	{
-		// create the window, only if we do not use the null device
+                // pass to the device the user defined window id and display pointer 
+                window  = WindowId;
+                display = DisplayPointer;
+                //if window and display aren't uninitialised it create a rendering surface in the window passed by the user
+                isUserSuppliedWindow = display && window;
+                //if isUserSuppliedWindow is true fullscreen will be false  
+                if (isUserSuppliedWindow) Fullscreen = false;
+                // create the window, only if we do not use the null device
 		if (!createWindow(windowSize, bits))
 			return;
 	}
@@ -168,8 +177,10 @@
 	XSetErrorHandler(IrrPrintXError);
 #endif
 
-	display = XOpenDisplay(0);
-	if (!display)
+	if (!isUserSuppliedWindow)
+        display = XOpenDisplay(0); //it's needed to not overwrite the user settings
+	
+        if (!display)
 	{
 		os::Printer::log("Error: Need running XServer to start Irrlicht Engine.", ELL_ERROR);
 		return false;
@@ -289,10 +300,16 @@
 				    GLX_STENCIL_SIZE, 1,
 				    GLX_SAMPLE_BUFFERS_ARB, GL_TRUE,
 				    GLX_SAMPLES_ARB, MAX_SAMPLES,
+                                    GLX_FBCONFIG_ID,GLX_DONT_CARE,
 				    None
 				};
 
-				GLXFBConfig *configList=0;
+                                 if (isUserSuppliedWindow)
+                                {
+                                        visualAttrBuffer[21] = window;
+                                }				
+
+                                GLXFBConfig *configList=0;
 				int nitems=0;
 				if (!AntiAlias)
 				{
@@ -416,9 +433,15 @@
 				    GLX_DEPTH_SIZE, 16,
 				    GLX_DOUBLEBUFFER, GL_TRUE,
 				    GLX_STENCIL_SIZE, 1,
+                                    GLX_FBCONFIG_ID,GLX_DONT_CARE,
 				    None
 				};
 
+                                 if (isUserSuppliedWindow)
+                                {
+                                        visualAttrBuffer[17] = window;
+                                }
+
 				if (StencilBuffer)
 					visual=glXChooseVisual(display, screennr, visualAttrBuffer);
 				if (!visual)
@@ -473,7 +496,7 @@
 	// create color map
 	Colormap colormap;
 	colormap = XCreateColormap(display,
-			    RootWindow(display, visual->screen),
+			    isUserSuppliedWindow ? window : RootWindow(display, visual->screen),
 			    visual->visual, AllocNone);
 
 	attributes.colormap = colormap;
@@ -501,7 +524,7 @@
 		XGrabPointer(display, window, True, ButtonPressMask,
 			GrabModeAsync, GrabModeAsync, window, None, CurrentTime);
 	}
-	else
+	else if (!isUserSuppliedWindow)
 	{ // we want windowed mode
 		attributes.event_mask |= ExposureMask;
 		attributes.event_mask |= FocusChangeMask;
@@ -656,7 +679,11 @@
 			switch (event.type)
 			{
 			case ConfigureNotify:
-				// check for changed window size
+				
+                                if(event.xconfigure.display != display || event.xconfigure.window != window) 
+                                break;
+
+                                // check for changed window size
 				if ((event.xconfigure.width != (int) Width) ||
 					(event.xconfigure.height != (int) Height))
 				{
@@ -1159,6 +1186,8 @@
 		param.Vsync,
 		param.AntiAlias,
 		param.EventReceiver,
+                (XID)param.WindowId,
+                (Display*)param.DisplayPointer,
 		param.SDK_version_do_not_use);
 	
 	if (dev && !dev->getVideoDriver() && param.DriverType != video::EDT_NULL)
--->here<--- you can found already patched files and a test program
I'm member of Irrlicht Italia.org the Italian site for Irrlicht engine
Post Reply