Well, here's one I can take a shot at. The following code is from a program that uses the pallette manager and a custom Color LookUp Table to force a specific set of colors. The error handling isn't very elegant yet so you'd have to improve that but its worked for me during development just fine. Actually this particular routine came out the FB examples folder and I've simply modified it to force 8 bit color and the special CLUT.
The short answer to your question is the "8" in the NEWGWORLD line. That forces the Gworld to be 8 bit, regardless of your monitor settings. The GETCTABLE resource stuff allows you to use a custom color table which can be created (or copied and modified) in ResEdit.
CLEAR LOCAL MODE 'returns an offscreen GWorld
DIM rect;8 'warning: use only with 32-bit color QuickDraw
LOCAL FN getOffScrnGWorld&(rect;8)
ctab&= FN GETCTABLE (130)
LONG IF ctab&<>0
QDErr = FN NEWGWORLD(offPort&,8,rect,ctab&,0,0)'offPort contains offScreen port
LONG IF QDErr 'check for error
CLS:PRINT"Image too big to make offscreen port. QDerr=" QDerr
PRINT "rect"
PRINT "top",rect.top
PRINT "bottom",rect.bottom
PRINT "left",rect.left
PRINT "right",rect.right
STOP 'not very graceful
END IF
XELSE
CLS:PRINT"Can't find color table resource"
STOP
END IF
CALL DISPOSCTABLE(ctab&)
END FN = offPort&
The way I do that may not be optimal, but it works.
I cannot build a CLUT from scratch. I only know how to build a palette and then to derive a CLUT from a palette.
' get the present palette so that you can restore it at the end:
colorWndPtr& = WINDOW(_wndPointer)
gPalette& = FN GETPALETTE(colorWndPtr&)
' build a new palette. Set parameters : entries%, srcColor&,srcUsage%,srcTolerance%.
customPalette& = FN NEWPALETTE()
FOR I = 0 TO (number of colors)
' set the RGB record from an array with red,green,blue values
dstEntry% = 1
CALL SETENTRYCOLOR()
NEXT
CALL SETPALETTE()
CTH& = FN NEWHANDLE(CTabsize&)
CALL PALETTE2CTAB(customPalette&,CTH&)
CALL DISPOSEPALETTE(customPalette&)
' store the CLUT in a resource :
FN pGreplaceRes(CTH&,_"CLUT",ID%,"")
CTH& = FN GETCTABLE(ID%)
' use the CLUT in your GWorld :
QDErr% = FN NEWGWORLD(offPort&,8,rect,CTH&,0,0)
' or in an update :
QDErr% = FN UPDATEGWORLD()
At the end you will have to restore the system CLUT/Palette (there was a post about this some time ago).
You will find what should be in parenthesis by looking in the Help files (toolbox).