Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/post/src/teksti.c
3196 views
1
#include "elmerpost.h"
2
3
#include <stdio.h>
4
#include <math.h>
5
6
7
#include <GL/gl.h>
8
#include <GL/glu.h>
9
10
11
#include "tcl.h"
12
13
#include <X11/Xlib.h>
14
#include <X11/Xutil.h>
15
16
extern void (*user_hook_before_all)();
17
18
static unsigned int FontBase;
19
static double x,y,z,size;
20
static char text[132];
21
22
void jooMakeRasterFont( char *name )
23
{
24
unsigned int first, last;
25
26
XFontStruct *fontInfo;
27
28
int n,i;
29
static char str[32], here = 0;
30
31
char **FontNames;
32
void glXUseXFont();
33
34
fontInfo = XLoadQueryFont( auxXDisplay(),name );
35
if ( fontInfo == NULL )
36
{
37
fprintf( stderr, "Can't find font: [%s]\n", name );
38
return;
39
}
40
41
first = fontInfo->min_char_or_byte2;
42
last = fontInfo->max_char_or_byte2;
43
44
FontBase = glGenLists( last + 1 );
45
glXUseXFont( fontInfo->fid,first,last-first+1,FontBase+first );
46
}
47
48
void jooPrintString( char *s )
49
{
50
glDisable( GL_LIGHTING );
51
glDisable( GL_TEXTURE_1D );
52
glPushAttrib( GL_LIST_BIT );
53
glListBase( FontBase );
54
glCallLists( strlen(s),GL_UNSIGNED_BYTE,(unsigned char *)s);
55
glPopAttrib();
56
glEnable( GL_TEXTURE_1D );
57
glEnable( GL_LIGHTING );
58
}
59
60
void jooShowString( char *font,char *str,float x,float y,float z )
61
{
62
static int been_here = 0;
63
64
glMatrixMode( GL_MODELVIEW );
65
glPushMatrix();
66
glLoadIdentity();
67
68
glMatrixMode( GL_PROJECTION );
69
glPushMatrix();
70
glLoadIdentity();
71
72
/*
73
glDisable( GL_TEXTURE_1D );
74
glDisable( GL_DEPTH_TEST );
75
glDrawBuffer( GL_FRONT_AND_BACK );
76
*/
77
78
glColor3f( 0.0,0.0,0.0 );
79
glRasterPos3f( x,y,z );
80
81
if ( !been_here )
82
{
83
jooMakeRasterFont( font );
84
been_here = 1;
85
}
86
jooPrintString( str );
87
88
glPopMatrix();
89
90
glMatrixMode( GL_MODELVIEW );
91
glPopMatrix();
92
}
93
94
void jooDoit()
95
{
96
97
char str[132];
98
99
sprintf(str,"-adobe-helvetica-bold-r-normal--%g--100-100-p-88-iso8859-1",size);
100
jooShowString(str,text,x,y,z);
101
102
}
103
104
static int Teksti( ClientData cl,Tcl_Interp *interp,int argc,char **argv )
105
{
106
extern double br,bg,bb;
107
108
user_hook_before_all = jooDoit;
109
110
x = atof(argv[1]);
111
y = atof(argv[2]);
112
z = atof(argv[3]);
113
114
strcpy(text,argv[4]);
115
116
size = atof(argv[5]);
117
118
return TCL_OK;
119
}
120
121
int Teksti_Init( Tcl_Interp *interp )
122
{
123
Tcl_CreateCommand( interp,"teksti",(void *)Teksti,(ClientData)NULL,(Tcl_CmdDeleteProc *)NULL);
124
125
return TCL_OK;
126
}
127
128