1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
/***********************************************************************
FONCTION :
----------
File OpenGl_text :
REMARQUES:
----------
HISTORIQUE DES MODIFICATIONS :
--------------------------------
xx-xx-xx : xxx ; Creation.
05-03-96 : FMN ; Suppression code inutile:
01-04-96 : CAL ; Integration MINSK portage WNT
29-04-96 : FMN ; correction warning de compilation.
21-10-96 : FMN ; Suppression LMC_COLOR fait dans OpenGl_execstruct.c
30-11-98 : FMN ; S4069 : Textes toujours visibles
02.14.100 : JR : Warnings on WNT truncations from double to float
21.06.03 : SAN : Suppress text display while in animation mode (TEXT_DEGENER)
22.01.04 : SAN : Implement texture mapped fonts on WNT only (OCC2934)
************************************************************************/
/*----------------------------------------------------------------------*/
/*
* Includes
*/
#ifndef WNT
#include <X11/Xlib.h>
#endif
#include <OpenGl_tgl_all.hxx>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <OpenGl_cmn_varargs.hxx>
#include <OpenGl_telem_attri.hxx>
#include <OpenGl_tsm.hxx>
#include <OpenGl_telem.hxx>
#include <OpenGl_telem_highlight.hxx>
#include <OpenGl_telem_inquire.hxx>
#include <OpenGl_tgl_funcs.hxx>
#include <OpenGl_Extension.hxx>
#include <OpenGl_Memory.hxx>
#include <OpenGl_TextRender.hxx>
struct TEL_TEXT_DATA
{
TEL_POINT attach_pt;
Tint length;
const wchar_t *sdata;
IMPLEMENT_MEMORY_OPERATORS
};
typedef TEL_TEXT_DATA* tel_text_data;
/*----------------------------------------------------------------------*/
/*
* Fonctions statiques
*/
static TStatus TextDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
static TStatus TextAdd( TSM_ELEM_DATA, Tint, cmn_key* );
static TStatus TextDelete( TSM_ELEM_DATA, Tint, cmn_key* );
static TStatus TextPrint( TSM_ELEM_DATA, Tint, cmn_key* );
static TStatus TextInquire( TSM_ELEM_DATA, Tint, cmn_key* );
#if defined(__sun) || defined (__osf__) || defined (__hp) || defined (__sgi)
#else
PFNGLBLENDEQUATIONEXTPROC glBlendEquationOp = (PFNGLBLENDEQUATIONEXTPROC) INVALID_EXT_FUNCTION_PTR;
#endif
/*----------------------------------------------------------------------*/
/*
* Constantes
*/
#if defined(__osf__) || defined (__sun) || defined (__sgi) || defined(__hp9000s700) || defined(WNT)
#undef GL_EXT_blend_logic_op
#endif
/*----------------------------------------------------------------------*/
/*
* Variables statiques
*/
/*static GLboolean lighting_mode;*/
static TStatus (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
{
TextDisplay,
TextDisplay,
TextAdd,
TextDelete,
TextPrint,
TextInquire
};
extern GLuint fontBase;
extern GLuint printerFontBase;
#define TEXT_DEGENER
#ifdef TEXT_DEGENER
extern int g_nDegenerateModel;
extern float g_fSkipRatio;
#endif
/*----------------------------------------------------------------------*/
MtblPtr
TelTextInitClass( TelType* el )
{
*el = TelText;
return MtdTbl;
}
/*----------------------------------------------------------------------*/
static TStatus
TextAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
{
Tint i;
TEL_POINT def_pt = {{ ( float )0.0, ( float )0.0, ( float )0.0 }};
tel_point pt = &def_pt;
tel_text_data data;
Techar *str= 0;
for( i = 0; i < n; i++ )
{
switch( k[i]->id )
{
case TEXT_ATTACH_PT_ID:
pt = (tel_point)k[i]->data.pdata;
break;
case TEXT_STRING_ID:
str = (Techar*)k[i]->data.pdata;
break;
}
}
data = new TEL_TEXT_DATA();
if( !data )
return TFailure;
//szv: instead of strlen + 1
i = 0; while (str[i++]);
wchar_t *wstr = new wchar_t[i];
if( !wstr )
{
delete data;
delete [] wstr;
return TFailure;
}
data->attach_pt = *pt;
data->length = i;
//szv: instead of memcpy
i = 0; while (wstr[i++] = (wchar_t)(*str++));
data->sdata = wstr;
((tsm_elem_data)(d.pdata))->pdata = data;
return TSuccess;
}
/*----------------------------------------------------------------------*/
static TStatus
TextDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
{
tel_text_data d;
CMN_KEY key, key1;
TEL_COLOUR colour, colours;
int style, display_type;
GLboolean flag_zbuffer = GL_FALSE;
GLboolean blend_state = GL_FALSE;
GLint sWidth, sAscent, sDescent;
GLdouble modelMatrix[16], projMatrix[16];
GLint viewport[4];
GLdouble objrefX, objrefY, objrefZ;
GLdouble objX, objY, objZ;
GLdouble obj1X, obj1Y, obj1Z;
GLdouble obj2X, obj2Y, obj2Z;
GLdouble obj3X, obj3Y, obj3Z;
GLdouble winx1, winy1, winz1;
GLdouble winx, winy, winz;
#ifdef TEXT_DEGENER
if ( g_nDegenerateModel > 0 && g_fSkipRatio == 1. )
return TSuccess;
#endif
d = (tel_text_data)data.pdata;
if( k[0]->id == TOn )
{ /* Use highlight colours */
TEL_HIGHLIGHT hrep;
key.id = TelHighlightIndex;
TsmGetAttri( 1, &key );
if( TelGetHighlightRep( TglActiveWs, key.data.ldata, &hrep )
== TSuccess )
colour = hrep.col;
else
{
TelGetHighlightRep( TglActiveWs, 0, &hrep );
colour = hrep.col;
}
}
else
{
key.id = TelTextColour;
key.data.pdata = &colour;
TsmGetAttri( 1, &key );
}
key.id = TelTextStyle;
key1.id = TelTextDisplayType;
TsmGetAttri( 2, &key, &key1 );
style = key.data.ldata;
display_type = key1.data.ldata;
/* style annotation */
if (style == ASPECT_TOST_ANNOTATION)
{
flag_zbuffer = glIsEnabled(GL_DEPTH_TEST);
if (flag_zbuffer) glDisable(GL_DEPTH_TEST);
}
OpenGl_TextRender* textRender=OpenGl_TextRender::instance();
/* display type of text */
if (display_type != ASPECT_TODT_NORMAL)
{
key.id = TelTextColourSubTitle;
key.data.pdata = &colours;
TsmGetAttri( 1, &key );
/* Optimisation: il faudrait ne faire le Get qu'une fois par Redraw */
glGetIntegerv (GL_VIEWPORT, viewport);
glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
switch (display_type)
{
case ASPECT_TODT_BLEND:
#if defined(GL_EXT_blend_logic_op)
if ( (PFNGLBLENDEQUATIONEXTPROC)glBlendEquationOp == (PFNGLBLENDEQUATIONEXTPROC)INVALID_EXT_FUNCTION_PTR )
{
if(QueryExtension("GL_EXT_blend_logic_op")) {
#ifdef WNT
glBlendEquationOp = (PFNGLBLENDEQUATIONEXTPROC)wglGetProcAddress("glBlendEquationOp");
#else
glBlendEquationOp = (PFNGLBLENDEQUATIONEXTPROC)glXGetProcAddress((GLubyte*)"glBlendEquationOp");
#endif
} else
glBlendEquationOp = NULL;
}
if ( glBlendEquationOp )
{
blend_state = glIsEnabled(GL_BLEND);
if (!blend_state) glEnable(GL_BLEND);
glBlendEquationOp(GL_LOGIC_OP);
glLogicOp(GL_XOR);
}
#else
blend_state = glIsEnabled(GL_BLEND);
if (!blend_state) glEnable(GL_BLEND);
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
#endif
break;
case ASPECT_TODT_SUBTITLE:
textRender->StringSize(d->sdata, &sWidth, &sAscent, &sDescent);
objrefX = (float)d->attach_pt.xyz[0];
objrefY = (float)d->attach_pt.xyz[1];
objrefZ = (float)d->attach_pt.xyz[2];
gluProject (objrefX, objrefY, objrefZ, modelMatrix, projMatrix, viewport,
&winx1, &winy1, &winz1);
winx = winx1;
winy = winy1-sDescent;
winz = winz1+0.00001;
gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
&objX, &objY, &objZ);
winx = winx1 + sWidth;
winy = winy1-sDescent;
winz = winz1+0.00001; /* il vaut mieux F+B / 1000000 ? */
gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
&obj1X, &obj1Y, &obj1Z);
winx = winx1 + sWidth;
winy = winy1 + sAscent;
winz = winz1+0.00001;
gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
&obj2X, &obj2Y, &obj2Z);
winx = winx1;
winy = winy1+ sAscent;
winz = winz1+0.00001;
gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
&obj3X, &obj3Y, &obj3Z);
glColor3fv( colours.rgb );
glBegin(GL_POLYGON);
glVertex3d(objX, objY, objZ);
glVertex3d(obj1X, obj1Y, obj1Z);
glVertex3d(obj2X, obj2Y, obj2Z);
glVertex3d(obj3X, obj3Y, obj3Z);
glEnd();
break;
case ASPECT_TODT_DEKALE:
objrefX = (float)d->attach_pt.xyz[0];
objrefY = (float)d->attach_pt.xyz[1];
objrefZ = (float)d->attach_pt.xyz[2];
gluProject (objrefX, objrefY, objrefZ, modelMatrix, projMatrix, viewport,
&winx1, &winy1, &winz1);
winx = winx1+1;
winy = winy1+1;
winz = winz1+0.00001;
gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
&objX, &objY, &objZ);
glColor3fv( colours.rgb );
textRender->RenderText( d->sdata, fontBase, 0, (float)objX, (float)objY,(float)objZ );
winx = winx1-1;
winy = winy1-1;
gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
&objX, &objY, &objZ);
textRender->RenderText( d->sdata, fontBase, 0, (float)objX, (float)objY,(float)objZ );
winx = winx1-1;
winy = winy1+1;
gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
&objX, &objY, &objZ);
textRender->RenderText( d->sdata, fontBase, 0, (float)objX, (float)objY,(float)objZ );
winx = winx1+1;
winy = winy1-1;
gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
&objX, &objY, &objZ);
textRender->RenderText( d->sdata, fontBase, 0, (float)objX, (float)objY,(float)objZ );
break;
}
}
glColor3fv( colour.rgb );
textRender->RenderText( d->sdata, fontBase, 0, (float)d->attach_pt.xyz[0], (float)d->attach_pt.xyz[1],(float)d->attach_pt.xyz[2] );
/* maj attributs */
if (flag_zbuffer) glEnable(GL_DEPTH_TEST);
if (display_type == ASPECT_TODT_BLEND)
{
#if defined(GL_EXT_blend_logic_op)
if ((!blend_state) && (QueryExtension("GL_EXT_blend_logic_op"))) glDisable(GL_BLEND);
#else
if (!blend_state) glDisable(GL_BLEND);
glDisable(GL_COLOR_LOGIC_OP);
#endif
}
return TSuccess;
}
/*----------------------------------------------------------------------*/
static TStatus
TextDelete( TSM_ELEM_DATA data, Tint n, cmn_key *k )
{
tel_text_data d = (tel_text_data)data.pdata;
if (d)
{
delete[] d->sdata;
free(d);
}
return TSuccess;
}
/*----------------------------------------------------------------------*/
static TStatus
TextPrint( TSM_ELEM_DATA data, Tint n, cmn_key *k )
{
tel_text_data p;
p = (tel_text_data)data.pdata;
fprintf( stdout, "TelText.\n" );
fprintf( stdout, "\t\tString : %S\n", p->sdata );
fprintf( stdout, "\t\tAttach Point : %f %f %f\n", p->attach_pt.xyz[0],
p->attach_pt.xyz[1],
p->attach_pt.xyz[2] );
fprintf( stdout, "\n" );
return TSuccess;
}
/*----------------------------------------------------------------------*/
static TStatus
TextInquire( TSM_ELEM_DATA data, Tint n, cmn_key *k )
{
Tint i;
tel_text_data d;
Tint size_reqd=0;
TStatus status = TSuccess;
d = (tel_text_data)data.pdata;
size_reqd = sizeof(Techar)*d->length;
for( i = 0; i < n; i++ )
{
switch( k[i]->id )
{
case INQ_GET_SIZE_ID:
{
k[i]->data.ldata = size_reqd;
break;
}
case INQ_GET_CONTENT_ID:
{
TEL_INQ_CONTENT *c;
Teldata *w;
c = (tel_inq_content)k[i]->data.pdata;
c->act_size = size_reqd;
w = c->data;
if( c->size >= size_reqd )
{
w->atext3.string = (Techar*)c->buf;
w->atext3.ref_pt = d->attach_pt;
w->atext3.anno.xyz[0] = ( float )0.0;
w->atext3.anno.xyz[1] = ( float )0.0;
w->atext3.anno.xyz[2] = ( float )0.0;
//szv: instead of strcpy
Techar *ptr1 = w->atext3.string;
const wchar_t *ptr2 = d->sdata;
while (*ptr1++ = (Techar)(*ptr2++));
status = TSuccess;
}
else
status = TFailure;
break;
}
}
}
return status;
}
/*----------------------------------------------------------------------*/
|