-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFontEngine.cpp
More file actions
112 lines (91 loc) · 2.03 KB
/
FontEngine.cpp
File metadata and controls
112 lines (91 loc) · 2.03 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
using namespace std;
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
/**
class FontEngine{
char* line;
void* font;
public :
FontEngine(char* newLine):line(newLine)
{
// OpenGL init
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
};
void setFont(void* newFont);
void renderBitmapString(float x,
float y,
float z,
void *font);
void renderStrokeFontString(
float x,
float y,
float z,
void *font);
};
void FontEngine::renderBitmapString(
float x,
float y,
float z,
void *font) {
char *c;
glRasterPos3f(x, y,z);
for (c=line; *c != '\0'; c++) {
glutBitmapCharacter(font, *c);
}
}
void FontEngine::renderStrokeFontString(
float x,
float y,
float z,
void *font) {
char *c;
glPushMatrix();
glTranslatef(x, y,z);
glScalef(0.02f, 0.02f, 0.02f);
for (c=line; *c != '\0'; c++) {
glutStrokeCharacter(font, *c);
}
glPopMatrix();
}
void renderScene2() {
//Clear information from last draw
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
glLoadIdentity(); //Reset the drawing perspective
FontEngine newFont("Prashaan");
//newFont.renderBitmapString(5,30,0,GLUT_BITMAP_HELVETICA_18);
newFont.renderStrokeFontString(5,30,1,GLUT_STROKE_MONO_ROMAN);
glutSwapBuffers(); //Send the 3D scene to the screen
glFlush();
}
void reshape(int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc,char** argv)
{
// init GLUT and create window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(800,600);
glutCreateWindow("Font Engine");
glutReshapeFunc(reshape);
glutDisplayFunc(renderScene2);
// enter GLUT event processing cycle
glutMainLoop();
return 0;
}**/