1/*
2	Copyright 1999, Be Incorporated.   All Rights Reserved.
3	This file may be used under the terms of the Be Sample Code License.
4*/
5#include "FPS.h"
6
7FPS::FPS()
8{
9}
10
11
12FPS::~FPS()
13{
14}
15
16
17void
18FPS::drawChar(GLfloat x, GLfloat y, GLint number)
19{
20	static bool numbers[13][7] = {
21		{ true, true, true, true, true, true, false }, 		/* 0 */
22		{ false, true, true, false, false, false, false },	/* 1 */
23		{ true, true, false, true, true, false, true },		/* 2 */
24		{ true, true, true, true, false, false, true },		/* 3 */
25		{ false, true, true, false, false, true, true },	/* 4 */
26		{ true, false, true, true, false, true, true },		/* 5 */
27		{ true, false, true, true, true, true, true },		/* 6 */
28		{ true, true, true, false, false, false, false },	/* 7 */
29		{ true, true, true, true, true, true, true },		/* 8 */
30		{ true, true, true, false, false, true, true },		/* 9 */
31
32		{ true, false, false, false, true, true, true },	/* F */
33		{ true, true, false, false, true, true, true },		/* P */
34		{ true, false, true, true, false, true, true },		/* S */
35	};
36
37	static GLfloat gap = 0.03;
38	static GLfloat size = 1.0;
39
40	static GLfloat x0 = -size / 4;
41	static GLfloat x1 = -size / 4 + gap;
42	static GLfloat x2 = -x1;
43	static GLfloat x3 = -x0;
44
45	static GLfloat y0 = size / 2;
46	static GLfloat y1 = size / 2 - gap;
47	static GLfloat y2 = 0 + gap;
48	static GLfloat y3 = 0;
49	static GLfloat y4 = -y2;
50	static GLfloat y5 = -y1;
51	static GLfloat y6 = -y0;
52
53	glBegin(GL_LINES);
54	if (numbers[number][0]) {
55		glVertex2f(x1 + x, y0 + y);
56		glVertex2f(x2 + x, y0 + y);
57	}
58
59	if (numbers[number][1]) {
60		glVertex2f(x3 + x, y1 + y);
61		glVertex2f(x3 + x, y2 + y);
62	}
63
64	if (numbers[number][2]) {
65		glVertex2f(x3 + x, y4 + y);
66		glVertex2f(x3 + x, y5 + y);
67	}
68
69	if (numbers[number][3]) {
70		glVertex2f(x1 + x, y6 + y);
71		glVertex2f(x2 + x, y6 + y);
72	}
73
74	if (numbers[number][4]) {
75		glVertex2f(x0 + x, y5 + y);
76		glVertex2f(x0 + x, y4 + y);
77	}
78
79	if (numbers[number][5]) {
80		glVertex2f(x0 + x, y2 + y);
81		glVertex2f(x0 + x, y1 + y);
82	}
83
84	if (numbers[number][6]) {
85		glVertex2f(x1 + x, y3 + y);
86		glVertex2f(x2 + x, y3 + y);
87	}
88
89	glEnd();
90}
91
92
93void
94FPS::drawCounter(GLfloat frameRate)
95{
96	GLfloat pos = 0;
97	int ifps = (int)frameRate;
98
99	int count = 0;
100	int number = 1;
101	while (ifps > number) {
102		number *= 10;
103		count++;
104	}
105
106	number /= 10;
107	for (int i = 0; i < count; i++) {
108		drawChar(pos, 0, (ifps / number) % 10);
109		pos += 1.0;
110		if (number == 1)
111			break;
112		number /= 10;
113	}
114
115	pos += 0.5;
116	drawChar(pos, 0, 10);
117	pos += 1;
118	drawChar(pos, 0, 11);
119	pos += 1;
120	drawChar(pos, 0, 12);
121	pos += 1;
122}
123