December 96 - Macintosh Q & A
Macintosh Q & A
Q My application animates moving geometries in QuickDraw 3D. Recently I've been
seeing a lot of screen flicker, and faces of geometries that should be behind other faces
are showing through. What's going on?
A The flickering problem is probably happening because double buffering is turned
off (call Q3DrawContext_SetDoubleBufferState to turn it on) or because double buffer
bypass is set on the interactive renderer and the scene is taking longer than a screen
refresh to render. See page 12-8 of 3D Graphics Programming With QuickDraw 3D
for more information.
Your second problem is likely the result of having an excessively large difference
between hither and yon (and, as a result, not having enough zresolution to resolve
depth differences). Experiment with greater hither values and smaller yon values to
see if the bleed-through goes away.
Q We're using QuickDraw 3D and applying UV attributes to our geometries so that we
can texture-map them. There are, however, two sorts of UVs: surface UVs and shading
UVs. Which one should we use to get the textures to map correctly and what does the
other one do?
A At the time of this writing (QuickDraw 3D 1.5), only the surface UVs are
supported. The shading UVs will be used in a future version to support advanced
shading renderers.
Q What are view hints in the QuickDraw 3D metafile format (3DMF)?
A The concept of view hints was included early on in the development of QuickDraw
3D. It became apparent that the settings for determining how a scene should be
rendered aren't always transportable from one application to another (for example,
settings such as the camera location, lighting, and camera type). The idea of a view
hint is that it sets up a series of hints that tell the reading application how the author
of a metafile intended the geometries within the metafile to be rendered. The fact that
these are hints implies that the reading application can ignore them.
Rather than writing out the lighting information to the metafile as absolute objects, we
recommend creating a view in the normal manner, adding lighting, camera, renderer,
and other information as usual, and then extracting the view hints from the view with
Q3ViewHints_New(theView). You pass in a view object to this function, and it returns
a view hints object that includes the view configuration for the view you pass in. The
Tumbler and Podium sample code that comes with the QuickDraw 3D release
illustrates how to use view hints read from a metafile to configure a view. Look in the
file Tumbler_document.c for details.
Q What's the best way to do collision detection in QuickDraw 3D?
A QuickDraw 3D doesn't directly provide collision detection, but you can use the
bounding boxes or bounding spheres of the geometries to determine whether the bounds
intersect. You can easily calculate bounding boxes and spheres on either individual
geometries or groups of geometries. If the bounds intersect, you can either assume the
objects have collided or test further, depending on your application.
Q In the TQ3CameraData record, is the position of the point of interest relative to the
camera location used for anything other than the view direction of the camera?
A The point of interest is an absolute position -- it's not relative to anything. As the
camera's location changes, the camera "turns" to keep the point of interest in view.
Q TQ3HitData's distance field is described for window-point picking as "the distance
from window point's location on the camera frustum (in world space) to the point of
intersection with the picked object." Does this refer to the center of the intersection of
the pixel's frustum with the hither plane, or maybe the yon plane? Or is it the camera
location?
A TQ3HitData's distance field is the world space distance from the origin of the
picking ray to the intersection point. Effectively, this is the distance from the
camera's location to the geometry intersection point in world coordinates.
Q When I print with background printing enabled, and PrintMonitor fires up and
tries to post an error, my application hangs, and no dialog ever appears. What can I
do?
A Make sure the bits in your SIZE resource are set correctly. This behavior appears
when you've got your "MultiFinder aware" bit set but don't have your "accepts
Suspend/Resume events" bit set.
Q I can't figure out how to get the default settings for the features in a given
QuickDraw GX font. Any ideas?
A A routine to do this, GXGetFontDefaultFeatures, was added after the release of
QuickDraw GX 1.0. This routine will retrieve those layout features defined as default
by a given font. It's fully documented in Technote 1028, "Inside Macintosh: GX Series
Addenda.
Q I want to turn my font (generated with a third-party font design program) into a
true QuickDraw GX font with a customized features menu. How do I do this? What
programs are available for GX font design? Will I be able to add a features menu to my
font after generating it with a non-GX font design program?
A For custom design of QuickDraw GX features in a font, you should use TrueEdit,
which is available (along with other font tools) in the QuickDraw GX folder on the Mac
OS SDK edition of the Developer CD Series, or via ftp in this directory:
/cgi-bin/ftpchooser.pl?partialURL=Development_Kits/QuickDraw_GX/Goodies/
Font_Tools/.
The general process of designing a QuickDraw GX font starts with building all the
glyphs you're interested in and hinting them, just as you would for a non-GX font. Once
you have the glyph repertoire, use TrueEdit to add all the GX tables. You should be able
to add the tables for the various menu features with TrueEdit just fine after you've
built the font with another font design program.
Q I read somewhere that you don't have to call CloseOpenTransport if you're writing
an application. Is this true?
A Yes and no. The original Open Transport programming documentation stated that
calling CloseOpenTransport was optional for applications. There is, however, a bug in
Open Transport 1.1 and earlier whereby native PowerPC applications aren't properly
cleaned up when they terminate unless CloseOpenTransport is called.
Here are some rules of thumb:
• Nonapplication code must always call CloseOpenTransport when it
terminates.
• It's best if 680x0 applications call CloseOpenTransport, but they'll be
cleaned up automatically even if they don't.
• Make sure that PowerPC applications running under Open Transport 1.1
or earlier call CloseOpenTransport when terminating.
One way of ensuring that you comply with the third item is to use a CFM terminate
procedure in your main application fragment, like this:
static Boolean gOTInited = false;
void CFMTerminate(void)
{
if (gOTInited) {
gOTInited = false;
(void) CloseOpenTransport();
}
}
void main(void)
{
OSStatus err;
err = InitOpenTransport();
gOTInited = (err == noErr);
... // the rest of your application
if (gOTInited) {
(void) CloseOpenTransport();
gOTInited = false;
}
}
In general, when the Mac OS provides an automatic cleanup mechanism, it's normally
intended as a "safety net." It's always a good idea to do your own cleanup, at least for
normal application termination.
Q I'm using OTScheduleSystemTask to schedule a task to run at non-interrupt time.
Will this be cleaned up automatically when I call CloseOpenTransport?
A No. You must explicitly clean up any pending system tasks by calling the routine
OTDestroySystemTask. See Technote 1059, "On Improving Open Transport Network
Server Performance," for a good discussion of this.
Q How do I map Open Transport error numbers to their names?
A There are two ways to do this. The first is the OTErr MacsBug dcmd that ships with
the debugging version of Open Transport. This dcmd allows you to quickly map an error
number to a (hopefully) meaningful error name. Once you install it in your Debugger
Prefs file, you can type, for example, "oterr -3271" in MacsBug and get the name for
that error.
The second solution is to read the latest OpenTransport.h header (for Open Transport
version 1.1.1 or later), where the error numbers are now spelled out in an
easy-to-read format.
Q I'm writing an Open Transport server product and will be implementing hand-off
endpoints. What is the maximum qlen value that limits the number of hand-off
endpoints that can be implemented?
A There's a maximum qlen value for each protocol, but maximum values that are
true today for Open Transport may change in the future, so we recommend that you set
the qlen value to a desired value. If the desired value is greater than the number of
hand-off endpoints that the underlying protocol can support, the protocol can specify
its own maximum qlen value for the server endpoint. After making the OTBind call,
take a look at the qlen field of the TBind structure to see whether the protocol imposed
a limit on the qlen value.
Q I'm developing a plug-in (let's call it MyPlugIn) for an application (let's say
CoolApp). I'd like to create a special icon for the documents my plug-in creates, but
they're really CoolApp documents. However, if I add a BNDL resource to MyPlugIn, all
other CoolApp plug-ins become MyPlugIn documents. What can I do?
A Just register a new, unique creator code and use that for the BNDL, but not for the
plug-in. Contrary to popular belief, the owner code for a BNDL doesn't have to match
the creator code of the file it's in.
Another possibility is to create custom icons for documents you create, but this has a
couple of drawbacks: it takes the Finder longer to display them, and you'd be storing