[vox-tech] [Fwd] Re: Text and Image Scrolling in Xlib

Bill Kendrick vox-tech@lists.lugod.org
Fri, 12 Dec 2003 01:39:28 -0800


I replied directly to Sharad, but his e-mail is over quota!
I decided that it's a useful enough piece of info to be archived on
vox-tech, so I'm fwd'ing my response here. :^)

(And if Sharad's email works again, I can just point him to the archive URL
of this message ;^) ;^) )

-bill!

----- Forwarded message from Bill Kendrick <nbs@sonic.net> -----

On Wed, Nov 26, 2003 at 04:54:19PM -0800, Sharad Bajaj wrote:
> 
> Hello Mr Bill,
> 
> I was looking for help regrading Xlib for some graphics as I have
> two window i want to play movie in one window and in another window
> i want to scroll some image and text,For that purpose i gone thru so
> many documents so find problems
> 
> (1) How Blitting is possible in Xlib as when we make windows we specify
> same GC and whenever we will update gc it will update all display.
> 
> (2) How can we scroll text or Image flicker free in Xlib.


Hi Sharad - Sorry I hadn't gotten back to you, I've been fairly busy,
and I'm pretty rusty with my Xlib coding. :^)

Most of my X-Window programs have been single-window applications, so I can't
really think of how to answer your first question.

For your second, you'll want to use 'double buffering.'

In my game "Bobobot," I create an X-Window 'Pixmap' which I call
"backbuffer."

I do all of my drawing and erasing there, for each loop of the program...
for each 'frame' I want to display, in other words.

Then, when I'm all done, I merely copy the ENTIRE backbuffer onto my
window (an X-Window 'Window' type I named "window" :^) )


So what happens is my image is constructed 'behind the scenes,' and then
finally revealed, all at once, when it's done.

Of course, this happens many times per second... and under X-Window,
with PC hardware, sometimes there can be 'tearing' between frames
(e.g., half of the window shows the new frame, while the other half
still shows the old, but that only happens for a split second, and not
very often).

It greatly reduces flickering, though!  Of course, you pay for it because
you need to have another, window-sized chunk of memory (the Pixmap),
and because you have to do the final, large copy at the end of each frame.

So, it looks better, but costs a little memory and time.  Typically,
computers are fast enough and have enough memory for this not to matter.
It's worth it, to have the program look better. :)

I hope that all makes sense!  Good luck! :)

-bill!

----- End forwarded message -----

-- 
bill@newbreedsoftware.com                           Got kids?  Get Tux Paint! 
http://newbreedsoftware.com/bill/       http://newbreedsoftware.com/tuxpaint/