1 | /********************************************************************************
|
---|
2 | * Volatile - Volume Visualization Software for SAGE
|
---|
3 | * Copyright (C) 2004 Electronic Visualization Laboratory,
|
---|
4 | * University of Illinois at Chicago
|
---|
5 | *
|
---|
6 | * All rights reserved.
|
---|
7 | *
|
---|
8 | * Redistribution and use in source and binary forms, with or without
|
---|
9 | * modification, are permitted provided that the following conditions are met:
|
---|
10 | *
|
---|
11 | * * Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | * * Redistributions in binary form must reproduce the above
|
---|
14 | * copyright notice, this list of conditions and the following disclaimer
|
---|
15 | * in the documentation and/or other materials provided with the distribution.
|
---|
16 | * * Neither the name of the University of Illinois at Chicago nor
|
---|
17 | * the names of its contributors may be used to endorse or promote
|
---|
18 | * products derived from this software without specific prior written permission.
|
---|
19 | *
|
---|
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
---|
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
---|
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
---|
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
31 | *
|
---|
32 | * Direct questions, comments etc about Volatile to www.evl.uic.edu/cavern/forum
|
---|
33 | *********************************************************************************/
|
---|
34 |
|
---|
35 | #include <stdio.h>
|
---|
36 | #include "vFPSText.h"
|
---|
37 | #include "global.h"
|
---|
38 | GLvoid
|
---|
39 | renderBitmapString( char *string )
|
---|
40 | {
|
---|
41 | int i;
|
---|
42 | int len = (int) strlen(string);
|
---|
43 | for (i = 0; i < len; i++) {
|
---|
44 | glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, string[i]);
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | GLvoid
|
---|
49 | renderStrokeString( void *font, char *string )
|
---|
50 | {
|
---|
51 | int i;
|
---|
52 | int len = (int) strlen(string);
|
---|
53 | for (i = 0; i < len; i++) {
|
---|
54 | glutStrokeCharacter(font, string[i]);
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | CFrameTimer::CFrameTimer() {
|
---|
59 | #ifdef WIN32
|
---|
60 | LARGE_INTEGER num;
|
---|
61 | //get current performance-counter frequency, in counts per second
|
---|
62 | QueryPerformanceFrequency(&num);
|
---|
63 | timerResolution = (double)num.HighPart*4294967296.0;
|
---|
64 | timerResolution += (double)num.LowPart;
|
---|
65 | timerResolution=1.0/timerResolution; //get time for 1 count
|
---|
66 | QueryPerformanceCounter(&last); //store current counter as last
|
---|
67 |
|
---|
68 | #endif
|
---|
69 |
|
---|
70 | #if defined(linux) || defined(__APPLE__)
|
---|
71 | //struct timeval _tstart;
|
---|
72 | //struct timezone tz;
|
---|
73 | gettimeofday(&_tstart, &tz);
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | elapsedTime=0.0;
|
---|
77 | frameLocation=0;
|
---|
78 | framesProcessed=0;
|
---|
79 |
|
---|
80 | }
|
---|
81 |
|
---|
82 | void CFrameTimer::pingFrameCounter(){
|
---|
83 | #ifdef WIN32
|
---|
84 | LARGE_INTEGER t;
|
---|
85 | double elapsed;
|
---|
86 |
|
---|
87 | QueryPerformanceCounter(&t); //get current counter
|
---|
88 | //get elapsed = current counter - last counter
|
---|
89 | elapsed=((double)t.HighPart-(double)last.HighPart)*4294967296.0;
|
---|
90 | elapsed+=(double)t.LowPart-(double)last.LowPart;
|
---|
91 | elapsed *= timerResolution;
|
---|
92 | //update last counter
|
---|
93 | last.HighPart=t.HighPart;
|
---|
94 | last.LowPart=t.LowPart;
|
---|
95 | #endif
|
---|
96 |
|
---|
97 | #if defined(linux) || defined(__APPLE__)
|
---|
98 | struct timeval _tend;
|
---|
99 | gettimeofday(&_tend,&tz);
|
---|
100 | double t1, t2;
|
---|
101 | t1 = (double)_tstart.tv_sec + (double)_tstart.tv_usec/(1000*1000);
|
---|
102 | t2 = (double)_tend.tv_sec + (double)_tend.tv_usec/(1000*1000);
|
---|
103 | //return t2-t1;
|
---|
104 | double elapsed;
|
---|
105 | elapsed = t2 - t1;
|
---|
106 | _tstart = _tend;
|
---|
107 | #endif
|
---|
108 |
|
---|
109 | frameTimes[frameLocation]= elapsed; //store elapsed
|
---|
110 | elapsedTime += frameTimes[frameLocation]; //add to the total elapsed time
|
---|
111 | frameLocation = (frameLocation+1)%FRAME_HISTORY; //next index
|
---|
112 | framesProcessed++;
|
---|
113 | }
|
---|
114 |
|
---|
115 | float CFrameTimer::getFPS(){
|
---|
116 | int top=(FRAME_HISTORY>framesProcessed)?framesProcessed:FRAME_HISTORY;
|
---|
117 |
|
---|
118 | double total=0.0f;
|
---|
119 | for(int ii=0;ii<top;ii++)
|
---|
120 | total+=frameTimes[ii];
|
---|
121 | total/=(float)FRAME_HISTORY; //no of secs per frame
|
---|
122 | total=1.0f/total; //get fps
|
---|
123 | return (float)total;
|
---|
124 | }
|
---|
125 |
|
---|
126 | vText::vText(const char* txt) : vPrimitive() {
|
---|
127 | strcpy(myText,txt);
|
---|
128 | }
|
---|
129 |
|
---|
130 | void vText::init() {
|
---|
131 | }
|
---|
132 |
|
---|
133 | void vText::draw() {
|
---|
134 | glPushMatrix();
|
---|
135 | glRasterPos3f(xform.trans[0],xform.trans[1],xform.trans[2]);
|
---|
136 | if (selected)
|
---|
137 | glColor3f(0.0f,0.5f,0.5f);
|
---|
138 | else
|
---|
139 | glColor3f(1.0f,1.0f,1.0f);
|
---|
140 | //glScalef(xform.scale,xform.scale,xform.scale);
|
---|
141 | //glScalef(0.5, 0.5, 0.5);
|
---|
142 | //renderStrokeString(myText);
|
---|
143 | renderBitmapString(myText);
|
---|
144 | glPopMatrix();
|
---|
145 | }
|
---|
146 |
|
---|
147 | void vFPSText::init() {
|
---|
148 | xform.trans[0] = -6.0f;
|
---|
149 | xform.trans[1] = -5.0f;
|
---|
150 | xform.trans[2] = 0.0f;
|
---|
151 | vText::init();
|
---|
152 | timer = new CFrameTimer();
|
---|
153 | }
|
---|
154 |
|
---|
155 | void vFPSText::draw() {
|
---|
156 | timer->pingFrameCounter();
|
---|
157 | if (global.ui.printFPS) {
|
---|
158 | sprintf(myText,"FPS %f",timer->getFPS());
|
---|
159 | vText::draw();
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | void vVolText::init() {
|
---|
164 | xform.trans[0] = 1.0f;
|
---|
165 | xform.trans[1] = -3.0f;
|
---|
166 | xform.trans[2] = 0.0f;
|
---|
167 | vText::init();
|
---|
168 | }
|
---|
169 |
|
---|
170 | void vVolText::draw() {
|
---|
171 | sprintf(myText,"(X,Y,Z):(%d,%d,%d) Vox:%d",global.volume->probeX, global.volume->probeY,
|
---|
172 | global.volume->probeZ, global.volume->probeValue);
|
---|
173 | vText::draw();
|
---|
174 | }
|
---|