GLboolean FWindow::Linux_InitializeGL() { if(!Context) { Context = glXCreateContext( WindowManager::GetDisplay(), VisualInfo, 0, GL_TRUE); if(Context) { glXMakeCurrent(WindowManager::GetDisplay(), WindowHandle, Context); XWindowAttributes l_Attributes; XGetWindowAttributes(WindowManager::GetDisplay(), WindowHandle, &l_Attributes); Position[0] = l_Attributes.x; Position[1] = l_Attributes.y; const char* ExtensionsAvailable = 0; ExtensionsAvailable = glXQueryExtensionsString(WindowManager::GetDisplay(), 0); if(!ExtensionsAvailable) { PrintWarningMessage(WARNING_NOGLEXTENSIONS); } else { InitGLExtensions(); } ContextCreated = GL_TRUE; return FOUNDATION_OKAY; } } else { PrintErrorMessage(ERROR_EXISTINGCONTEXT); return FOUNDATION_ERROR; } return FOUNDATION_ERROR; }
// Implement static initializer function to create this class. Render::RenderDevice* RenderDevice::CreateDevice(const RendererParams& rp, void* oswnd) { HWND hwnd = (HWND)oswnd; PIXELFORMATDESCRIPTOR pfd; memset(&pfd, 0, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.iPixelType = PFD_TYPE_RGBA; pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER; pfd.cColorBits = 32; pfd.cDepthBits = 16; HDC dc = GetDC(hwnd); int pf = ChoosePixelFormat(dc, &pfd); if (!pf) { ReleaseDC(hwnd, dc); return NULL; } if (!SetPixelFormat(dc, pf, &pfd)) { ReleaseDC(hwnd, dc); return NULL; } HGLRC context = wglCreateContext(dc); if (!wglMakeCurrent(dc, context)) { wglDeleteContext(context); ReleaseDC(hwnd, dc); return NULL; } InitGLExtensions(); return new RenderDevice(rp, hwnd, dc, context); // return 0; }
// Implement static initializer function to create this class. Render::RenderDevice* RenderDevice::CreateDevice(const RendererParams& rp, void* oswnd) { HWND hwnd = (HWND)oswnd; HDC dc = GetDC(hwnd); if (!DwmEnableComposition) { HINSTANCE hInst = LoadLibrary( L"dwmapi.dll" ); OVR_ASSERT(hInst); DwmEnableComposition = (PFNDWMENABLECOMPOSITIONPROC)GetProcAddress( hInst, "DwmEnableComposition" ); OVR_ASSERT(DwmEnableComposition); } DwmEnableComposition(DWM_EC_DISABLECOMPOSITION); { PIXELFORMATDESCRIPTOR pfd; memset(&pfd, 0, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.iPixelType = PFD_TYPE_RGBA; pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER; pfd.cColorBits = 32; pfd.cDepthBits = 16; int pf = ChoosePixelFormat(dc, &pfd); if (!pf) { ReleaseDC(hwnd, dc); return NULL; } if (!SetPixelFormat(dc, pf, &pfd)) { ReleaseDC(hwnd, dc); return NULL; } HGLRC context = wglCreateContext(dc); if (!wglMakeCurrent(dc, context)) { wglDeleteContext(context); ReleaseDC(hwnd, dc); return NULL; } wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB"); wglDeleteContext(context); } int iAttributes[] = { //WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, WGL_SUPPORT_OPENGL_ARB, GL_TRUE, WGL_COLOR_BITS_ARB, 32, WGL_DEPTH_BITS_ARB, 16, WGL_DOUBLE_BUFFER_ARB, GL_TRUE, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE, 0, 0}; float fAttributes[] = {0,0}; int pf = 0; UINT numFormats = 0; if (!wglChoosePixelFormatARB(dc, iAttributes, fAttributes, 1, &pf, &numFormats)) { ReleaseDC(hwnd, dc); return NULL; } PIXELFORMATDESCRIPTOR pfd; memset(&pfd, 0, sizeof(pfd)); if (!SetPixelFormat(dc, pf, &pfd)) { ReleaseDC(hwnd, dc); return NULL; } GLint attribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 2, WGL_CONTEXT_MINOR_VERSION_ARB, 1, WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 0 }; HGLRC context = wglCreateContextAttribsARB(dc, 0, attribs); if (!wglMakeCurrent(dc, context)) { wglDeleteContext(context); ReleaseDC(hwnd, dc); return NULL; } InitGLExtensions(); return new RenderDevice(rp, hwnd, context); }
void InitGL( void ) { InitGLExtensions(); CheckDestinationAlphaSupport(); }
int Pane::Initialise( ) { m_pDisplay = XOpenDisplay( "" ); if( !m_pDisplay ) { std::cout << "Failed to open display" << std::endl; return 0; } int VisualAttributes[ ] = { GLX_X_RENDERABLE, True, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_DOUBLEBUFFER, True, None }; int GLXMajor = 0, GLXMinor = 0; if( !glXQueryVersion( m_pDisplay, &GLXMajor, &GLXMinor ) ) { std::cout << "Failed to query GLX version" << std::endl; return 0; } int FBCount = 0; GLXFBConfig *pFBC = glXChooseFBConfig( m_pDisplay, DefaultScreen( m_pDisplay ), VisualAttributes, &FBCount ); GLXFBConfig FBConfig = pFBC[ 0 ]; XFree( pFBC ); pFBC = NULL; m_pVisualInfo = glXGetVisualFromFBConfig( m_pDisplay, FBConfig ); XSetWindowAttributes WindowAttributes; WindowAttributes.colormap = XCreateColormap( m_pDisplay, RootWindow( m_pDisplay, m_pVisualInfo->screen ), m_pVisualInfo->visual, AllocNone ); WindowAttributes.border_pixel = 0; WindowAttributes.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | FocusChangeMask | EnterWindowMask | LeaveWindowMask| ButtonPressMask | ButtonReleaseMask; m_Window = XCreateWindow( m_pDisplay, RootWindow( m_pDisplay, m_pVisualInfo->screen ), 0, 0, 800, 600, 0, m_pVisualInfo->depth, InputOutput, m_pVisualInfo->visual, CWEventMask | CWColormap | CWBorderPixel, &WindowAttributes ); XMapWindow( m_pDisplay, m_Window ); XMapRaised( m_pDisplay, m_Window ); XMoveWindow( m_pDisplay, m_Window, 0, 0 ); XRaiseWindow( m_pDisplay, m_Window ); m_GLXContext = glXCreateContext( m_pDisplay, m_pVisualInfo, 0, True ); glXMakeCurrent( m_pDisplay, m_Window, m_GLXContext ); char *pGLVersion = ( char * )glGetString( GL_VERSION ); char *pTokenVersion = strtok( pGLVersion, ". " ); for( int i = 0; i < 2; ++i ) { m_GLVersion[ i ] = atoi( pTokenVersion ); pTokenVersion = strtok( NULL, ". " ); } std::cout << "OpenGL version: " << m_GLVersion[ 0 ] << "." << m_GLVersion[ 1 ] << std::endl; if( ( m_GLVersion[ 0 ] < 1 ) || ( ( m_GLVersion[ 0 ] == 1 ) && ( m_GLVersion[ 1 ] < 1 ) ) ) { std::cout << "Failed to create an OpenGL 1.1 context" << std::endl; return 0; } XTextProperty Text; char *pList = new char[ 1024 ]; memset( pList, '\0', 1024*sizeof( char ) ); strcat( pList, "MULE | Client" ); #if defined MULE_BUILD_DEBUG strcat( pList, " [DEBUG] " ); #elif defined MULE_BUILD_PROFILE strcat( pList, " [PROFILE] " ); #endif #if defined MULE_BUILD_DEBUG || MULE_BUILD_PROFILE strcat( pList, GIT_COMMITHASH ); #endif XmbTextListToTextProperty( m_pDisplay, &pList, 1, XStringStyle, &Text ); delete [ ] pList; pList = NULL; XSetWMName( m_pDisplay, m_Window, &Text ); /* XEvent Event; Atom State = XInternAtom( m_pDisplay, "_NET_WM_STATE", False ); Atom MaxHorz = XInternAtom( m_pDisplay, "_NET_WM_STATE_MAXIMIZED_HORZ", False ); Atom MaxVert = XInternAtom( m_pDisplay, "_NET_WM_STATE_MAXIMIZED_VERT", False ); memset( &Event, 0, sizeof( Event ) ); Event.type = ClientMessage; Event.xclient.window = m_Window; Event.xclient.message_type = State; Event.xclient.format = 32; Event.xclient.data.l[ 0 ] = 1; //_NET_WM_STATE_ADD; Event.xclient.data.l[ 1 ] = MaxHorz; Event.xclient.data.l[ 2 ] = MaxVert; XSendEvent( m_pDisplay, DefaultRootWindow( m_pDisplay ), False, SubstructureNotifyMask, &Event );*/ if( InitGLExtensions( m_GLVersion[ 0 ], m_GLVersion [ 1 ] ) ) { std::cout << "Failed to initialise GL extensions" << std::endl; return 0; } glClearColor( 1.0f, 0.0f, 1.0f, 1.0f ); glEnable( GL_TEXTURE_2D ); m_pElements = new RemoteDisplayElement[ 1 ]; m_pElements[ 0 ].Dimensions( 800, 600 ); m_pElements[ 0 ].Initialise( ); return 1; }