From 67d27a20a0b0722ec2f211f1a9454a038f0db01e Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 14 Apr 2014 10:50:57 +0400 Subject: [PATCH] Use visual Id on Linux --- src/XGUI/XGUI_Main.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/XGUI/XGUI_Main.cpp b/src/XGUI/XGUI_Main.cpp index f851637d6..26f8d58fd 100644 --- a/src/XGUI/XGUI_Main.cpp +++ b/src/XGUI/XGUI_Main.cpp @@ -2,9 +2,82 @@ #include #include +#ifndef WIN32 + +#include +#include + +/*! + \brief Open the default X display and returns pointer to it. + This method is available on Linux only. + \return Pointer to X display. + \sa getVisual() +*/ +void* getDisplay() +{ + static Display* pDisplay = NULL; + if ( !pDisplay ) + pDisplay = XOpenDisplay( NULL ); + return pDisplay; +} + +/*! + \brief Returns pointer to X visual suitable for 3D rendering. + This method is available on Linux only. + \return Pointer to X visual. + \sa getDisplay() +*/ +Qt::HANDLE getVisual() +{ + Qt::HANDLE res = (Qt::HANDLE)NULL; + + Display* pDisplay = (Display*)getDisplay(); + if ( !pDisplay ) + return res; + + int errorBase; + int eventBase; + + // Make sure OpenGL's GLX extension supported + if( !glXQueryExtension( pDisplay, &errorBase, &eventBase ) ){ + qCritical( "Could not find glx extension" ); + return res; + } + + // Find an appropriate visual + + int doubleBufferVisual[] = { + GLX_RGBA, // Needs to support OpenGL + GLX_DEPTH_SIZE, 16, // Needs to support a 16 bit depth buffer + GLX_DOUBLEBUFFER, // Needs to support double-buffering + None // end of list + }; + + // Try for the double-bufferd visual first + XVisualInfo *visualInfo = NULL; + visualInfo = glXChooseVisual( pDisplay, DefaultScreen(pDisplay), doubleBufferVisual ); + + if( visualInfo == NULL ){ + qCritical( "Could not find matching glx visual" ); + return res; + } + + qDebug() << "Picked visual 0x" << hex << XVisualIDFromVisual( visualInfo->visual ); + res = (Qt::HANDLE)( visualInfo->visual ); + + return res; +} +#endif // WIN32 + + + int main(int argc, char *argv[]) { +#ifndef WIN32 + QApplication app(getDisplay(), argc, argv, getVisual()); +#else QApplication app(argc, argv); +#endif // Install translator QTranslator aTranslator; -- 2.39.2