Re: simple(?) question

Search this archive.

From: Jay Link (jlink@ilbbs.com)
Date: Wed 28 Feb 2001 - 16:50:20 IST


> I want to display one screen (or set the display to off) while drawing two
> other screens, and when the second and third screens are finished I want to
> change between those two over and over again until a key is pressed.

Well, as you probably know, vgagl only gives you one "virtual screen".
For those of you who don't know, this is like a "backstage" area in a
theater, where you can set up the props and backdrops needed for the next
act in a play (in privacy) before bringing them all into view at once, by
transfering everything to the physical screen.

However, as I said, you only get one of these built-in memory areas. So, I
think you will have no choice but to create two new memory areas to use
with gl_putbox() and then gl_getbox().

As the man page says:

   The destination pixmap has the size w * h * BYTESPERPIXEL.

So, create two variables of type void or char, and -- since you are using
vgagl -- you can define them using the built-in size macros:

void area1[WIDTH * HEIGHT * BYTESPERPIXEL];
void area2[WIDTH * HEIGHT * BYTESPERPIXEL];

Next, you will need to draw the screen for "area1", and then transfer it
to that area with gl_getbox(). Then, overlay that with the image for
"area2" -- perhaps clearing the screen first, if the two images are sized
differently -- and copy that one with gl_getbox() also.

Here's the syntax:

void gl_getbox(int x, int y, int w, int h, void *dp);
void gl_putbox(int x, int y, int w, int h, void *dp);

Now, you have two options for drawing these screens without anyone seeing
you:

1) As you suggested, you can turn the "real" (or physical screen) off with
vga_screenoff(). However, this depends on the video card, and so it may
not be 100% reliable.

2) Switch your context to gl's virtual screen, and draw everything there.
Then, use gl_getbox() just like before. Since the virtual screen will be
the current context, gl_getbox() will know to look there instead of the
physical screen.

Now, go back to the physical screen, either by using vga_screenon() or
else by changing your context, maybe clear the screen immediately to keep
things clean, and then call gl_putbox() over & over, alternating between
the two memory areas, & probably inserting a slight delay with usleep().

As far as waiting for the user to press a key, you will want a
non-blocking function. So, vga_getch() is BAD in this case, as it will
stop your program. Instead, use either vga_getkey():

       int vga_getkey(void);

DESCRIPTION
       Read  a  character  from  the  keyboard  without  waiting;
       returns  zero if no key pressed and the ASCII value other-
       wise. This function must not be used in raw keyboard mode.
       In   this   situation  use  keyboard_getstate(3)  or  key-
       board_keypressed(3) instead.

or else vga_waitevent(), which will also look for mouse events.


Hope that helps!

-J


------------------------------------------------------------------
Unsubscribe:  To:   listbot@svgalib.org
              Body: unsubscribe linux-svgalib


This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:23 IST