-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.cpp
96 lines (76 loc) · 2.12 KB
/
text.cpp
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
/***********************************************
* $author: javery
* $date : 06 jun 02
* $descp : routines to support openGL scalable
* system fonts.
* $path : C:\Program Files\Microsoft Visual Studio\MyProjects\KaosDemoEngine\text.cpp
* $ver : 0.0.0
***********************************************/
#include "text.h"
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#include <stdarg.h>
#include <stdio.h>
static int glDispListInx=0;
static GLYPHMETRICSFLOAT gmFloats[ 256 ];
HFONT Txt_wglBuildFont( char* fontName , int scale , int paramA , int paramB , HDC hDC )
{
HFONT hFont;
// alloc space for the fonts display list.
glDispListInx = glGenLists( 256 );
// create font using gdi function.
hFont = CreateFont( -scale ,
0 ,
0 ,
0 ,
FW_BOLD ,
k_false ,
k_false ,
k_false ,
ANSI_CHARSET ,
OUT_TT_PRECIS ,
CLIP_DEFAULT_PRECIS ,
ANTIALIASED_QUALITY ,
FF_DONTCARE | DEFAULT_PITCH ,
fontName );
if( hFont==NULL )
{
MessageBox( NULL , "Unable to create the specified font" , "Txt_wglCreateFont fault" , MB_OK | MB_ICONEXCLAMATION );
PostQuitMessage(0);
}
SelectObject( hDC , hFont );
wglUseFontOutlines( hDC ,
0 ,
255 ,
glDispListInx,
0.0f ,
0.2f ,
WGL_FONT_POLYGONS ,
gmFloats );
return hFont;
}
int Txt_wglPrint( char* string, float xPos , float yPos , float zPos )
{
float length=0;
char text[256];
va_list ap;
if (string == NULL)
return -1;
va_start(ap, string );
vsprintf(text, string, ap);
va_end(ap);
for (unsigned int loop=0;loop<(strlen(text));loop++) // Loop To Find Text Length
{
length+=gmFloats[text[loop]].gmfCellIncX; // Increase Length By Each Characters Width
}
glPushMatrix();
glTranslatef( xPos , yPos , zPos );
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(glDispListInx); //
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib();
glPopMatrix();
return loop;
}