5

I'm trying to grasp programming graphics with Xlib and OpenGL. I can create windows etc., but I stuck at changing display modes.

I can list available video modes with Xrandr functions (XRRSizes, XRRRates, XRRGetScreenInfo, XRRConfigSizes), check which one is currently set (XRRConfigCurrentConfiguration), and change the resolution (XRRSetScreenConfig).

I can list available bit depths (a.k.a. color depths, that is, bits per pixel) with XListDepths.

What I don't know is how to change the bit depth for a given screen.

I couldn't find any suitable function for setting bit depths along with screen sizes in Xrandr. It seems to be totally ignorant about bit depths, which is really weird. I couldn't find any suitable function in the Xlib documentation either.

So my question is:
How to chhange the resolution and bit depth programatically under Linux?
Are there any functions in the Xlib library or somewhere else?

I know that there are full-blown libraries for graphics, such as SDL, but I don't want to use them as a dependency just for changing display modes, since I'm attempting to write a minimal graphics library myself, for learning purposes.

Edit:
What I want to achieve doesn't have to be done particularly with Xlib or X, but it has to cooperate with X gracefully. E.g. I don't want to get rid of X altogether ─ It is still useful for displaying graphics in windowed mode. But i also need some way for switching to fullscreen mode where I need full control over the video mode: resolutions, color depths, refresh rates, and direct access to the actual pixels in the frame buffer, not some "emulation". I assume that there is some way to do it, since there are video games who can do it on Linux.

SasQ
  • 14,009
  • 7
  • 43
  • 43
  • You cannot change the screen depth. – n. m. could be an AI Mar 26 '14 at 11:40
  • @n.m. why not? What would be the purpose of X listing the available screen depths if it wouldn't be possible to choose one of them? And there are games which offer me to select the video mode *and* depth and they can switch to that mode. How? I'd like to recreate this behavior. – SasQ Mar 26 '14 at 11:49
  • You don't switch modes to select between these depths. You can create windows with any listed depth, all at the same time. The screen depth is normally the maximal of the listed values. To replicate the behaviour you switch to desired size, and create a window of desired depth. – n. m. could be an AI Mar 26 '14 at 12:29
  • I don't want to *replicate* nor *simulate* any behavior with some shadow surfaces with desired depth. I'd prefer to access the actual video mode my graphics card supports natively, with the actual 8 bpp pixel format. What sense would it be to use 8 bpp color depths at all if it were emulated (think: slower) with 24/32 bpp? If Xlib cannot do that, then what library can? – SasQ Mar 26 '14 at 12:40
  • 1
    XLib or any other X interface library are irrelevant, as they are but thin layers on top of the wire protocol. Read [here](http://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt) about XRandR wire protocol. Information about depth switching is at the very top. Sorry. – n. m. could be an AI Mar 26 '14 at 13:20

0 Answers0