[comp.sys.mac.programmer] Have you used NewGDevice?

mbrady@mmm.UUCP (Mark W. Brady) (03/11/89)

 I am attempting to create a graphics device for use with an off screen
pixMap on a mac II. According to Inside Mac V, one should begin with a 
call to NewGDevice( refNum: INTEGER; mode: LONGINT ). Since I would have
no driver, IM V says to use -1 for the mode. However, I have no idea as to what
to use for refNum. 

If you can tell me, please do.

ph@cci632.UUCP (Pete Hoch) (03/15/89)

In article <1240@mmm.UUCP>, mbrady@mmm.UUCP (Mark W. Brady) writes:
> 
>  I am attempting to create a graphics device for use with an off screen
> pixMap on a mac II. According to Inside Mac V, one should begin with a 
> call to NewGDevice( refNum: INTEGER; mode: LONGINT ). Since I would have
> no driver, IM V says to use -1 for the mode. However, I have no idea as to
> what to use for refNum. 
> 
> If you can tell me, please do.

Unless you need a GDevice with characteristics other than the real device
that te screen is using forget anout making an offscreen GDevice.  All
you really need to do is set up an offscreen GrafPort.  Then when you
want to use your offscreen PixMap all you need to do is a SetPort to the
offscreen GrafPort and use quick draw to do it's thing.

The only time I needed to set up an offscreen GDevice was when I wanted
the offscreen device to have a greater pixel depth than the real device.
However this case does not come up often.

As to refNum.  NewGDevice is looking for the refNum of the GDevice's
driver code.  Since your offscreen device does not have a driver this
value can be zero.  Actualy I have never used NewGDevice.  I usualy
set one up loke so:


	gDevHand = (GDHandle)NewHandle( sizeof( GDevice));

	/* then I zero out most of the fields. */

	SetDeviceAttribute( gDevHand, noDriver, true);

	/* Other fields of interest. */

	.gdITable; .gdType; .gdResPref; .gdPMap

	/* Lastly I call InitGDevice. */

	InitGDevice( 0, -1, gDevHand);

This is the frame work without all of the code.  I hope this helps.

Pete Hoch

oster@dewey.soe.berkeley.edu (David Phillip Oster) (03/16/89)

Here is one case where I needed a GDevice: I had an arbitrary PICT that
used only two colors, neither of them black or white, and I wanted to draw
it with the colors reversed.  Simple, I thought, I'd just render it to an
offscreen pixmap, with a color table of only two entries, swap the
entries, and CopyBits the offscreen pixmap to the screen.  But noooo,
CopyBits uses the inverse table of the current GDevice as an implicit
parameter to figure out how to map the colors of the pixmap source to the
pixmap destination.  I needed to build a gdevice to get the rather
peculiar color map I wanted.  So, I did it. It works.

IanHendry@apple.com (Ian Hendry) (03/18/89)

> I am attempting to create a graphics device for use with an off screen
>pixMap on a mac II. According to Inside Mac V, one should begin with a 
>call to NewGDevice( refNum: INTEGER; mode: LONGINT ). Since I would have
>no driver, IM V says to use -1 for the mode. However, I have no idea as 
to what
>to use for refNum. 

>If you can tell me, please do.
The correct call is
myGDevice = NewGDevice(-1,-1);

The refnum to use is -1 for creating off screen pixMaps.  At the moment I 
don't know if anything bad will happen if you use 0 and I don't know why 
it is not documented, but I was told  by one of the head quickdraw guys to 
use -1, so I do.  I am hoping for a tech note on the subject to make it 
official (obviously making this posting "unofficial").

Hope this helps,



Ian Hendry
No E-mail, post replies to network.
TE: 408-974-4737

Disclaimer:  It was all HIS idea anyway!