tesscallback.3gl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. '\" e
  2. '\"! eqn | mmdoc
  3. '\"macro stdmacro
  4. .ds Vn Version 1.2
  5. .ds Dt 6 March 1997
  6. .ds Re Release 1.2.0
  7. .ds Dp May 02 11:53
  8. .ds Dm 37 tesscallb
  9. .ds Xs 14825 12 tesscallback.gl
  10. .TH GLUTESSCALLBACK 3G
  11. .SH NAME
  12. .B "gluTessCallback
  13. \- define a callback for a tessellation object
  14. .SH C SPECIFICATION
  15. void \f3gluTessCallback\fP(
  16. GLUtesselator* \fItess\fP,
  17. .nf
  18. .ta \w'\f3void \fPgluTessCallback( 'u
  19. GLenum \fIwhich\fP,
  20. _GLUfuncptr \fICallBackFunc\fP )
  21. .fi
  22. .EQ
  23. delim $$
  24. .EN
  25. .SH PARAMETERS
  26. .TP \w'\fICallBackFunc\fP\ \ 'u
  27. \f2tess\fP
  28. Specifies the tessellation object (created with \%\f3gluNewTess\fP).
  29. .TP
  30. \f2which\fP
  31. Specifies the callback being defined. The following values are valid:
  32. \%\f3GLU_TESS_BEGIN\fP,
  33. \%\f3GLU_TESS_BEGIN_DATA\fP,
  34. \%\f3GLU_TESS_EDGE_FLAG\fP,
  35. \%\f3GLU_TESS_EDGE_FLAG_DATA\fP,
  36. \%\f3GLU_TESS_VERTEX\fP,
  37. \%\f3GLU_TESS_VERTEX_DATA\fP,
  38. \%\f3GLU_TESS_END\fP,
  39. \%\f3GLU_TESS_END_DATA\fP,
  40. \%\f3GLU_TESS_COMBINE\fP,
  41. \%\f3GLU_TESS_COMBINE_DATA\fP,
  42. \%\f3GLU_TESS_ERROR\fP, and
  43. \%\f3GLU_TESS_ERROR_DATA\fP.
  44. .TP
  45. \f2CallBackFunc\fP
  46. Specifies the function to be called.
  47. .SH DESCRIPTION
  48. \%\f3gluTessCallback\fP is used to indicate a callback to be used by a tessellation object.
  49. If the specified callback is already defined, then it is replaced. If
  50. \f2CallBackFunc\fP is NULL, then the existing callback becomes undefined.
  51. .P
  52. These callbacks are used by the tessellation object to describe how a
  53. polygon specified by the user is broken into triangles. Note that there
  54. are two versions of each callback: one with user-specified polygon data
  55. and one without. If both versions of a particular callback are specified,
  56. then the callback with user-specified polygon data will be used. Note
  57. that the \f2polygon_data\fP parameter used by some of the functions is
  58. a copy of the pointer that was specified when
  59. \%\f3gluTessBeginPolygon\fP was called. The legal callbacks are as follows:
  60. .TP 10
  61. \%\f3GLU_TESS_BEGIN\fP
  62. The begin callback is invoked like \f3glBegin\fP to indicate the start of
  63. a (triangle) primitive. The function takes a single argument of type
  64. GLenum. If the \%\f3GLU_TESS_BOUNDARY_ONLY\fP property is set to
  65. \%\f3GL_FALSE\fP, then the argument is set to either
  66. \%\f3GL_TRIANGLE_FAN\fP, \%\f3GL_TRIANGLE_STRIP\fP, or \%\f3GL_TRIANGLES\fP. If
  67. the \%\f3GLU_TESS_BOUNDARY_ONLY\fP property is set to \%\f3GL_TRUE\fP,
  68. then the argument will be set to \%\f3GL_LINE_LOOP\fP. The function
  69. prototype for this callback is:
  70. .RS
  71. .Ex
  72. void begin ( GLenum type );
  73. .Ee
  74. .RE
  75. .TP
  76. \%\f3GLU_TESS_BEGIN_DATA\fP
  77. The same as the \%\f3GLU_TESS_BEGIN\fP callback except that it
  78. takes an additional pointer argument. This pointer is identical to the
  79. opaque pointer provided when
  80. \%\f3gluTessBeginPolygon\fP was called. The function prototype for this callback
  81. is:
  82. .RS
  83. .Ex
  84. void beginData ( GLenum type, void *polygon_data );
  85. .Ee
  86. .RE
  87. .TP
  88. \%\f3GLU_TESS_EDGE_FLAG\fP
  89. The edge flag callback is similar to \f3glEdgeFlag\fP. The function
  90. takes a single boolean flag that indicates which edges lie on the
  91. polygon boundary. If the flag is \%\f3GL_TRUE\fP, then each vertex
  92. that follows begins an edge that lies on the polygon boundary, that is,
  93. an edge that separates an interior region from an exterior one.
  94. If the flag is \%\f3GL_FALSE\fP, then each vertex that follows begins an edge
  95. that lies in the polygon interior. The edge flag callback (if defined) is
  96. invoked before the first vertex callback.
  97. .IP
  98. Since triangle fans and triangle strips do not support edge flags, the begin
  99. callback is not called with \%\f3GL_TRIANGLE_FAN\fP or \%\f3GL_TRIANGLE_STRIP\fP
  100. if a non-NULL edge flag callback is provided. (If the callback is
  101. initialized to NULL, there is no impact on performance). Instead, the fans and
  102. strips are converted to independent triangles. The function prototype
  103. for this callback is:
  104. .RS
  105. .Ex
  106. void edgeFlag ( GLboolean flag );
  107. .Ee
  108. .RE
  109. .TP
  110. \%\f3GLU_TESS_EDGE_FLAG_DATA\fP
  111. The same as the \%\f3GLU_TESS_EDGE_FLAG\fP callback except that it takes an additional pointer
  112. argument. This pointer is identical to the opaque pointer provided when
  113. \%\f3gluTessBeginPolygon\fP was called. The function prototype for this callback
  114. is:
  115. .RS
  116. .Ex
  117. void edgeFlagData ( GLboolean flag, void *polygon_data );
  118. .Ee
  119. .RE
  120. .TP
  121. \%\f3GLU_TESS_VERTEX\fP
  122. The vertex callback is invoked between the begin and end callbacks.
  123. It is similar to \f3glVertex\fP, and it defines the vertices of the triangles
  124. created by the tessellation process. The function
  125. takes a pointer as its only argument. This pointer is identical to
  126. the opaque pointer provided by the user when the vertex was described
  127. (see \%\f3gluTessVertex\fP). The function prototype for this callback is:
  128. .RS
  129. .Ex
  130. void vertex ( void *vertex_data );
  131. .Ee
  132. .RE
  133. .TP
  134. \%\f3GLU_TESS_VERTEX_DATA\fP
  135. The same as the \%\f3GLU_TESS_VERTEX\fP callback except that it takes an additional pointer
  136. argument. This pointer is identical to the opaque pointer provided when
  137. \%\f3gluTessBeginPolygon\fP was called. The function prototype for this callback
  138. is:
  139. .RS
  140. .Ex
  141. void vertexData ( void *vertex_data, void *polygon_data );
  142. .Ee
  143. .RE
  144. .TP
  145. \%\f3GLU_TESS_END\fP
  146. The end callback serves the same purpose as \f3glEnd\fP. It indicates the
  147. end of a primitive and it takes no arguments. The function prototype for this
  148. callback is:
  149. .RS
  150. .Ex
  151. void end ( void );
  152. .Ee
  153. .RE
  154. .TP
  155. \%\f3GLU_TESS_END_DATA\fP
  156. The same as the \%\f3GLU_TESS_END\fP callback except that it takes an additional pointer
  157. argument. This pointer is identical to the opaque pointer provided when
  158. \%\f3gluTessBeginPolygon\fP was called. The function prototype for this callback
  159. is:
  160. .RS
  161. .Ex
  162. void endData ( void *polygon_data);
  163. .Ee
  164. .RE
  165. .TP 10
  166. \%\f3GLU_TESS_COMBINE\fP
  167. The combine callback is called to create a new vertex when the tessellation
  168. detects an intersection, or wishes to merge features. The function takes
  169. four arguments: an array of three elements each of type GLdouble, an array
  170. of four pointers, an array of four elements each of type GLfloat, and a
  171. pointer to a pointer. The prototype is:
  172. .RS
  173. .Ex
  174. void combine( GLdouble coords[3], void *vertex_data[4],
  175. GLfloat weight[4], void **outData );
  176. .Ee
  177. .RE
  178. .IP
  179. The vertex is defined as a linear combination of up to four existing vertices,
  180. stored in \f2vertex_data\fP. The coefficients of the linear
  181. combination are given by \f2weight\fP; these weights always add up to 1.
  182. All vertex pointers are valid even when some of the weights are 0.
  183. \f2coords\fP gives the location of the new vertex.
  184. .IP
  185. The user must allocate another vertex, interpolate parameters using
  186. \f2vertex_data\fP and \f2weight\fP, and return the new vertex pointer in
  187. \f2outData\fP. This handle is supplied during rendering callbacks.
  188. The user is responsible for freeing the memory some time after
  189. \%\f3gluTessEndPolygon\fP is called.
  190. .IP
  191. For example, if the polygon lies in an arbitrary plane in 3-space,
  192. and a color is associated with each vertex, the
  193. \%\f3GLU_TESS_COMBINE\fP callback might look like this:
  194. .RS
  195. .Ex
  196. void myCombine( GLdouble coords[3], VERTEX *d[4],
  197. GLfloat w[4], VERTEX **dataOut )
  198. {
  199. VERTEX *new = new_vertex();
  200. new->x = coords[0];
  201. new->y = coords[1];
  202. new->z = coords[2];
  203. new->r = w[0]*d[0]->r + w[1]*d[1]->r + w[2]*d[2]->r + w[3]*d[3]->r;
  204. new->g = w[0]*d[0]->g + w[1]*d[1]->g + w[2]*d[2]->g + w[3]*d[3]->g;
  205. new->b = w[0]*d[0]->b + w[1]*d[1]->b + w[2]*d[2]->b + w[3]*d[3]->b;
  206. new->a = w[0]*d[0]->a + w[1]*d[1]->a + w[2]*d[2]->a + w[3]*d[3]->a;
  207. *dataOut = new;
  208. }
  209. .Ee
  210. .RE
  211. .IP
  212. If the tessellation detects an intersection, then the \%\f3GLU_TESS_COMBINE\fP or
  213. \%\f3GLU_TESS_COMBINE_DATA\fP callback (see below) must be defined, and it must
  214. write a non-NULL pointer into \f2dataOut\fP. Otherwise the
  215. \%\f3GLU_TESS_NEED_COMBINE_CALLBACK\fP error occurs, and no
  216. output is generated.
  217. .TP
  218. \%\f3GLU_TESS_COMBINE_DATA\fP
  219. The same as the \%\f3GLU_TESS_COMBINE\fP callback except that it takes an additional pointer
  220. argument. This pointer is identical to the opaque pointer provided when
  221. \%\f3gluTessBeginPolygon\fP was called. The function prototype for this callback
  222. is:
  223. .RS
  224. .Ex
  225. void combineData ( GLdouble coords[3], void *vertex_data[4],
  226. GLfloat weight[4], void **outData,
  227. void *polygon_data );
  228. .Ee
  229. .RE
  230. .TP 10
  231. \%\f3GLU_TESS_ERROR\fP
  232. The error callback is called when an error is encountered. The one argument
  233. is of type GLenum; it indicates the specific error that occurred and will be
  234. set to one of \%\f3GLU_TESS_MISSING_BEGIN_POLYGON\fP, \%\f3GLU_TESS_MISSING_END_POLYGON\fP,
  235. \%\f3GLU_TESS_MISSING_BEGIN_CONTOUR\fP, \%\f3GLU_TESS_MISSING_END_CONTOUR\fP,
  236. \%\f3GLU_TESS_COORD_TOO_LARGE\fP, \%\f3GLU_TESS_NEED_COMBINE_CALLBACK\fP or
  237. \%\f3GLU_OUT_OF_MEMORY\fP. Character
  238. strings describing these errors can be retrieved with the
  239. \%\f3gluErrorString\fP call. The function prototype for this callback is:
  240. .RS
  241. .Ex
  242. void error ( GLenum errno );
  243. .Ee
  244. .RE
  245. .IP
  246. The GLU library will recover from the first four
  247. errors by inserting the missing call(s).
  248. \%\f3GLU_TESS_COORD_TOO_LARGE\fP indicates that some vertex coordinate exceeded
  249. the predefined constant \%\f3GLU_TESS_MAX_COORD\fP in absolute value, and
  250. that the value has been clamped. (Coordinate values must be small
  251. enough so that two can be multiplied together without overflow.)
  252. \%\f3GLU_TESS_NEED_COMBINE_CALLBACK\fP indicates that the tessellation
  253. detected an intersection between two edges in the input data, and the
  254. \%\f3GLU_TESS_COMBINE\fP or \%\f3GLU_TESS_COMBINE_DATA\fP callback was
  255. not provided. No output is generated. \%\f3GLU_OUT_OF_MEMORY\fP indicates
  256. that there is not enough memory so no output is generated.
  257. .TP
  258. \%\f3GLU_TESS_ERROR_DATA\fP
  259. The same as the \%\f3GLU_TESS_ERROR\fP callback except that it takes an additional pointer
  260. argument. This pointer is identical to the opaque pointer provided when
  261. \%\f3gluTessBeginPolygon\fP was called. The function prototype for this callback
  262. is:
  263. .RS
  264. .Ex
  265. void errorData ( GLenum errno, void *polygon_data );
  266. .Ee
  267. .RE
  268. .SH EXAMPLE
  269. Polygons tessellated can be rendered directly like this:
  270. .sp
  271. .Ex
  272. gluTessCallback(tobj, GLU_TESS_BEGIN, glBegin);
  273. gluTessCallback(tobj, GLU_TESS_VERTEX, glVertex3dv);
  274. gluTessCallback(tobj, GLU_TESS_END, glEnd);
  275. gluTessCallback(tobj, GLU_TESS_COMBINE, myCombine);
  276. gluTessBeginPolygon(tobj, NULL);
  277. gluTessBeginContour(tobj);
  278. gluTessVertex(tobj, v, v);
  279. ...
  280. gluTessEndContour(tobj);
  281. gluTessEndPolygon(tobj);
  282. .Ee
  283. .sp
  284. Typically, the tessellated polygon should be stored in a display list so that
  285. it does not need to be retessellated every time it is rendered.
  286. .SH SEE ALSO
  287. \f3glBegin(3G)\fP, \f3glEdgeFlag(3G)\fP, \f3glVertex(3G)\fP, \%\f3gluNewTess(3G)\fP,
  288. \%\f3gluErrorString(3G)\fP, \%\f3gluTessVertex(3G)\fP,
  289. \%\f3gluTessBeginPolygon(3G)\fP,
  290. \%\f3gluTessBeginContour(3G)\fP, \%\f3gluTessProperty(3G)\fP, \%\f3gluTessNormal(3G)\fP