Mail Archives: djgpp/1993/06/21/09:09:35
I posted a message about having difficulty with the above topic.
I was mailed by someone who was also having problems with this.
I managed to figure out how to get this to work with a lot of help
from a co-worker here. My return message to the person who was
having problems bounced back to me. I figured this may be of
general use to the mailing list so I'll post it here.
/* I made savedimage a global so that it could be saved or restored
anytime throughout the program */
Grcontext *savedimage;
void save_backgrnd(void)
{
int imagesizex, imagesizey;
/* The right, left, top and bottom coordinates can be any part or
all of the current context (which in my case the current context
was the screen */
imagesizex = rightx - leftx;
imagesizey = bottomy - topy;
/* Create the memory location (a "context") to hold the image,
the last two NULL pointers just tell the library to use
it's own memory allocation instead of one you provide */
savedimage = GrCreateContext(imagesizex, imagesizey, NULL, NULL);
/* The above has now saved an area of the screen in a global pointer
accessible at any time */
}
void restore_backgrnd(void)
{
int imagesizex, imagesizey;
/* leftx, rightx, topy, bottomy are globals that are unchanged
since save_backgrnd() was called */
imagesizex = rightx - leftx;
imagesizey = bottomy - topy;
/* Restore the area in memory to a context. If NULL is entered
as the context then it is drawn to the screen. Remember
that 0, 0 for x,y in savedimage is the upper left of the image
that was located at leftx, topy in screen coordinates */
GrBitBlt(NULL, leftx, topy, savedimage, 0, 0, imagesizex, imagesizey,
GrWRITE);
/* Free the memory used by savedimage */
GrDestroyContext(savedimage);
}
It was pointed out to me that if another GrContext instead of NULL
is used as the first argument to GrBitBlt then the image will
be written to a memory location. In this way you can do page swapping
with the number of pages limited only by your system memory and the
resolution up to the full resolution of your video card. Very
nice.
***********************************************************************
* Joe Clark | Internet : joe AT ziggy DOT larc DOT nasa DOT gov *
* NASA Langley Research Center | *
* MS 152E | Phone : 804-864-6655 *
* Hampton, VA 23665 | FAX : 804-864-7793 *
***********************************************************************
- Raw text -