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 6 7 #include "FPS.h" 8 9 10 FPS::FPS() 11 { 12 } 13 14 FPS::~FPS() 15 { 16 } 17 18 void FPS::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 38 static GLfloat gap = 0.03; 39 static GLfloat size = 1.0; 40 41 static GLfloat x0 = -size / 4; 42 static GLfloat x1 = -size / 4 + gap; 43 static GLfloat x2 = -x1; 44 static GLfloat x3 = -x0; 45 46 static GLfloat y0 = size / 2; 47 static GLfloat y1 = size / 2 - gap; 48 static GLfloat y2 = 0 + gap; 49 static GLfloat y3 = 0; 50 static GLfloat y4 = -y2; 51 static GLfloat y5 = -y1; 52 static GLfloat y6 = -y0; 53 54 glBegin( GL_LINES ); 55 if( numbers[number][0] ) 56 { 57 glVertex2f( x1 + x, y0 + y ); 58 glVertex2f( x2 + x, y0 + y ); 59 } 60 if( numbers[number][1] ) 61 { 62 glVertex2f( x3 + x, y1 + y ); 63 glVertex2f( x3 + x, y2 + y ); 64 } 65 if( numbers[number][2] ) 66 { 67 glVertex2f( x3 + x, y4 + y ); 68 glVertex2f( x3 + x, y5 + y ); 69 } 70 if( numbers[number][3] ) 71 { 72 glVertex2f( x1 + x, y6 + y ); 73 glVertex2f( x2 + x, y6 + y ); 74 } 75 if( numbers[number][4] ) 76 { 77 glVertex2f( x0 + x, y5 + y ); 78 glVertex2f( x0 + x, y4 + y ); 79 } 80 if( numbers[number][5] ) 81 { 82 glVertex2f( x0 + x, y2 + y ); 83 glVertex2f( x0 + x, y1 + y ); 84 } 85 if( numbers[number][6] ) 86 { 87 glVertex2f( x1 + x, y3 + y ); 88 glVertex2f( x2 + x, y3 + y ); 89 } 90 glEnd(); 91 92 } 93 94 void FPS::drawCounter( GLfloat frameRate ) 95 { 96 GLfloat pos = 0; 97 int ifps = (int) (frameRate * 10 +0.5); 98 int c100,c10,c1,c_1; 99 100 c100 = ifps / 1000; 101 c10 = (ifps / 100) % 10; 102 c1 = (ifps / 10) % 10; 103 c_1 = ifps % 10; 104 105 if( c100 ) 106 { 107 drawChar( pos, 0, c100 ); 108 pos += 1; 109 } 110 if( c100 || c10 ) 111 { 112 drawChar( pos, 0, c10 ); 113 pos += 1; 114 } 115 drawChar( pos, 0, c1 ); 116 pos += 0.5; 117 118 glBegin( GL_POINTS ); 119 glVertex2f( pos, -0.5 ); 120 glEnd(); 121 pos += 0.5; 122 123 drawChar( pos, 0, c_1 ); 124 pos += 1.5; 125 126 127 drawChar( pos, 0, 10 ); 128 pos += 1; 129 drawChar( pos, 0, 11 ); 130 pos += 1; 131 drawChar( pos, 0, 12 ); 132 pos += 1; 133 134 } 135 136