39 #include "glimports.h"
40 #include "glrenderer.h"
46 defineMap(GL_MAP2_NORMAL, 0, 3);
47 defineMap(GL_MAP1_NORMAL, 0, 3);
48 defineMap(GL_MAP2_TEXTURE_COORD_1, 0, 1);
49 defineMap(GL_MAP1_TEXTURE_COORD_1, 0, 1);
50 defineMap(GL_MAP2_TEXTURE_COORD_2, 0, 2);
51 defineMap(GL_MAP1_TEXTURE_COORD_2, 0, 2);
52 defineMap(GL_MAP2_TEXTURE_COORD_3, 0, 3);
53 defineMap(GL_MAP1_TEXTURE_COORD_3, 0, 3);
54 defineMap(GL_MAP2_TEXTURE_COORD_4, 1, 4);
55 defineMap(GL_MAP1_TEXTURE_COORD_4, 1, 4);
56 defineMap(GL_MAP2_VERTEX_4, 1, 4);
57 defineMap(GL_MAP1_VERTEX_4, 1, 4);
58 defineMap(GL_MAP2_VERTEX_3, 0, 3);
59 defineMap(GL_MAP1_VERTEX_3, 0, 3);
60 defineMap(GL_MAP2_COLOR_4, 0, 4);
61 defineMap(GL_MAP1_COLOR_4, 0, 4);
62 defineMap(GL_MAP2_INDEX, 0, 1);
63 defineMap(GL_MAP1_INDEX, 0, 1);
65 setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMETHOD, (
float) N_PATHLENGTH);
66 setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMETHOD, (
float) N_PATHLENGTH);
67 setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMETHOD, (
float) N_PATHLENGTH);
68 setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMETHOD, (
float) N_PATHLENGTH);
70 setnurbsproperty(GL_MAP1_VERTEX_3, N_PIXEL_TOLERANCE, (
float) 50.0);
71 setnurbsproperty(GL_MAP1_VERTEX_4, N_PIXEL_TOLERANCE, (
float) 50.0);
72 setnurbsproperty(GL_MAP2_VERTEX_3, N_PIXEL_TOLERANCE, (
float) 50.0);
73 setnurbsproperty(GL_MAP2_VERTEX_4, N_PIXEL_TOLERANCE, (
float) 50.0);
75 setnurbsproperty(GL_MAP1_VERTEX_3, N_ERROR_TOLERANCE, (
float) 0.50);
76 setnurbsproperty(GL_MAP1_VERTEX_4, N_ERROR_TOLERANCE, (
float) 0.50);
77 setnurbsproperty(GL_MAP2_VERTEX_3, N_ERROR_TOLERANCE, (
float) 0.50);
78 setnurbsproperty(GL_MAP2_VERTEX_4, N_ERROR_TOLERANCE, (
float) 0.50);
80 setnurbsproperty(GL_MAP1_VERTEX_3, N_S_STEPS, (
float) 100.0);
81 setnurbsproperty(GL_MAP1_VERTEX_4, N_S_STEPS, (
float) 100.0);
82 setnurbsproperty(GL_MAP2_VERTEX_3, N_S_STEPS, (
float) 100.0);
83 setnurbsproperty(GL_MAP2_VERTEX_4, N_S_STEPS, (
float) 100.0);
86 set_domain_distance_u_rate(100.0);
88 setnurbsproperty(GL_MAP1_VERTEX_3, N_T_STEPS, (
float) 100.0);
89 setnurbsproperty(GL_MAP1_VERTEX_4, N_T_STEPS, (
float) 100.0);
90 setnurbsproperty(GL_MAP2_VERTEX_3, N_T_STEPS, (
float) 100.0);
91 setnurbsproperty(GL_MAP2_VERTEX_4, N_T_STEPS, (
float) 100.0);
94 set_domain_distance_v_rate(100.0);
95 set_is_domain_distance_sampling(0);
103 errorCallback = NULL;
107 GLUnurbs::bgnrender(
void)
117 GLUnurbs::endrender(
void)
122 GLUnurbs::errorHandler(
int i)
126 gluError = i + (GLU_NURBS_ERROR1 - 1);
127 postError( gluError );
133 GLUnurbs::loadGLMatrices(
void)
138 grabGLMatrix((GLfloat (*)[4]) vmat);
139 loadCullingMatrix((GLfloat (*)[4]) vmat);
140 ::glGetIntegerv((GLenum) GL_VIEWPORT, (GLint *) viewport);
141 loadSamplingMatrix((
const GLfloat (*)[4]) vmat, (
const GLint *) viewport);
146 GLUnurbs::useGLMatrices(
const GLfloat modelMatrix[16],
147 const GLfloat projMatrix[16],
148 const GLint viewport[4])
152 multmatrix4d(vmat, (
const GLfloat (*)[4]) modelMatrix,
153 (
const GLfloat (*)[4]) projMatrix);
154 loadCullingMatrix((GLfloat (*)[4]) vmat);
155 loadSamplingMatrix((
const GLfloat (*)[4]) vmat, (
const GLint *) viewport);
164 GLUnurbs::grabGLMatrix(GLfloat vmat[4][4])
166 GLfloat m1[4][4], m2[4][4];
168 ::glGetFloatv((GLenum) GL_MODELVIEW_MATRIX, (GLfloat *) &(m1[0][0]));
169 ::glGetFloatv((GLenum) GL_PROJECTION_MATRIX, (GLfloat *) &(m2[0][0]));
170 multmatrix4d((GLfloat (*)[4]) vmat,
171 (
const GLfloat (*)[4]) m1, (
const GLfloat (*)[4]) m2);
177 GLUnurbs::setSamplingMatrixIdentity(
void )
179 INREAL smat[4][4] = {
185 const long rstride =
sizeof(smat[0]) /
sizeof(smat[0][0]);
186 const long cstride = 1;
188 setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
190 setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
192 setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
194 setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
200 GLUnurbs::loadSamplingMatrix(
const GLfloat vmat[4][4],
201 const GLint viewport[4])
205 REAL xsize = 0.5 * (REAL) (viewport[2]);
206 REAL ysize = 0.5 * (REAL) (viewport[3]);
209 smat[0][0] = vmat[0][0] * xsize;
210 smat[1][0] = vmat[1][0] * xsize;
211 smat[2][0] = vmat[2][0] * xsize;
212 smat[3][0] = vmat[3][0] * xsize;
214 smat[0][1] = vmat[0][1] * ysize;
215 smat[1][1] = vmat[1][1] * ysize;
216 smat[2][1] = vmat[2][1] * ysize;
217 smat[3][1] = vmat[3][1] * ysize;
224 smat[0][3] = vmat[0][3];
225 smat[1][3] = vmat[1][3];
226 smat[2][3] = vmat[2][3];
227 smat[3][3] = vmat[3][3];
229 const long rstride =
sizeof(smat[0]) /
sizeof(smat[0][0]);
230 const long cstride = 1;
232 setnurbsproperty(GL_MAP1_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
234 setnurbsproperty(GL_MAP1_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
236 setnurbsproperty(GL_MAP2_VERTEX_3, N_SAMPLINGMATRIX, &smat[0][0], rstride,
238 setnurbsproperty(GL_MAP2_VERTEX_4, N_SAMPLINGMATRIX, &smat[0][0], rstride,
243 GLUnurbs::loadCullingMatrix(GLfloat vmat[4][4])
247 cmat[0][0] = vmat[0][0];
248 cmat[0][1] = vmat[0][1];
249 cmat[0][2] = vmat[0][2];
250 cmat[0][3] = vmat[0][3];
252 cmat[1][0] = vmat[1][0];
253 cmat[1][1] = vmat[1][1];
254 cmat[1][2] = vmat[1][2];
255 cmat[1][3] = vmat[1][3];
257 cmat[2][0] = vmat[2][0];
258 cmat[2][1] = vmat[2][1];
259 cmat[2][2] = vmat[2][2];
260 cmat[2][3] = vmat[2][3];
262 cmat[3][0] = vmat[3][0];
263 cmat[3][1] = vmat[3][1];
264 cmat[3][2] = vmat[3][2];
265 cmat[3][3] = vmat[3][3];
267 const long rstride =
sizeof(cmat[0]) /
sizeof(cmat[0][0]);
268 const long cstride = 1;
270 setnurbsproperty(GL_MAP2_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride,
272 setnurbsproperty(GL_MAP2_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride,
275 setnurbsproperty(GL_MAP1_VERTEX_3, N_CULLINGMATRIX, &cmat[0][0], rstride,
277 setnurbsproperty(GL_MAP1_VERTEX_4, N_CULLINGMATRIX, &cmat[0][0], rstride,
286 GLUnurbs::transform4d(GLfloat A[4], GLfloat B[4], GLfloat mat[4][4])
289 A[0] = B[0]*mat[0][0] + B[1]*mat[1][0] + B[2]*mat[2][0] + B[3]*mat[3][0];
290 A[1] = B[0]*mat[0][1] + B[1]*mat[1][1] + B[2]*mat[2][1] + B[3]*mat[3][1];
291 A[2] = B[0]*mat[0][2] + B[1]*mat[1][2] + B[2]*mat[2][2] + B[3]*mat[3][2];
292 A[3] = B[0]*mat[0][3] + B[1]*mat[1][3] + B[2]*mat[2][3] + B[3]*mat[3][3];
300 GLUnurbs::multmatrix4d (GLfloat n[4][4],
const GLfloat left[4][4],
301 const GLfloat right[4][4])
303 transform4d ((GLfloat *) n[0],(GLfloat *) left[0],(GLfloat (*)[4]) right);
304 transform4d ((GLfloat *) n[1],(GLfloat *) left[1],(GLfloat (*)[4]) right);
305 transform4d ((GLfloat *) n[2],(GLfloat *) left[2],(GLfloat (*)[4]) right);
306 transform4d ((GLfloat *) n[3],(GLfloat *) left[3],(GLfloat (*)[4]) right);