vfs: check userland buffers before reading them.
[haiku.git] / src / apps / glteapot / FPS.cpp
blobd578cf138eefdff742dc258fad8ef0f047cc8f4b
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"
7 FPS::FPS()
12 FPS::~FPS()
17 void
18 FPS::drawChar(GLfloat x, GLfloat y, GLint number)
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 */
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 */
37 static GLfloat gap = 0.03;
38 static GLfloat size = 1.0;
40 static GLfloat x0 = -size / 4;
41 static GLfloat x1 = -size / 4 + gap;
42 static GLfloat x2 = -x1;
43 static GLfloat x3 = -x0;
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;
53 glBegin(GL_LINES);
54 if (numbers[number][0]) {
55 glVertex2f(x1 + x, y0 + y);
56 glVertex2f(x2 + x, y0 + y);
59 if (numbers[number][1]) {
60 glVertex2f(x3 + x, y1 + y);
61 glVertex2f(x3 + x, y2 + y);
64 if (numbers[number][2]) {
65 glVertex2f(x3 + x, y4 + y);
66 glVertex2f(x3 + x, y5 + y);
69 if (numbers[number][3]) {
70 glVertex2f(x1 + x, y6 + y);
71 glVertex2f(x2 + x, y6 + y);
74 if (numbers[number][4]) {
75 glVertex2f(x0 + x, y5 + y);
76 glVertex2f(x0 + x, y4 + y);
79 if (numbers[number][5]) {
80 glVertex2f(x0 + x, y2 + y);
81 glVertex2f(x0 + x, y1 + y);
84 if (numbers[number][6]) {
85 glVertex2f(x1 + x, y3 + y);
86 glVertex2f(x2 + x, y3 + y);
89 glEnd();
93 void
94 FPS::drawCounter(GLfloat frameRate)
96 GLfloat pos = 0;
97 int ifps = (int)frameRate;
99 int count = 0;
100 int number = 1;
101 while (ifps > number) {
102 number *= 10;
103 count++;
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;
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;