///////////////////////////////////////////////////////// // createMess // ///////////////////////////////////////////////////////// bool gemsdlwindow :: create(void) { if(m_surface) { error("window already made!"); return false; } if ( SDL_InitSubSystem( SDL_INIT_VIDEO ) < 0 ) { error("could not (re)initialize SDL window infrastructure"); return false; } /* Fetch the video info */ const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo( ); m_videoFlags = SDL_OPENGL; /* Enable OpenGL in SDL */ if(2==m_buffer) { m_videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */ /* Sets up OpenGL double buffering */ SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); } else { /* Sets up OpenGL double buffering */ SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 0 ); } m_videoFlags |= SDL_HWPALETTE; /* Store the palette in hardware */ m_videoFlags |= SDL_RESIZABLE; /* Enable window resizing */ if(videoInfo) { /* This checks to see if surfaces can be stored in memory */ if ( videoInfo->hw_available ) m_videoFlags |= SDL_HWSURFACE; else m_videoFlags |= SDL_SWSURFACE; /* This checks if hardware blits can be done */ if ( videoInfo->blit_hw ) m_videoFlags |= SDL_HWACCEL; } /* get a SDL surface */ m_surface = SDL_SetVideoMode( m_width, m_height, m_bpp, m_videoFlags ); if(!m_surface) return false; if(!createGemWindow()) { destroyMess(); return false; } titleMess(m_title); fullscreenMess(m_fullscreen); dispatch(); return true; }
///////////////////////////////////////////////////////// // createConstWindow // ///////////////////////////////////////////////////////// int GemMan::createConstWindow(char* disp) { // can we only have one context? if (s_singleContext) return(GemMan::createWindow(disp)); WindowHints myHints; myHints.title = const_cast<char*>(GemMan::m_title.c_str()); myHints.border = 1; myHints.buffer = 1; myHints.x_offset = 0; myHints.y_offset = 0; myHints.width = GemMan::m_width; myHints.height = GemMan::m_height; initWin_sharedContext(constInfo, myHints); myHints.actuallyDisplay = 0; myHints.fullscreen = 0; myHints.display = disp; myHints.fsaa = GemMan::fsaa; if (!createGemWindow(constInfo, myHints) ) { error("GEM: Error creating const context"); constInfo.have_constContext=0; gfxInfo.have_constContext=0; return(0); } else{ constInfo.have_constContext=1; gfxInfo.have_constContext=1; } return(1); }
///////////////////////////////////////////////////////// // createMess // ///////////////////////////////////////////////////////// bool gemglfw2window :: create(void) { int mode = GLFW_WINDOW; if(0!=s_window) { error("window already made!"); return false; } if(m_fullscreen) mode=GLFW_FULLSCREEN; glfwOpenWindowHint(GLFW_FSAA_SAMPLES, m_fsaa); if(m_profile_major) { glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, m_profile_major); // We want OpenGL 3.3 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, m_profile_minor); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL } if (!glfwOpenWindow(m_width, m_height, 8, 8, 8, 8, /* RGBA bits */ 24, 8, /* depth/stencil bits */ mode)) { error("glfw couldn't create window"); return false; } // FIXXME: single/double buffering if(!createGemWindow()) { destroyMess(); return false; } s_window=this; titleMess(m_title); offsetMess(m_xoffset, m_yoffset); cursorMess(m_cursor); glfwSetWindowSizeCallback (windowsizeCb); glfwSetWindowCloseCallback (windowcloseCb); glfwSetWindowRefreshCallback(windowrefreshCb); glfwSetKeyCallback (keyCb); glfwSetCharCallback (charCb); glfwSetMouseButtonCallback (mousebuttonCb); glfwSetMousePosCallback (mouseposCb); glfwSetMouseWheelCallback (mousewheelCb); dispatch(); return (0!=s_window); }
///////////////////////////////////////////////////////// // createMess // ///////////////////////////////////////////////////////// bool gemglutwindow :: create(void) { if(m_window) { error("window already made!"); return false; } #ifdef FREEGLUT // display list sharing (with FreeGLUT) if(s_windowmap.size()>0) { std::map<int,gemglutwindow*>::iterator it = s_windowmap.begin(); gemglutwindow*other=NULL; other=it->second; if(other && other->makeCurrent()) { glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_USE_CURRENT_CONTEXT ); } } #endif unsigned int mode=GLUT_RGB | GLUT_DEPTH; if(2==m_buffer) mode|=GLUT_DOUBLE; else mode|=GLUT_SINGLE; glutInitDisplayMode(mode); m_window=glutCreateWindow(m_title.c_str()); s_windowmap[m_window]=this; glutDisplayFunc (&gemglutwindow::displayCb); glutVisibilityFunc(&gemglutwindow::visibleCb); glutCloseFunc (&gemglutwindow::closeCb); #ifdef FREEGLUT glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS); #endif glutKeyboardFunc(&gemglutwindow::keyboardCb); glutSpecialFunc(&gemglutwindow::specialCb); glutReshapeFunc(&gemglutwindow::reshapeCb); glutMouseFunc(&gemglutwindow::mouseCb); glutMotionFunc(&gemglutwindow::motionCb); glutPassiveMotionFunc(&gemglutwindow::passivemotionCb); glutEntryFunc(&gemglutwindow::entryCb); glutKeyboardUpFunc(&gemglutwindow::keyboardupCb); glutSpecialUpFunc(&gemglutwindow::specialupCb); glutJoystickFunc(&gemglutwindow::joystickCb, 20); glutMenuStateFunc(&gemglutwindow::menustateCb); glutMenuStatusFunc(&gemglutwindow::menustatusCb); glutWindowStatusFunc(&gemglutwindow::windowstatusCb); // glutNameFunc(&gemglutwindow::nameCb); if(!createGemWindow()) { destroyMess(); return false; } titleMess(m_title); fullscreenMess(m_fullscreen); dispatch(); return true; }
///////////////////////////////////////////////////////// // createMess // ///////////////////////////////////////////////////////// bool gemglxwindow :: create(void) { bool success=true; /* * hmm, this crashes when enabled * when disabled, we don't get textures on two screens */ //~#warning context-sharing disabled bool context_sharing=false; if(!m_context && context_sharing) { /* gemglxwindow::PIMPL::s_shared.count(m_display)>0 */ gemglxwindow::PIMPL*sharedPimpl=&gemglxwindow::PIMPL::s_shared[m_display]; if(!sharedPimpl->glxcontext) { try { int x=0, y=0; unsigned int w=1, h=1; success=sharedPimpl->create(m_display, 2, false, false, x, y, w, h, m_transparent); } catch (GemException&ex) { error("creation of shared glxcontext failed: %s", ex.what()); verbose(0, "continuing at your own risk!"); } if(!sharedPimpl->gemcontext) { try { sharedPimpl->gemcontext = createContext(); } catch (GemException&ex) { sharedPimpl->gemcontext = NULL; error("creation of shared gem::context failed: %s", ex.what()); } } } m_context=sharedPimpl->gemcontext; } else { // no context sharing /* creation of gem::Context is deferred until *after* window creation */ } int modeNum=4; #ifdef HAVE_LIBXXF86VM XF86VidModeModeInfo **modes; #endif char svalue[3]; snprintf(svalue, 3, "%d", m_fsaa); svalue[2]=0; if (m_fsaa!=0) { setenv("__GL_FSAA_MODE", svalue, 1); // this works only for NVIDIA-cards } try { success=m_pimpl->create(m_display, m_buffer, m_fullscreen, m_border, m_xoffset, m_yoffset, m_width, m_height, m_transparent); } catch (GemException&x) { x.report(); success=false; } if(!success) { return false; } /* create a gem::context if we don't already have (a shared) one */ if(!m_context) { try { m_context = createContext(); } catch (GemException&x) { m_context = NULL; error("creation of gem::context failed: %s", x.what()); } } XMapRaised(m_pimpl->dpy, m_pimpl->win); // XMapWindow(m_pimpl->dpy, m_pimpl->win); XEvent report; XIfEvent(m_pimpl->dpy, &report, WaitForNotify, (char*)m_pimpl->win); if (glXIsDirect(m_pimpl->dpy, m_pimpl->glxcontext)) { post("Direct Rendering enabled!"); } cursorMess(m_cursor); titleMess(m_title); return createGemWindow(); }
///////////////////////////////////////////////////////// // createMess // ///////////////////////////////////////////////////////// bool gemglutwindow :: create(void) { if(m_window) { error("window already made!"); return false; } #ifdef FREEGLUT // display list sharing (with FreeGLUT) if(s_windowmap.size()>0) { std::map<int,gemglutwindow*>::iterator it = s_windowmap.begin(); gemglutwindow*other=NULL; other=it->second; if(other && other->makeCurrent()) { glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_USE_CURRENT_CONTEXT ); } } #endif unsigned int mode=GLUT_RGB | GLUT_DEPTH; if(2==m_buffer) mode|=GLUT_DOUBLE; else mode|=GLUT_SINGLE; glutInitDisplayMode(mode); #ifdef FREEGLUT // glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS); glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); glutSetOption(GLUT_INIT_WINDOW_X, m_xoffset); glutSetOption(GLUT_INIT_WINDOW_Y, m_yoffset); glutSetOption(GLUT_INIT_WINDOW_WIDTH, m_width); glutSetOption(GLUT_INIT_WINDOW_HEIGHT, m_height); #endif m_window=glutCreateWindow(m_title.c_str()); s_windowmap[m_window]=this; glutReshapeWindow(m_width, m_height); glutPositionWindow(m_xoffset, m_yoffset); glutCloseFunc (&closeCb); glutKeyboardFunc(&keyboardCb); glutSpecialFunc(&specialCb); glutReshapeFunc(&reshapeCb); glutKeyboardUpFunc(&keyboardupCb); glutSpecialUpFunc(&specialupCb); glutJoystickFunc(&joystickCb, 20); glutMenuStateFunc(&menustateCb); glutMenuStatusFunc(&menustatusCb); glutWindowStatusFunc(&windowstatusCb); #if (defined GLUT_HAS_MULTI) && (GLUT_HAS_MULTI > 0) glutMultiEntryFunc(multiEntryCb); glutMultiButtonFunc(multiButtonCb); glutMultiMotionFunc(multiMotionCb); glutMultiPassiveFunc(multiPassivemotionCb); #else glutEntryFunc(&entryCb); glutMouseFunc(&mouseCb); glutMotionFunc(&motionCb); glutPassiveMotionFunc(&passivemotionCb); #endif // glutNameFunc(&nameCb); glutDisplayFunc (&displayCb); glutVisibilityFunc(&visibleCb); if(!createGemWindow()) { destroyMess(); return false; } titleMess(m_title); fullscreenMess(m_fullscreen); dispatch(); return true; }
///////////////////////////////////////////////////////// // createGemWindow // ///////////////////////////////////////////////////////// bool gemw32window:: create(void) { unsigned int w = m_width; unsigned int h = m_height; int x = m_xoffset; int y = m_yoffset; static bool firstTime = true; // Register the frame class HINSTANCE hInstance = GetModuleHandle(NULL); if (!hInstance) { error("GEM: Unable to get module instance"); return false; } if (firstTime) { WNDCLASS wndclass; wndclass.style = 0; wndclass.lpfnWndProc = (WNDPROC)Window::MainWndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hCursor = LoadCursor(NULL, IDC_CROSS); wndclass.hIcon = LoadIcon(NULL, IDI_WINLOGO); wndclass.hbrBackground = NULL; wndclass.lpszMenuName = NULL; wndclass.lpszClassName = "GEM"; if (!RegisterClass(&wndclass) ) { error("GEM: Unable to register window class"); return false; } firstTime = false; } if (NULL==Window::sharedContext) { static Window*s_sharedWindow=NULL; try { unsigned int w0=0, h0=0; int x0=0, y0=0; s_sharedWindow=new Window(NULL, hInstance, 2, false, false, "GEM", x0, y0, w0, h0); Window::sharedContext=s_sharedWindow->context; } catch (GemException&) { Window::sharedContext=NULL; } } m_win=NULL; try { m_win=new Window(this, hInstance, m_buffer, m_fullscreen>0, m_border, m_title, x, y, w, h); } catch (GemException&x) { error("%s", x.what()); return false; } // show and update main window if (m_fullscreen){ ShowWindow(m_win->win,SW_SHOW); // Show The Window SetForegroundWindow(m_win->win); // Slightly Higher Priority SetFocus(m_win->win); } else { ShowWindow(m_win->win, SW_SHOWNORMAL); } UpdateWindow(m_win->win); dimension(w, h); position(x, y); return createGemWindow(); }
///////////////////////////////////////////////////////// // createWindow // ///////////////////////////////////////////////////////// int GemMan :: createWindow(char* disp) { if ( m_windowState ) return(s_singleContext); debug_post("GemMan: create window"); WindowHints myHints; myHints.border = m_border; myHints.buffer = m_buffer; myHints.width = m_width; myHints.height = m_height; myHints.fullscreen = m_fullscreen; myHints.secondscreen = m_secondscreen; myHints.x_offset = m_xoffset; myHints.y_offset = m_yoffset; myHints.shared = constInfo.context; myHints.actuallyDisplay = 1; myHints.display = disp; myHints.title = const_cast<char*>(GemMan::m_title.c_str()); myHints.fsaa = fsaa; if (disp) post("GEM: creating gem-window on display %s",disp); if (!createGemWindow(gfxInfo, myHints) ) { error("GEM: Unable to create window"); return(0); } /* Check for the presence of a couple of useful OpenGL extensions we can use to speed up the movie rendering. GL_EXT_texture_rectangle allows for non-power-of-two sized textures. Texture coordinates for these textures run from 0..width, 0..height instead of 0..1, 0..1 as for normal power-of-two textures. GL_EXT_texture_rectangle is available on the NVidia GeForce2MX and above, or the ATI Radeon and above. */ glewInitialized=false; GLenum err = glewInit(); if (GLEW_OK != err) { if(GLEW_ERROR_GLX_VERSION_11_ONLY == err) { error("GEM: failed to init GLEW (glx): continuing anyhow - please report any problems to the gem-dev mailinglist!"); } else if (GLEW_ERROR_GL_VERSION_10_ONLY) { error("GEM: failed to init GLEW: your system only supports openGL-1.0"); return(0); } else { error("GEM: failed to init GLEW"); return(0); } } glewInitialized=true; logpost(NULL, 4,"GEM: GLEW version %s",glewGetString(GLEW_VERSION)); checkOpenGLExtensions(); /* check the stack-sizes */ glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, maxStackDepth+STACKMODELVIEW); if(GLEW_ARB_imaging) { glGetIntegerv(GL_MAX_COLOR_MATRIX_STACK_DEPTH, maxStackDepth+STACKCOLOR); } glGetIntegerv(GL_MAX_TEXTURE_STACK_DEPTH, maxStackDepth+STACKTEXTURE); glGetIntegerv(GL_MAX_PROJECTION_STACK_DEPTH, maxStackDepth+STACKPROJECTION); m_w=myHints.real_w; m_h=myHints.real_h; m_windowState = 1; cursorOnOff(m_cursor); topmostOnOff(m_topmost); m_windowNumber++; windowInit(); clock_delay(s_windowClock, s_windowDelTime); s_windowRun = 1; return(1); }