Advertisement

Double Buffering on X Windows

Started by November 07, 2005 12:34 PM
4 comments, last by khaplienhoa 18 years, 10 months ago
The first one, I, have decided to start programming on Linux for 2 days :D after 2 years playing with WinAPI. The very first problem is that I can't find any tutorial about double-buffering on X. And if there is, can I directly change the content of the bitmap (like implementing a line drawing function) and just BitBlt it to the window as the way we do on Ms Windows? I only want to do with X, not with OpenGL, SDL, GNOME or KDE. The second one,

diplay = XOpenDisplay (NULL);
white = WhitePixel (display, DefaultScreen(display));
black = BlackPixel (display, DefaultScreen(display));

window = XCreateSimpleWindow (
      display, DefaultRootWindow (display),
      100, 100, 100, 50, 1, black, white);

XSelectInput (display, window, ExposureMask);

XMapWindow (display, window);
and something more like event loop, but I think that's enough. I just want a blank window. But it's funny that sometime my window didn't have a caption/title bar on its top, I mean the bar including minimize, maximize/restore, and close buttons. So where is the problem? The last one, Can I customize the entry point function, so that the first called function is not main (...). Because sometime, my command line is not only in English, meaning Unicode text. That's easy on Ms Windows. Sorry for my bad English. [Edited by - khaplienhoa on November 7, 2005 12:56:26 PM]
I thought you would have to do something to tell it to do double-buffering, but I could be wrong. If you want, you could check the source to libglut, and see how it does it.
Advertisement
X Window System is more complicated to program than Win32 imho, due mostly to the other layers such as Window Managers, which are not actually part of X, but special clients. To set the window title 'properly', certain ICCCM extensions may need to be used.

I think this tutorial should be just what you're looking for.
-bodisiw
It is not automatic as you have to select a Visual when initializing openGL. Not all of your visuals have double buffering support. When you call glXChooseVisual you specify GLX_DOUBLEBUFFER as one of the flags. Then from there, you call glXSwapBuffers(display, window) to swap your buffers.
barrysee, he specified in the original post that he is not interested in OpenGL.
-bodisiw
About double-buffering, http://xander.ncl.ac.uk/game/ helps alot. This lecture may be also interesting http://www.cs.cf.ac.uk/Dave/X_lecture/node17.html
in that Dave stated, "The best approach is to store the drawing data in a Pixmap by writing directly to a Pixmap."

In Ms Windows,
HBITMAP CreateBitmap(  int nWidth,         // bitmap width, in pixels  int nHeight,        // bitmap height, in pixels  UINT cPlanes,       // number of color planes  UINT cBitsPerPel,   // number of bits to identify color  CONST VOID *lpvBits // color data array);

I can plot a pixel directly through lpvBits. But it seems I can not do in the same way with Pixmap. I have implemented a lot of useful graphic functions in Windows, and I want to reuse in Linux.

About window title, thanks NoahAlder, I'll check it out.

About entrypoint, when I used gcc to compile a simple program without main() function, the compiler throwed "crt: main function referenced by _start can not be found" or something like that.
So the real entry point is _start in CRT, not main function. It reminds me of the function WinMainCRTStartup which calls WinMain. I have not used static CRT in MS Windows recently to reduce the executable file size, so I implementd a WinMainStartup by myself, and specify it for my entry-point. Can I speficy my real entry-point with GCC in Linux.

This topic is closed to new replies.

Advertisement