Index: Horde3D/Source/Shared/utPlatform.h =================================================================== --- Horde3D/Source/Shared/utPlatform.h (revision 149) +++ Horde3D/Source/Shared/utPlatform.h (working copy) @@ -39,8 +39,12 @@ # endif #endif +#ifndef PLATFORM_X11 +# if defined( __linux__ ) +# define PLATFORM_X11 +# endif +#endif - #ifndef DLLEXP # ifdef PLATFORM_WIN # define DLLEXP extern "C" __declspec( dllexport ) Index: Horde3D/Source/Horde3DUtils/main.cpp =================================================================== --- Horde3D/Source/Horde3DUtils/main.cpp (revision 149) +++ Horde3D/Source/Horde3DUtils/main.cpp (working copy) @@ -31,6 +31,9 @@ # define NOMINMAX # include #endif +#ifdef PLATFORM_X11 +# include +#endif #ifndef PLATFORM_MAC # include #endif @@ -66,41 +69,137 @@ HDC hDC = 0; HGLRC hRC = 0; #endif + +#ifdef PLATFORM_X11 + Display * dpy=0; + Window win; + GLXContext ctx; + static Bool WaitForNotify (Display *d, XEvent *e, char *arg) + { + return (e->type == MapNotify) & (e->xmap.window == (Window)arg); + } +#endif - string cleanPath( string path ) + // ********************************************************************************************* + // Exported API functions + // ********************************************************************************************* + + // TODO: Make OpenGL functions platform independent + + DLLEXP bool initOpenGLX11(Display* display,Window window) { - // Remove spaces at the beginning - int cnt = 0; - for( int i = 0; i < (int)path.length(); ++i ) + + #ifdef PLATFORM_X11 + dpy=display; + + int attributeList[] = + { + GLX_RGBA, + GLX_DOUBLEBUFFER, + GLX_RED_SIZE, + 1, + GLX_GREEN_SIZE, + 1, + GLX_BLUE_SIZE, + 1, + None + }; + + int scr=XDefaultScreen(dpy); + + XVisualInfo * vis = glXChooseVisual(dpy, scr,attributeList); + + if (vis == NULL) { - if( path[i] != ' ' ) break; - else ++cnt; + return false; } - if( cnt > 0 ) path.erase( 0, cnt ); + + ctx = glXCreateContext(dpy, vis, 0, GL_TRUE); - // Remove slashes, backslashes and spaces at the end - cnt = 0; - for( int i = (int)path.length() - 1; i >= 0; --i ) + if(ctx == NULL) { - if( path[i] != '/' && path[i] != '\\' && path[i] != ' ' ) break; - else ++cnt; + return false; } + + Colormap cmap = XCreateColormap(dpy, RootWindow(dpy, vis->screen), vis->visual, AllocNone); + if(cmap == BadAlloc) + { + return false; + } + if(cmap == BadMatch) + { + return false; + } + if(cmap == BadValue) + { + return false; + } + if(cmap == BadWindow) + { + return false; + } - if( cnt > 0 ) path.erase( path.length() - cnt, cnt ); + XSetWindowAttributes swa; + swa.colormap = cmap; + swa.border_pixel = 0; + swa.event_mask = StructureNotifyMask; - return path; + //RootWindow(dpy, vis->screen) + win=XCreateWindow(dpy, window, + + 0, 0, 200, 200, 0, vis->depth, + + InputOutput, vis->visual, + + CWBorderPixel|CWColormap|CWEventMask, + + &swa); + + if(win == BadAlloc) + { + return false; + } + if(win == BadMatch) + { + return false; + } + if(win == BadValue) + { + return false; + } + if(win == BadWindow) + { + return false; + } + + XMapWindow (dpy, win); + + XEvent event; + XIfEvent (dpy, &event, WaitForNotify, (char *)win); + + // Make sure that our window ends up on top of things + XRaiseWindow(dpy, win); + + Bool success=glXMakeCurrent (dpy, win, ctx); + + if(success==False) + return false; + + //glViewport(0, 0, 200, 200); + //glClear( GL_COLOR_BUFFER_BIT ); + //glFlush(); + //glXSwapBuffers(dpy,win); + + return true; + #else + return false; + #endif } - - // ********************************************************************************************* - // Exported API functions - // ********************************************************************************************* - - // TODO: Make OpenGL functions platform independent - DLLEXP bool initOpenGL( int hdc ) { + #ifdef PLATFORM_WIN hDC = (HDC)(__int64)hdc; @@ -160,6 +259,16 @@ DLLEXP void releaseOpenGL() { + #ifdef PLATFORM_X11 + if(dpy==0) return; + if( !glXMakeCurrent(dpy,None,NULL)) + { + return; + } + glXDestroyContext(dpy,ctx); + glXDestroyWindow(dpy,win); + dpy=0; + #endif #ifdef PLATFORM_WIN if( hDC == 0 || hRC == 0 ) return; @@ -175,17 +284,54 @@ #endif } + DLLEXP void setOpenGLWindowSize(int width, int height) + { + #ifdef PLATFORM_X11 + if(dpy==0) return; + XWindowChanges windowChanges; + windowChanges.width=width; + windowChanges.height=height; + XConfigureWindow(dpy,win,CWWidth|CWHeight,&windowChanges); + #endif + } DLLEXP void swapBuffers() { + #ifdef PLATFORM_X11 + if(dpy==0) return; + glClear( GL_COLOR_BUFFER_BIT ); + glXSwapBuffers(dpy,win); + #endif #ifdef PLATFORM_WIN if( hDC == 0 || hRC == 0 ) return; - SwapBuffers( hDC ); #endif } + string cleanPath( string path ) + { + // Remove spaces at the beginning + int cnt = 0; + for( int i = 0; i < (int)path.length(); ++i ) + { + if( path[i] != ' ' ) break; + else ++cnt; + } + if( cnt > 0 ) path.erase( 0, cnt ); + // Remove slashes, backslashes and spaces at the end + cnt = 0; + for( int i = (int)path.length() - 1; i >= 0; --i ) + { + if( path[i] != '/' && path[i] != '\\' && path[i] != ' ' ) break; + else ++cnt; + } + + if( cnt > 0 ) path.erase( path.length() - cnt, cnt ); + + return path; + } + DLLEXP const char *getResourcePath( int type ) { return resourcePaths[type].c_str(); Index: Horde3D/Samples/Chicago .NET/sample - Chicago .NET.csproj =================================================================== --- Horde3D/Samples/Chicago .NET/sample - Chicago .NET.csproj (revision 149) +++ Horde3D/Samples/Chicago .NET/sample - Chicago .NET.csproj (working copy) @@ -1,4 +1,5 @@ - + + Debug AnyCPU @@ -18,15 +19,12 @@ DEBUG;TRACE prompt 4 - false x86 pdbonly false ..\..\Build\ - - prompt 4 x86 @@ -38,20 +36,24 @@ full x86 prompt + 4 + false ..\..\Binaries\Win32\ pdbonly x86 prompt + 4 + false - + @@ -60,27 +62,21 @@ + Designer ResXFileCodeGenerator - Resources.Designer.cs - Designer RenderForm.cs Designer - True Resources.resx - True SettingsSingleFileGenerator - Settings.Designer.cs - True Settings.settings - True Form @@ -107,4 +103,9 @@ + + + + + \ No newline at end of file Index: Horde3D/Bindings/C#/Source/Horde3D .NET/Horde3DUtils_Import.cs =================================================================== --- Horde3D/Bindings/C#/Source/Horde3D .NET/Horde3DUtils_Import.cs (revision 149) +++ Horde3D/Bindings/C#/Source/Horde3D .NET/Horde3DUtils_Import.cs (working copy) @@ -44,6 +44,13 @@ [DllImport(UTILS_DLL), SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.U1)] // represents C++ bool type internal static extern bool initOpenGL(int hDC); + + [DllImport(UTILS_DLL), SuppressUnmanagedCodeSecurity] + [return: MarshalAs(UnmanagedType.U1)] // represents C++ bool type + internal static extern bool initOpenGLX11(IntPtr display,long window); + + [DllImport(UTILS_DLL), SuppressUnmanagedCodeSecurity] + internal static extern void setOpenGLWindowSize(int width, int height); [DllImport(UTILS_DLL), SuppressUnmanagedCodeSecurity] internal static extern void releaseOpenGL(); Index: Horde3D/Bindings/C#/Source/Horde3D .NET/Horde3DUtils.cs =================================================================== --- Horde3D/Bindings/C#/Source/Horde3D .NET/Horde3DUtils.cs (revision 149) +++ Horde3D/Bindings/C#/Source/Horde3D .NET/Horde3DUtils.cs (working copy) @@ -61,7 +61,17 @@ { return NativeMethodsUtils.initOpenGL(hDC); } - + + public static bool initOpenGLX11(IntPtr display, IntPtr window) + { + return NativeMethodsUtils.initOpenGLX11(display,window.ToInt64()); + } + + public static void setOpenGLWindowSize(int width,int height) + { + NativeMethodsUtils.setOpenGLWindowSize(width,height); + } + /// /// This utility function destroys the previously created OpenGL rendering context. ///