*轉自:
http://old.blog.edu.cn/user3/zjdukang/archives/2007/1751751.shtml
(1) void glutInit(int *argc, char **argv);
這個函數用來初始化GLUT庫.這個函數從main函數獲取其兩個參數.對應main函數的形式應是:int main(int argc,char* argv[]);
//*******************************************************************************************
(2) void glutInitDisplayMode(unsigned int mode);
設置圖形顯示模式.參數mode的可選值為:
GLUT_RGBA:當未指明GLUT—RGBA或GLUT—INDEX時,是默認使用的模式.表明欲建立RGBA模式的窗口.
GLUT_RGB:與GLUT—RGBA作用相同.
GLUT_INDEX:指明為顏色索引模式.
GLUT_SINGLE:只使用單緩存
GLUT_DOUBLE:使用雙緩存.以避免把計算機作圖的過程都表現出來,或者為了平滑地實現動畫.
GLUT_ACCUM:讓窗口使用累加的緩存.
GLUT_ALPHA:讓顏色緩沖區使用alpha組件.
GLUT_DEPTH:使用深度緩存.
GLUT_STENCIL:使用模板緩存.
GLUT_MULTISAMPLE:讓窗口支持多例程.
GLUT_STEREO:使窗口支持立體.
GLUT_LUMINACE:luminance是亮度的意思.但是很遺憾,在多數OpenGL平臺上,不被支持.
//******************************************************************************************
(3) void glutInitWindowPosition(int x, int y);
設置初始窗口的位置(窗口左上角相對于桌面坐標(x,y))
//******************************************************************************************
(4) void glutInitWindowSize(int width, int height);
設置初始窗口的大小
//******************************************************************************************
(5) void glutMainLoop(void);
讓glut程序進入事件循環.在一個glut程序中最多只能調用一次,且必須調用.一旦調用,會直到程序結束才返回.
//******************************************************************************************
(6) void glutInitDisplayString(const char *string);
通過一個字符串初始化display mode
參數:string:display mode的描述字符串
這個描述字符串用在創建頂級窗口,子窗口和重疊層時,給將要被創建的窗口或重疊層設置display mode.
這個字符串是由0個或多個功能描述參數組成,每個功能描述參數用空格或tab鍵隔開.(若未給參數限制緩存精度大小,則采用默認值)
例如:
glutInitDisplayString("stencil~2 rgb double depth>=16 samples");
上例將窗口初始化為至少2位的模板緩存,RGB模式alpha占用位數為0,深度緩存至少為16位,如果平臺支持的話使用mutlisampling技術.
可以使用的符號有:
= 等號
!= 不等號
< 小于號(越小越好)
> 大于號(越大越好)
<= 小于等于(越小越好)
>= 大于等于(盡可能選擇大的數值,主要用于顏色緩存或深度緩存等對位數要求高的參數設置)
~ 大于等于(但盡可能選擇小的數值,有效利用資源,主要用于模板緩存等)
主要參數:
alpha : alpaha緩存精度, 默認值>=1,即大于等于1位;
acca : red, green, blue, 和alpha累積緩存精度, 默認值>=1
acc : red, green, blue累積緩存精度, 默認值>=1,alpha累積緩存精度為0;
blue : blue顏色緩存精度, 默認值>=1;
buffer: 顏色索引緩存精度, 默認值>=1;
conformant :布爾值,指示幀緩存配置是否一致,該值基于GLX的EXT_visual_rationg擴展的支持,若不支持,則默認為一致, 默認值=1;
depth : 深度緩存精度, 默認值>=12;
double: 布爾值,指示顏色緩存是否是雙倍緩存. 默認值=1;
green : green顏色緩存精度,默認值>=1;
index : 布爾值,指示是否為顏色索引,true表示是顏色索引, 默認值>=1;
num : 專用名詞,指示數值表示的第n個幀緩存配置與這個描述字符串相符合的地方,當沒有指定,則glutInitDisplayString也返回初始(最佳符合)配置.
red : red顏色緩存精度, 默認值>=1;
rgba : rgba模式,顏色緩存精度默認值>=1;
rgb : rgb模式,顏色緩存精度默認值>=1,alpha精度=0;
luminance: 設置red顏色緩存精度,默認值>=1,其他顏色緩存精度=0(alpha沒有指定);
stencil: 模板緩存精度
single: 布爾值,指示顏色緩存是否為單緩存, 默認值=1;
stereo :布爾值,標示顏色緩存支持OpenGL的三維系統,默認值=1;
samples: 標示multisamples的值,這個值是基于GLX的SGIS_multisample的擴展.默認值<=4.這個默認值表示如果支持的話可以在glutInitDisplayString中添加描述參數讓glut請求multipsampling;
slow : 布爾值,標示幀緩存配置是否是slow的.對于X11對glut的執行,slow信息是基于GLX的EXT_visual_rating擴展的支持,如果不支持,就認為是fast;對于win32對glut的執行,slow是基于像素格式描述(pixel format Descriptor即PFD)被標記為"generic"并且未被標記為"accelerated",這說明Microsoft關于slow的OpenGL執行只用在PFD中.這個參數的作用是幫助程序避免對于當前機器的幀緩存配置越來越慢.默認值>=0,表示slow visuals優先于fast visuals,但fast visuals仍然被允許.
win32pdf : 只在win32系統中識別glut的請求,這個參數與win32中的像素格式(pixel format)相匹配,它的值是個數字
xvisual: 只在X Window系統中識別glut的請求,這個參數與X visual ID相匹配,它的值是個數字
xstaticgray: 只在X Window系統中識別glut請求,是個布爾值,標示幀緩存配置的X visual是否是StaticGray. 默認值=1
xgrayscale : 只在X Window系統中識別glut的請求,是個布爾值,標示幀緩存配置的X visual是否是GrayScale. 默認值=1;
xstaticcolor: 只在X Window系統中識別glut的請求,是個布爾值,標示幀緩存配置的X visual是否是StaticColor. 默認值=1;
xpseudocolor : 只在X Window系統中識別glut的請求,是個布爾值,標示幀緩存配置的X visual是否是PsuedoColor. 默認值=1;
xtruecolor : 只在X Window系統中識別glut的請求,是個布爾值,標示幀緩存配置的X visual是否是TrueColor. 默認值=1;
xdirectcolor : 只在X Window系統中識別glut的請求,是個布爾值,標示幀緩存配置的X visual是否是DirectColor. 默認值=1;
//*******************************************************************************************
網上沒有搜到關于glut的完整資料,于是下狠心自己花時間整理了一下.這里只是glut初始化的API,其中void glutInitDisplayString(const char *string);在國內網站上沒搜到具體解釋,是從國外網站上翻譯過來的,本人英文水平有限,可能有錯誤,下面貼上英文原文,望達人指點.(其他API 會在以后分類后陸續給出).
void glutInitDisplayString(const char *string) - sets the initial display mode via a string.
string:Display mode description string, see below.
Description:
The initial display mode description string is
used when creating top-level windows,subwindows,
and overlays to determine the OpenGL display mode
for the to-be-created window or overlay.
The string is a list of zero or more capability
descriptions separated by spaces and tabs.Each
capability description is a capability name that
is optionally followed by a comparator and a
numeric value.For example,"double" and "depth>=12"
are both valid criteria.
The capability descriptions are translated into
a set of criteria used to select the appropriate
frame buffer configuration.
The criteria are matched in strict left to right
order of precdence.That is,the first specified
criteria(leftmost) takes precedence over the later
criteria for nonexact criteria (greater than,less
than,etc.comparators).Exact criteria (equal, not
equal compartors) must match exactly so precedence
is not relevant.
The numeric value is an integer that is parsed
according to ANSI C's strtol(str,strptr,0) behavior.
This means that decimal,octal(leading 0),and
hexidecimal values(leading 0x) are accepeted.
The valid compartors are:
= Equal.
!= Not equal.
< Less than and preferring larger difference
(theleast is best).
> Greater than and preferring larger differences
(the most is best).
<= Less than or equal and preferring larger
difference(the least is best).
>= Greater than or equal and preferring more
instead of less. This comparator is useful for
allocating resources like color precsion or
depth buffer precision where the maximum
precison is generally preferred.Contrast with
the tilde (~) comprator.
~ Greater than or equal but preferring less
instead of more.This compartor is useful for
allocating resources such as stencil bits or
auxillary color buffers where you would rather
not over allocate.
When the compartor and numeric value are not
specified,each capability name has a different
default(one default is to require a compartor
and numeric value).
The valid capability names are:
alpha:Alpha color buffer precision in bits.Default
is ">=1".
acca:Red,green,blue,and alpha accumulation buffer
precision in bits.Default is ">=1" for red,
green,blue,and alpha capabilities.
acc:Red,green,and green accumulation buffer
precision in bits and zero bits of alpha
accumulation buffer precision.Default is ">=1"
for red,green,and blue capabilities,and "~0"
for the alpha capability.
blue:Blue color buffer precision in bits.Default
is ">=1".
buffer:Number of bits in the color index color
buffer.Default is ">=1".
conformant:
Boolean indicating if the frame buffer
configuration is conformant or not.
Conformance information is based on GLX's
EXT_visual_rating extension if supported.
If the extension is not supported,all
visuals are assumed conformat.Default is
"=1".
depth:Number of bits of precsion in the depth
buffer.Default is ">=12".
double:Boolean indicating if the color buffer is
double buffered.Default is "=1".
green:Green color buffer precision in bits.Default
is ">=1".
index:Boolean if the color model is color index or
not.True is color index.Default is ">=1".
num:A special capability name indicating where the
value represents the Nth frame buffer
configuration matching the description string.
When not specified,glutInitDisplayString also
returns the first(best matching) configuration.
num requires a compartor and numeric value.
red;Red color buffer precision in bits.Default is
">=1".
rgba:Number of bits of red,green,blue,and alpha
in the RGBA color buffer.Default is ">=1"
for red,green,blue,and alpha capabilities,
and "=1" for the RGBA color model capability.
rgb:Number of bits of red,green,and blue in the
RGBA color buffer and zero bits of alpha color
buffer precision.Default is ">=1" for the red,
green,and blue capabilities,and "~0" for alpha
capability,and "=1" for the RGBA color model
capability.
luminance:
Number of bits of red in the RGBA and zero
bits of green,blue(alpha not specified) of
color buffer precision.Default is ">=1"
for the red capabilitis,and "=0" for the green
and blue capabilities,and "=1" for the RGBA
color model capability,and,for X11,"=1" for the
StaticGray ("xstaticgray")capability.SGI
InfiniteReality(and other future machines)
support a 16-bit luminance (single channel)
display mode(an additional 16-bit alpha channel
can also be requested).The red channel maps to
gray scale and green and blue channels are not
available.A 16-bit precision luminance display
mode is often appropriate for medical imaging
applications.Do not expect many machines to
support extended precision luminance display
modes.
stencil:Number of bits in the stencil buffer.
single:Boolean indicate the color buffer is single
buffered.Double buffer capability "=1".
stereo:Boolean indicating the color buffer is
supports OpenGL-style stereo.Default is "=1".
samples:Indicates the number of multisamples to use
based on GLX's SGIS_multisample extension(for
antialiasing).Default is "<=4". This default
means that a GLUT application can request
multipsampling if available by simply
specifying "samples".
slow:Boolean indicating if the frame buffer
configuration is slow or not.For the X11
implementation of GLUT,slowness information is
based on GLX's EXT_visual_rating extension if
supported.If the EXT_visual_rating extension is
not supported,all visuals are assumed fast.For
the Win32 implementation of GLUT,slowness is
based on if the underlying Pixel Format Descriptor
(PFD)is marked "generic" and not "accelerated".
This implies that Microsoft's relatively slow
software OpenGL implementation is used by this
PFD.Note that slowness is a relative designation
relative to other frame buffer configurations
available.The intent of the slow capability is to
help programs avoid frame buffer configurations
that are slower(but perhaps higher precision) for
the current machine.Default is ">=0" if not
comparator and numeric value are provided.This
default means that slow visuals are used in
preference to fast visuals,but fast visuals will
still be allowed.
win32pfd:
Only recognized on GLUT implementations for Win32,
this capability name matches the Win32 Pixel For-
mat Descriptor by numer. win32pfd requires a com-
partor and numeric value.
xvisual:Only recongized on GLUT implementations for the
X Window System,this capability name matches
the X visual ID by number.xvisual requires a
compartor and numeric value.
xstaticgray:
Only recongized on GLUT implementations for the
X Window System,boolean indicating if the frame
buffer configuration's X visual is of type Stat-
icGray.Default is "=1".
xgrayscale:
Only recongized on GLUT implementations for the
X Window System,boolean indicating if the frame
buffer configuration's X visual is of type
GrayScale.Default is "=1".
xstaticcolor:
Only recongized on GLUT implementations for the
X Window System,boolean indicating if the frame
buffer configuration's X visual is of type
StaticColor.Default is "=1".
xpseudocolor:
Only recongized on GLUT implementations for the
X Window System,boolean indicating if the frame
buffer configuration's X visual is of type
PsuedoColor.Default is "=1".
xtruecolor:
Only recongized on GLUT implementations for the
X Window System,boolean indicating if the frame
buffer configuration's X visual is of type
TrueColor.Default is "=1".
xdirectcolor:
Only recongized on GLUT implementations for the
X Window System,boolean indicating if the frame
buffer configuration's X visual is of type
DirectColor.Default is "=1".
Unspecifed capability descriptions will result in
unspecified criteria being generated.These unspecified
criteria help glutInitDisplayString behave sensibly
with terse display mode description strings.For
example,if no "slow" capability description is provided,
fast frame buffer configurations will be choosen in
preference to slow frame buffer configurations,but slow
frame buffer configurations will still be choosen if
no better fast frame buffer configuration is available.
Example:
Here is an examples using glutInitDisplayString:
glutInitDisplayString("stencil~2 rgb double depth>=16 samples");
The above call requests a window with an RGBA color
model(but requesting no bits of alpha),a depth buffer
with at least 16 bits of precsion but preferring more,
mutlisampling if available,and at least 2 bits of
stencil(favoring less stencil to more as long as 2 bits
are available).