Ejemplo n.º 1
0
void GemMan :: destroyWindow()
{
  GemMan::pleaseDestroy=false;

  // don't want to get rid of this
  //  if (s_singleContext) return;

  // nothing to destroy...
  if (!m_windowState) return;

  stopRendering();
  clock_unset(s_windowClock);
  s_windowClock = NULL;

  glFlush();
  glFinish();

  destroyGemWindow(gfxInfo);

  m_windowState = 0;
    
  windowCleanup();

  // this should really go into the GemWinCreate<OS> files::

  // reestablish the const glxContext 
  /* this crashes on linux with intel cards */
  gemWinMakeCurrent(constInfo);
  s_windowRun = 0;
}
Ejemplo n.º 2
0
/////////////////////////////////////////////////////////
// destroy window
//
/////////////////////////////////////////////////////////
void gemglxwindow :: destroy(void)
{
  /* both glXMakeCurrent() and XCloseDisplay() will crash the application
   * if the handler of the display (m_pimpl->dpy) is invalid, e.g. because
   * somebody closed the Gem-window with xkill or by clicking on the "x" of the window
   */
  if (m_pimpl->dpy) {
    int err=0;

#ifdef HAVE_LIBXXF86VM
    if (m_pimpl->fs) {
      XF86VidModeSwitchToMode(m_pimpl->dpy, m_pimpl->screen, &m_pimpl->deskMode);
      XF86VidModeSetViewPort(m_pimpl->dpy, m_pimpl->screen, 0, 0);
      m_pimpl->fs=0;
    }
#endif

    /* patch by cesare marilungo to prevent the crash "on my laptop" */
    glXMakeCurrent(m_pimpl->dpy, None,
                   NULL); /* this crashes if no window is there! */
    if (m_pimpl->glxcontext) {
      // this crashes sometimes on my laptop:
      glXDestroyContext(m_pimpl->dpy, m_pimpl->glxcontext);
    }

    if (m_pimpl->win) {
      XUnmapWindow      (m_pimpl->dpy, m_pimpl->win);
      err=XDestroyWindow(m_pimpl->dpy, m_pimpl->win);
      if(err) {
        verbose(1, "XDestroyWindow returned %d", err);
      }
    }

    if (m_pimpl->cmap) {
      err=XFreeColormap(m_pimpl->dpy, m_pimpl->cmap);
      if(err) {
        verbose(1, "XFreeColormap returned %d", err);
      }
    }

    XFlush( m_pimpl->dpy );
    err=XCloseDisplay(m_pimpl->dpy); /* this crashes if no window is there */
    if(err) {
      verbose(1, "XCloseDisplay returned %d", err);
    }
  }
  m_pimpl->dpy = NULL;
  m_pimpl->win = 0;
  m_pimpl->cmap = 0;
  m_pimpl->glxcontext = NULL;
  if(m_pimpl->delete_atom) {
    m_pimpl->delete_atom=None;  /* not very sophisticated destruction...*/
  }

  destroyGemWindow();
}
Ejemplo n.º 3
0
/////////////////////////////////////////////////////////
// destroyGemWindow
//
/////////////////////////////////////////////////////////
void gemw32window:: destroy(void)
{
  if (m_fullscreen)
    ChangeDisplaySettings(NULL,0);	// Switch Back To The Desktop

  if(m_win)
    delete m_win;
  m_win=NULL;

  destroyGemWindow();
}
Ejemplo n.º 4
0
/////////////////////////////////////////////////////////
// destroy window
//
/////////////////////////////////////////////////////////
void gemglutwindow :: destroy(void)
{
  destroyGemWindow();
  m_window=0;
  info("window", "closed");
}
Ejemplo n.º 5
0
/////////////////////////////////////////////////////////
// destroy window
//
/////////////////////////////////////////////////////////
void gemsdlwindow :: destroy(void)
{
  destroyGemWindow();
  m_surface=NULL;
  info("window", "closed");
}
Ejemplo n.º 6
0
/////////////////////////////////////////////////////////
// createGemWindow
//
/////////////////////////////////////////////////////////
GEM_EXTERN int createGemWindow(WindowInfo &info, WindowHints &hints)
{
  static int firstTime = 1;

  // Register the frame class
  HINSTANCE hInstance = GetModuleHandle(NULL);
  if (!hInstance)
    {
      error("GEM: Unable to get module instance");
      return(0);
    }
  if (firstTime)
    {
      WNDCLASS wndclass;
      wndclass.style         = 0;
      wndclass.lpfnWndProc   = (WNDPROC)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(0);
        }
      firstTime = 0;
    }

  DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
  DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;

  hints.real_w = hints.width;
  hints.real_h = hints.height;

  int x = hints.x_offset;
  int y = hints.y_offset;

  bool fullscreen=(hints.fullscreen!=0);
  if (fullscreen){
    DEVMODE dmScreenSettings;								// Device Mode

    if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dmScreenSettings)){
      error("GEM: couldn't get screen capabilities!");
    }
    int w = dmScreenSettings.dmPelsWidth;
    int h = dmScreenSettings.dmPelsHeight;

    x=y=0;

    memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
    dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
    dmScreenSettings.dmPelsWidth	= hints.width;			// Selected Screen Width
    dmScreenSettings.dmPelsHeight	= hints.height;			// Selected Screen Height
    dmScreenSettings.dmBitsPerPel	= 32;					// Selected Bits Per Pixel
    dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
    // Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
    if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) {
      dmScreenSettings.dmPelsWidth	= w;
      dmScreenSettings.dmPelsHeight	= h;
      if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) {
	error("GEM: couldn't switch to fullscreen");
	fullscreen=false;
      } else {
	hints.real_h=h;
	hints.real_w=w;
      }
    }
  }
  if (fullscreen){
    dwExStyle  = WS_EX_APPWINDOW;
    style     |= WS_POPUP;
  } else {
    dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
    if (hints.border)
      style |= WS_OVERLAPPEDWINDOW;
    else
      style |= WS_POPUP;
  }

  info.fs = fullscreen;//hints.fullscreen;

  // Since Windows uses some of the window for the border, etc,
  //		we have to ask how big the window should really be
  RECT newSize;
  newSize.left = x;
  newSize.top = y;
  newSize.right = hints.real_w+x;
  newSize.bottom = hints.real_h+y;

  AdjustWindowRectEx(&newSize, style, FALSE, dwExStyle); // no menu

  if (newSize.left<0 && x>=0){
	  newSize.right-=newSize.left;
	  newSize.left=0;
  }
  if (newSize.top<0 && y>=0){
	  newSize.bottom-=newSize.top;
	  newSize.top=0;
  }

  // Create the window
  info.win = CreateWindowEx (
			     dwExStyle,
			     "GEM",
			     hints.title,
			     style,
			     newSize.left,
			     newSize.top,
			     newSize.right - newSize.left,
			     newSize.bottom - newSize.top,
			     NULL,
			     NULL,
			     hInstance,
			     NULL);

  if (!info.win)  {
      error("GEM: Unable to create window");
      return(0);
    }

  // create the device context
  info.dc = GetDC(info.win);
  if (!info.dc)  {
      error("GEM: Unable to create device context");
      destroyGemWindow(info);
      return(0);
    }

  // set the pixel format for the window
  if (!bSetupPixelFormat(info.dc, hints))  {
      error("GEM: Unable to set window pixel format");
      destroyGemWindow(info);
      return(0);
    }

  // create the OpenGL context
  info.context = wglCreateContext(info.dc);
  if (!info.context)  {
      error("GEM: Unable to create OpenGL context");
      destroyGemWindow(info);
      return(0);
    }

  // do we share display lists?
  if (hints.shared) wglShareLists(hints.shared, info.context);

  // make the context the current rendering context
  if (!wglMakeCurrent(info.dc, info.context))   {
      error("GEM: Unable to make OpenGL context current");
      destroyGemWindow(info);
      return(0);
    }

  if (!hints.actuallyDisplay) return(1);

  // show and update main window
  if (fullscreen){
    ShowWindow(info.win,SW_SHOW);				// Show The Window
    SetForegroundWindow(info.win);				// Slightly Higher Priority
    SetFocus(info.win);
  } else  ShowWindow(info.win, SW_SHOWNORMAL);

  UpdateWindow(info.win);

  return(1);
}
Ejemplo n.º 7
0
/////////////////////////////////////////////////////////
// destroyConstWindow
//
/////////////////////////////////////////////////////////
void destroyConstWindow()
{
  if (!s_singleContext)
    destroyGemWindow(constInfo);
}
Ejemplo n.º 8
0
/////////////////////////////////////////////////////////
// createGemWindow
//
/////////////////////////////////////////////////////////
GEM_EXTERN int createGemWindow(WindowInfo &info, WindowHints &hints)
{
  static int firstTime = 1;
  if (firstTime) {
    SDL_Init(SDL_INIT_VIDEO);
    firstTime = 0;
  }

  if (! hints.actuallyDisplay) {
    return(1);
  }

  int w = hints.width;
  int h = hints.height;
  int x = hints.x_offset;
  int y = hints.y_offset;
  bool fullscreen = (hints.fullscreen != 0);
  bool border = (hints.border != 0);

  info.win = SDL_CreateWindow(hints.title, x, y, w, h
    , SDL_WINDOW_OPENGL
    | SDL_WINDOW_RESIZABLE
    | (fullscreen ? SDL_WINDOW_FULLSCREEN : 0)
    | (border ? 0 : SDL_WINDOW_BORDERLESS)
    );
  info.fs = fullscreen;

  if (! info.win)  {
    error("GEM: Unable to create window");
    return(0);
  }

// Emscripten doesn't support shared contexts yet
#if 0
  if (hints.shared) {
    if (SDL_GL_MakeCurrent(info.win, hints.shared)) {
      error("GEM: Unable to make shared OpenGL context current: %s", SDL_GetError());
      destroyGemWindow(info);
      return(0);
    }
    SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
  }
#endif
  info.context = SDL_GL_CreateContext(info.win);
#if 0
  if (! info.context) {
    error("GEM: Unable to create OpenGL context: %s", SDL_GetError());
    SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 0);
    destroyGemWindow(info);
    return(0);
  }
  SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 0);
#endif

  if (SDL_GL_MakeCurrent(info.win, info.context)) {
    error("GEM: Unable to make OpenGL context current: %s", SDL_GetError());
    destroyGemWindow(info);
    return(0);
  }

  if (fullscreen) {
    SDL_RaiseWindow(info.win);
  }

  return(1);
}