Fullscreen OpenGL under XWindows (Linux)

Fullscreen OpenGL under XWindows (Linux)

Post by Josh » Fri, 11 Jun 1999 04:00:00



I've been looking for fullscreen tutorials forever, but can't seem to
find anything.  Everybody wants to do stuff in windows for some reason.
Anybody know of any good tutorials, or can give me the basic idea of how
to initialize everything?
 
 
 

Fullscreen OpenGL under XWindows (Linux)

Post by Jan Fische » Sat, 12 Jun 1999 04:00:00


Hi!

Quote:> I've been looking for fullscreen tutorials forever, but can't seem to
> find anything.  Everybody wants to do stuff in windows for some reason.
> Anybody know of any good tutorials, or can give me the basic idea of how
> to initialize everything?

If you're using GLUT, simply call glutFullScreen() after creating the
window. This will open a screen-sized, borderless windows (giving the
impression of a fullscreen program).

Jan

 
 
 

Fullscreen OpenGL under XWindows (Linux)

Post by Ron Fosne » Sat, 12 Jun 1999 04:00:00


For Windows program all you have to do is create a WS_POPUP window with no
border to get a fullscreen window.

Of course, the next question invariably is "Yes, that works great! But now I
want to change the resolution of the screen first."  Fow which you can use
DirectDraw (NOT Direct3D!).

Ron

 
 
 

Fullscreen OpenGL under XWindows (Linux)

Post by Chris Schoenema » Sat, 12 Jun 1999 04:00:00



> For Windows program all you have to do is create a WS_POPUP window with no
> border to get a fullscreen window.

I think you read the subject line too fast, Ron. :)

Here's the code I use in bzflag for X11.  I don't know how you change
screen resolution, though.  (I believe XFree86 has an extension for this.)

The code doesn't compile as is because of calls like display->getRootWindow().
I think you can guess how to fix those.  It's C++, btw.

cheers,
-chris

void                    XWindow::setFullscreen()
{
  // see if a motif based window manager is running.  do this by
  // getting the _MOTIF_WM_INFO property on the root window.  if
  // it exists then make sure the window it refers to also exists.
  Boolean isMWMRunning = False;
  Atom a = XInternAtom(display->getDisplay(), "_MOTIF_WM_INFO", True);
  if (a) {
    struct BzfPropMotifWmInfo {
      public:
        long            flags;
        Window          wmWindow;
    };

    Atom type;
    int format;
    unsigned long nitems;
    unsigned long bytes_after;
    long* mwmInfo;
    XGetWindowProperty(display->getDisplay(), display->getRootWindow(),
                        a, 0, 4, False,
                        a, &type, &format, &nitems, &bytes_after,
                        (unsigned char**)&mwmInfo);
    if (mwmInfo) {
      // get the mwm window from the properties
      const Window mwmWindow = ((BzfPropMotifWmInfo*)mwmInfo)->wmWindow;
      XFree(mwmInfo);

      // verify that window is a child of the root window
      Window root, parent, *children;
      unsigned int numChildren;
      if (XQueryTree(display->getDisplay(), mwmWindow, &root, &parent,
                &children, &numChildren)) {
        XFree(children);
        if (parent == display->getRootWindow())
          isMWMRunning = True;
      }
    }
  }

  // turning off decorations is window manager dependent
  if (isMWMRunning) {
    // it's a Motif based window manager
    long hints[4];
    hints[0] = 0;
    hints[1] = 0;
    hints[2] = 0;
    hints[3] = 0;
    long* xhints;
    a = XInternAtom(display->getDisplay(), "_MOTIF_WM_HINTS", False);
    {
      // get current hints
      Atom type;
      int format;
      unsigned long nitems;
      unsigned long bytes_after;
      XGetWindowProperty(display->getDisplay(), window, a, 0, 4, False,
                        a, &type, &format, &nitems, &bytes_after,
                        (unsigned char**)&xhints);
      if (xhints) {
        hints[0] = xhints[0];
        hints[1] = xhints[1];
        hints[2] = xhints[2];
        hints[3] = xhints[3];
        XFree(xhints);
      }
    }
    hints[0] |= 2;              // MWM_HINTS_DECORATIONS flag
    hints[2] = 0;                       // no decorations
    XChangeProperty(display->getDisplay(), window, a, a, 32,
                        PropModeReplace, (unsigned char*)&hints, 4);
    noWM = False;
  }

  else {
    // non-motif window manager.  use override redirect to prevent window
    // manager from messing with our appearance.  unfortunately, the user
    // can't move or iconify the window either.
    XSetWindowAttributes attr;
    attr.override_redirect = True;
    XChangeWindowAttributes(display->getDisplay(),
                                window, CWOverrideRedirect, &attr);
    noWM = True;
  }

  // now set position and size
  long dummy;
  XSizeHints xsh;
  XGetWMNormalHints(display->getDisplay(), window, &xsh, &dummy);
  xsh.x = 0;
  xsh.y = 0;
  xsh.base_width = getDisplay()->getWidth();
  xsh.base_height = getDisplay()->getHeight();
  xsh.flags |= USPosition | PPosition | PBaseSize;

#ifdef __linux__
  {
    int eventbase, errorbase;
    char *env;

    env=getenv("MESA_GLX_FX");
    if (env && *env=='f') { // Full screen Mesa mode
      xsh.base_width=640;
      xsh.base_height=480;
    }
#if defined(__i386__)
    else {
      // Check if we have the XF86 vidmode extension, for virtual roots
      if (XF86VidModeQueryExtension(display->getDisplay(), &eventbase,
                                    &errorbase)) {
        int dotclock;
        XF86VidModeModeLine modeline;

        XF86VidModeGetModeLine(display->getDisplay(), display->getScreen(),
                               &dotclock, &modeline);
        xsh.base_width=modeline.hdisplay;
        xsh.base_height=modeline.vdisplay;
        if (modeline.c_private) XFree(modeline.c_private);
      }
    }
#endif
  }
#endif

  // set the window manager hints for the window and move and resize
  // the window (overriding the window manager).  we have to override
  // the window manager for the move and resize because the window
  // *must* be the correct size when we first bind the OpenGL context
  // for the 3Dfx driver since it cannot handle later resizes.  if we
  // don't override the window manager, our move and resize will
  // probably be ignored.
  if (!noWM) {
    XSetWindowAttributes attr;
    attr.override_redirect = True;
    XChangeWindowAttributes(display->getDisplay(),
                                window, CWOverrideRedirect, &attr);
  }
  XSetWMNormalHints(display->getDisplay(), window, &xsh);
  XMoveResizeWindow(display->getDisplay(), window, xsh.x, xsh.y,
                        xsh.base_width, xsh.base_height);
  if (!noWM) {
    XSetWindowAttributes attr;
    attr.override_redirect = False;
    XChangeWindowAttributes(display->getDisplay(),
                                window, CWOverrideRedirect, &attr);
  }
  XSync(display->getDisplay(), False);

Quote:}

 
 
 

Fullscreen OpenGL under XWindows (Linux)

Post by Ron Fosne » Mon, 14 Jun 1999 04:00:00


Quote:

>I think you read the subject line too fast, Ron. :)

Ayup - I think you're right!

Ron

 
 
 

Fullscreen OpenGL under XWindows (Linux)

Post by Ryan Haks » Tue, 15 Jun 1999 04:00:00



> For Windows program all you have to do is create a WS_POPUP window with no
> border to get a fullscreen window.

> Of course, the next question invariably is "Yes, that works great! But now I
> want to change the resolution of the screen first."  Fow which you can use
> DirectDraw (NOT Direct3D!).

Actually no, you can't (or at least you shouldnt) Some OpenGL drivers
are implemented on top of DirectDraw. (Or so I hear). The correct
solution is to use ChangeDisplaySettings(). Source code as allways on my
web page.

l8r
Ryan

--
-+-+--+-+-> http://home.bc.rogers.wave.ca/borealis/ryan.html <-+-+--+-+-

 Ryan Haksi                     "Hah, that makes six shots I counted!"

                                "I re-loaded..." -the rebuttal

 
 
 

Fullscreen OpenGL under XWindows (Linux)

Post by Lev » Tue, 15 Jun 1999 04:00:00


OpenGL drivers on top of DirectDraw???

I dont know of any and I do not think this is the case(at least on hardware
specific drivers)



> > For Windows program all you have to do is create a WS_POPUP window with no
> > border to get a fullscreen window.

> > Of course, the next question invariably is "Yes, that works great! But now I
> > want to change the resolution of the screen first."  Fow which you can use
> > DirectDraw (NOT Direct3D!).

> Actually no, you can't (or at least you shouldnt) Some OpenGL drivers
> are implemented on top of DirectDraw. (Or so I hear). The correct
> solution is to use ChangeDisplaySettings(). Source code as allways on my
> web page.

> l8r
> Ryan

> --
> -+-+--+-+-> http://home.bc.rogers.wave.ca/borealis/ryan.html <-+-+--+-+-

>  Ryan Haksi                     "Hah, that makes six shots I counted!"

>                                 "I re-loaded..." -the rebuttal