-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.c
97 lines (77 loc) · 2.43 KB
/
text.c
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
#include "bitmap.c"
#define red glColor3f(0.9, 0.1, 0.1)
#define green glColor3f(0.1, 0.9, 0.1)
#define blue glColor3f(0.1, 0.1, 0.9)
void makeBitmapFonts(void){
// ########################
// Create the bitmap fonts.
// ########################
GLint i;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
fontOffset = glGenLists(128);
for (i = 32; i < 127; i++) {
glNewList(i+fontOffset, GL_COMPILE);
glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, bitmap_font[i-32]);
glEndList();
};
};
void printString(char *s){
// #############################################################
// Prints a string using bitmap fonts at current raster location
// #############################################################
glPushAttrib (GL_LIST_BIT);
glListBase(fontOffset);
glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *) s);
glPopAttrib();
};
int line_pos(int lines){
int margin = 6;
return (lines*13)+margin;
}
void left_align_text(int pos, char *charlies){
glRasterPos2f(6 ,line_pos(pos)); printString(charlies);
}
void right_align_text(int pos, char *charlies){
int index = 0;
for(index = 0; charlies[index] != 0; index++);
int text_width = index * 10;
int xpos = window_width - text_width;
glRasterPos2f(xpos - 6 ,line_pos(pos)); printString(charlies);
}
void centre_align_text(int pos, char *charlies){
int index = 0;
for(index = 0; charlies[index] != 0; index++);
int text_width = index * 10;
int xpos = (window_width/2) - (text_width/2);
glRasterPos2f(xpos ,line_pos(pos)); printString(charlies);
}
char * make_text(int number_int){
memset(sprinter, 0, sizeof(sprinter));
sprintf(sprinter, "%d", number_int);
return sprinter;
}
void draw_text_layers(void) {
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,window_width,0,window_height,0,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glColor3f(0.2, 0.9, 0.2);
left_align_text(0, "Conveyor belt Simulator");
glColor3f(1, 0, 0);
right_align_text(0, "HONEYWELL");
int current_line_height = 40;
char text_str[50];
memset(text_str, 0, sizeof(text_str));
current_line_height = 15;
glColor3f(0.8, 0.8, 0.8);
right_align_text(current_line_height--, "[W,A,S,D] to orbit");
right_align_text(current_line_height--, "[Q,E] to zoom");
right_align_text(current_line_height--, "[Z,X] to change vertical orbit position");
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
};