frames per second??? having problems with code from an earlier post

Started by
6 comments, last by th032 23 years, 7 months ago
I got this code from an earlier post on how to do frames per second, but when I put in into my code I get a link error. "error LNK2001: unresolved external symbol __imp__timeGetTime@0" Is there header file or library that I should be including with this code in my project??? Thanks Tom ---------------------------------- #define FPS_INTERVAL 50 DWORD timePrev. timeFPS; WORD FPS, FPSCounter; float timeElapsed; void InitTimer() { FPSCounter = FPS = 0; timePrev = timeFPS = timeGetTime(); } /* La seguente funzione deve essere richiamata AD OGNI CICLO di rendering per il corretto calcolo degli FPS */ void TickTimer() { timeElapsed = (timeGetTime() - timePrev) / 1000.0f; timePrev = timeGetTime(); if(FPSCounter == FPS_INTERVAL) { FPS = (WORD)((FRAME_INTERVAL * 1000) / (timePrev - timeFPS)); FPSCounter = 0; } else FPSCounter++; }
AMD Tbird 1GHz 266FSB, ASUS A7V133, Crucial 768MB PC133 SDRAM, PlexWriter 12X/10X/32X CD-RW, Voodoo3 2000 PCI, Creative SoundBlaster Live!, Maxtor 7200rpm 13.3GB, IBM 5200rpm 3.2GB, Samsung 955DF 19" Monitor, LinkSys USB100TX Ethernet Network Adapter,Rogers@Home, Win2000/Linux Mandrake 8.0
Advertisement
timeGetTime() is declared in Mmsystem.h


random-nomad

[still searching]
k, I got rid of the link error and the program runs but I don''t think its producing the correct framerate. It starts at 5 and eventually goes down to 1, never goes up in frame rate even when I change it to a view where it doesn''t draw anything(it really looks like I''m getting something like +40fps).

I think though that I may be making a mistake in the printing of the FPS, so I''m not sure if thats whats messing it up. I using Bitmap fonts from Tut13 and here is the command "glPrint("FPS - %f", (float)FPS);", I wasn''t sure what character to use for the WORD type for the function so I converted it to a float, don''t know if maybe this is the reason it gives me the wrong framerate but I doubt it. So what is the problem???

I did try modifying the code myself, and I get around 35fps(seems a little low) but I''m just not sure if I did it correct cause when I change it here to a view where it doesn''t draw anything I''m gettting around 40fps(thats just too low).

If u guys could look over my modified code and give me any suggestions, I would greatly appreciated!

Here''s my new modified code:
---------------------------------------------
DWORD timePrev;
WORD FPScounter;
float FPS, timeElapsed;

/////////////////////////////
// Initialize timer variables
void InitTimer()
{
FPScounter = 0; timeElapsed = FPS = 0.0f;
timePrev = timeGetTime();
}


/////////////////////////////
// Calculate frames per second
void TickTimer()
{
FPScounter++;
timeElapsed += (timeGetTime() - timePrev) / 1000.0f;
timePrev = timeGetTime();
FPS = FPScounter / timeElapsed;
}

I call InitTimer in InitGL(), and TickTimer() in DrawGLScene() before anything else is done.
AMD Tbird 1GHz 266FSB, ASUS A7V133, Crucial 768MB PC133 SDRAM, PlexWriter 12X/10X/32X CD-RW, Voodoo3 2000 PCI, Creative SoundBlaster Live!, Maxtor 7200rpm 13.3GB, IBM 5200rpm 3.2GB, Samsung 955DF 19" Monitor, LinkSys USB100TX Ethernet Network Adapter,Rogers@Home, Win2000/Linux Mandrake 8.0
k, I got rid of the link error and the program runs but I don''t think its producing the correct framerate. It starts at 5 and eventually goes down to 1, never goes up in frame rate even when I change it to a view where it doesn''t draw anything(it really looks like I''m getting something like +40fps).

I think though that I may be making a mistake in the printing of the FPS, so I''m not sure if thats whats messing it up. I using Bitmap fonts from Tut13 and here is the command "glPrint("FPS - %f", (float)FPS);", I wasn''t sure what character to use for the WORD type for the function so I converted it to a float, don''t know if maybe this is the reason it gives me the wrong framerate but I doubt it. So what is the problem???

I did try modifying the code myself, and I get around 35fps(seems a little low) but I''m just not sure if I did it correct cause when I change it here to a view where it doesn''t draw anything I''m gettting around 40fps(thats just too low).

If u guys could look over my modified code and give me any suggestions, I would greatly appreciated!

Here''s my new modified code:
---------------------------------------------
DWORD timePrev;
WORD FPScounter;
float FPS, timeElapsed;

/////////////////////////////
// Initialize timer variables
void InitTimer()
{
FPScounter = 0; timeElapsed = FPS = 0.0f;
timePrev = timeGetTime();
}


/////////////////////////////
// Calculate frames per second
void TickTimer()
{
FPScounter++;
timeElapsed += (timeGetTime() - timePrev) / 1000.0f;
timePrev = timeGetTime();
FPS = FPScounter / timeElapsed;
}

I call InitTimer in InitGL(), and TickTimer() in DrawGLScene() before anything else is done.
AMD Tbird 1GHz 266FSB, ASUS A7V133, Crucial 768MB PC133 SDRAM, PlexWriter 12X/10X/32X CD-RW, Voodoo3 2000 PCI, Creative SoundBlaster Live!, Maxtor 7200rpm 13.3GB, IBM 5200rpm 3.2GB, Samsung 955DF 19" Monitor, LinkSys USB100TX Ethernet Network Adapter,Rogers@Home, Win2000/Linux Mandrake 8.0
An easier way to do FPS is like this.

#include

#define EXPECTED_FPS 24 // use your best judgement here,
// but it doesn''t matter too much.

double fps_avg = EXPECTED_FPS, fps;
clock_t timeprev, timenow;

timeprev = clock() - EXPECTED_FPS;

while (!done) {
// Do your dawing
timenow = clock();
fps = 1000.0 / (double)(timenow - timeprev);
avg_fps = (avg_fps + fps) / 2.0; // this isn''t a *true*
// average, but it''s actually better, because it puts
// more weight on the most recent frame times
timeprev = timenow;
}

// now avg_fps should be your average frame rate
oops, include above should be
#include <time.h>
<font face="comix" size="30" color="#ff0000>#include




<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive 4">
blink-182
















<script><!--
CSStopExecution = false;
CSInit = new Array;
function CSScriptInit() {
if(typeof(skipPage) != "undefined") { if(skipPage) return; }
idxArray = new Array;
for(var i=0;i idxArray = i;
CSAction2(CSInit, idxArray);
}
function CSClickReturn () {
var bAgent = window.navigator.userAgent;
var bAppName = window.navigator.appName;
if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))
return true; // dont follow link
else return false; // dont follow link
}
CSAg = window.navigator.userAgent; CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);
function IsIE() { return CSAg.indexOf("MSIE") > 0;}
function CSIEStyl(s) { return document.all.tags("div").style; }<br>function CSNSStyl(s) { return CSFindElement(s,0); }<br>function CSFindElement(n,ly) { if (CSBVers < 4) return document[n];<br> var curDoc = ly ? ly.document : document; var elem = curDoc[n];<br> if (!elem) { for (var i=0;i<curDoc.layers.length;i++) {<br> elem = CSFindElement(n,curDoc.layers); if (elem) return elem; }}<br> return elem;<br>}<br>function CSButtonReturn () {<br> var bAgent = window.navigator.userAgent; <br> var bAppName = window.navigator.appName;<br> if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))<br> return false; // follow link<br> else return true; // follow link<br>}<br>CSIm = new Object();<br>function CSIShow(n,i) {<br> if (document.images) {<br> if (CSIm[n]) {<br> var img = (!IsIE()) ? CSFindElement(n,0) : document[n];<br> if (img && typeof(CSIm[n].src) != "undefined") {img.src = CSIm[n].src;}<br> if(i != 0)<br> self.status = CSIm[n][3];<br> else<br> self.status = " ";<br> return true;<br> }<br> }<br> return false;<br>}<br>function CSILoad(action) {<br> im = action[1];<br> if (document.images) {<br> CSIm[im] = new Object();<br> for (var i=2;i<5;i++) {<br> if (action != '''') { CSIm[im][i-2] = new Image(); CSIm[im][i-2].src = action; }<br> else CSIm[im][i-2] = 0;<br> }<br> CSIm[im][3] = action[5];<br> }<br>}<br>CSStopExecution = false;<br><br>function CSAction(array) { <br> return CSAction2(CSAct, array);<br>}<br>function CSAction2(fct, array) { <br> var result;<br> for (var i=0;i<array.length;i++) {<br> if(CSStopExecution) return false; <br> var actArray = fct[array];<br> if(actArray == null) return false; <br><br> var tempArray = new Array;<br> for(var j=1;j<actArray.length;j++) {<br> if((actArray[j] != null) && (typeof(actArray[j]) == "object") && (actArray[j].length == 2)) {<br> if(actArray[j][0] == "VAR") {<br> tempArray[j] = CSStateArray[actArray[j][1]];<br> }<br> else {<br> if(actArray[j][0] == "ACT") {<br> tempArray[j] = CSAction(new Array(new String(actArray[j][1])));<br> }<br> else<br> tempArray[j] = actArray[j];<br> }<br> }<br> else<br> tempArray[j] = actArray[j];<br> } <br> result = actArray[0](tempArray);<br> }<br> return result;<br>}<br>CSAct = new Object;<br>function CSSetImageURL(action) {<br> var img = null;<br> if (document.images) {<br> if (!IsIE()) img = CSFindElement(action[1],0);<br> else img = document.images[action[1]];<br> if (img) img.src = action[2];<br> }<br>}<br>// –&gt;&lt;/script><br></csscriptdict> <csactiondict> <br>&lt;script><br>&lt;!–<br>&lt;!–<br>CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''TheGuysIcon'',/*URL*/''img/rollo_guys.gif'',/*URL*/''img/rollo_guys-on.gif'',/*URL*/'''','''');<br>CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''TheGirlsIcon'',/*URL*/''img/rollo_girl.gif'',/*URL*/''img/rollo_girl-on.gif'',/*URL*/'''','''');<br>CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''TheClinicIcon'',/*URL*/''img/rollo_clinic.gif'',/*URL*/''img/rollo_clinic-on.gif'',/*URL*/'''','''');<br>CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''TRL_Button'',/*URL*/''img/button_TRL.gif'',/*URL*/'''',/*URL*/'''','''');<br>CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''Roids_Button'',/*URL*/''img/button_roids.gif'',/*URL*/'''',/*URL*/'''','''');<br>CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''Tour_Button'',/*URL*/''img/button_tour.gif'',/*URL*/'''',/*URL*/'''','''');<br>CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''TheBigPicture'',/*URL*/''img/TBP-girl.jpg'',/*URL*/'''',/*URL*/'''','''');<br>CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''LoserKids_Button'',/*URL*/''img/button_loserkids.gif'',/*URL*/'''',/*URL*/'''','''');<br>CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''BlinkTV_Button'',/*URL*/''img/button_blink-tv.gif'',/*URL*/'''',/*URL*/'''','''');<br>CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''Fenix-TX_Button'',/*URL*/''img/button_fenix-tx.gif'',/*URL*/'''',/*URL*/'''','''');<br>CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''TextBox'',/*URL*/''img/text_generic.gif'',/*URL*/'''',/*URL*/'''','''');<br>CSAct[/*CMP*/ ''B430044A0''] = new Array(CSSetImageURL,/*CMP*/ ''TheBigPicture'',/*URL*/ ''img/TBP-guys.jpg'');<br>CSAct[/*CMP*/ ''B430047C2''] = new Array(CSSetImageURL,/*CMP*/ ''TheBigPicture'',/*URL*/ ''img/TBP-girl.jpg'');<br>CSAct[/*CMP*/ ''B430049C4''] = new Array(CSSetImageURL,/*CMP*/ ''TheBigPicture'',/*URL*/ ''img/TBP-clinic.jpg'');<br>CSAct[/*CMP*/ ''B430059D7''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_TRL.gif'');<br>CSAct[/*CMP*/ ''B43005A88''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_generic.gif'');<br>CSAct[/*CMP*/ ''B43005BF9''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_roids.gif'');<br>CSAct[/*CMP*/ ''B43005CE10''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_generic.gif'');<br>CSAct[/*CMP*/ ''B43005D911''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_tour.gif'');<br>CSAct[/*CMP*/ ''B43005E612''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_generic.gif'');<br>CSAct[/*CMP*/ ''B43005F113''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_loserkids.gif'');<br>CSAct[/*CMP*/ ''B43005FF14''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_generic.gif'');<br>CSAct[/*CMP*/ ''B430060A15''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_blink-tv.gif'');<br>CSAct[/*CMP*/ ''B430061516''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_generic.gif'');<br>CSAct[/*CMP*/ ''B430062017''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_fenix-tx.gif'');<br>CSAct[/*CMP*/ ''B430063018''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_generic.gif'');<br><br>// –&gt;<br><br>function MM_openBrWindow(theURL,winName,features) { //v2.0<br> window.open(theURL,winName,features);<br>}<br>//–&gt;<br>&lt;/script><br></csactiondict> <br>&lt;style type="text/css"><br>&lt;!–<br>p { font-size: 11px; margin: 8px 0px}<br>–&gt;<br></style><br></head><br><br> <body bgcolor="white" link="black" alink="black" vlink="black" onload="CSScriptInit();"><br> <center><br> <span class="10pixel"></span> <br> &lt;table cool width="603" height="314" border="0" cellpadding="0" cellspacing="0" gridx="1" showgridx usegridx gridy="1" showgridy usegridy><br> &lt;tr height="1" cntrlrow> <br> &lt;td width="1" height="1">&lt;/td><br> &lt;td width="19" height="1"><spacer type="block" width="19" height="1">&lt;/td><br> &lt;td width="66" height="1"><spacer type="block" width="66" height="1">&lt;/td><br> &lt;td width="32" height="1"><spacer type="block" width="32" height="1">&lt;/td><br> &lt;td width="66" height="1"><spacer type="block" width="66" height="1">&lt;/td><br> &lt;td width="29" height="1"><spacer type="block" width="29" height="1">&lt;/td><br> &lt;td width="66" height="1"><spacer type="block" width="66" height="1">&lt;/td><br> &lt;td width="25" height="1"><spacer type="block" width="25" height="1">&lt;/td><br> &lt;td width="24" height="1"><spacer type="block" width="24" height="1">&lt;/td><br> &lt;td width="18" height="1"><spacer type="block" width="18" height="1">&lt;/td><br> &lt;td width="21" height="1"><spacer type="block" width="21" height="1">&lt;/td><br> &lt;td width="236" height="1"><spacer type="block" width="236" height="1">&lt;/td><br> &lt;/tr><br> &lt;tr height="19"> <br> &lt;td width="1" height="19"><spacer type="block" width="1" height="19">&lt;/td><br> &lt;td width="303" height="19" colspan="7" rowspan="1" valign="top" align="left" xpos="0"><img height="19" width="303" src="img/b_182-main_01.gif">&lt;/td><br> &lt;td width="24" height="19" colspan="1" rowspan="1" valign="top" align="left" xpos="303"><csobj w="24" h="19" t="Button" ht="img/rollo_guys-on.gif" csclick="B430044A0"><a href="#" overonmouse="return CSIShow(/*CMP*/''TheGuysIcon'',1)" onmouseout="return CSIShow(/*CMP*/''TheGuysIcon'',0)" whenclickedon="CSAction(new Array(/*CMP*/''B430044A0''));return CSClickReturn()"><img src="img/rollo_guys.gif" width="24" height="19" name="TheGuysIcon" border="0"></a></csobj>&lt;/td><br> &lt;td width="18" height="19" colspan="1" rowspan="1" valign="top" align="left" xpos="327"><csobj w="18" h="19" t="Button" ht="img/rollo_girl-on.gif" csclick="B430047C2"><a href="#" overonmouse="return CSIShow(/*CMP*/''TheGirlsIcon'',1)" onmouseout="return CSIShow(/*CMP*/''TheGirlsIcon'',0)" whenclickedon="CSAction(new Array(/*CMP*/''B430047C2''));return CSClickReturn()"><img src="img/rollo_girl.gif" width="18" height="19" name="TheGirlsIcon" border="0"></a></csobj>&lt;/td><br> &lt;td width="21" height="19" colspan="1" rowspan="1" valign="top" align="left" xpos="345"><csobj w="21" h="19" t="Button" ht="img/rollo_clinic-on.gif" csclick="B430049C4"><a href="#" overonmouse="return CSIShow(/*CMP*/''TheClinicIcon'',1)" onmouseout="return CSIShow(/*CMP*/''TheClinicIcon'',0)" whenclickedon="CSAction(new Array(/*CMP*/''B430049C4''));return CSClickReturn()"><img src="img/rollo_clinic.gif" width="21" height="19" name="TheClinicIcon" border="0"></a></csobj>&lt;/td><br> &lt;td width="236" height="19" colspan="1" rowspan="1" valign="top" align="left" xpos="366"><img height="19" width="234" src="img/b_182-main_05.gif">&lt;/td><br> &lt;/tr><br> &lt;tr height="66"> <br> &lt;td width="1" height="66"><spacer type="block" width="1" height="66">&lt;/td><br> &lt;td width="19" height="278" colspan="1" rowspan="6" valign="top" align="left" xpos="0"><img height="278" width="19" src="img/b_182-main_06.gif">&lt;/td><br> &lt;td width="259" height="155" colspan="5" rowspan="3" valign="top" align="left" xpos="19"><a href="previous/news/index.asp" target="blinkbody"><img src="img/news_tab1.gif" width="200" height="20" border="0"></a><a href="fanreg.asp" target="emailsignup" whenclickedon="MM_openBrWindow(''fanreg.asp'',''emailsignup'',''top=0,left=0,width=400 height=410,scrollbars=yes,resizable=yes'')"><img src="img/emailN.gif" width="59" height="20" border="0"></a><br><BR CLEAR="all"><br><br><br><span class="headonly"><a href="http://www.blink182.com/previous/news/index.asp#newsitem967755198,27718,">blink on MTV This Weekend </a></span><span class="headdate"> - 8.31.2000 </span><br><br><br><br><br><br><span class="headonly"><a href="http://www.blink182.com/previous/news/index.asp#newsitem967681690,9222,">blink 182 wins the KERRANG award for Best Video </a></span><span class="headdate"> - 8.30.2000 </span><br><br><br><br><br><br><span class="headonly"><a href="http://www.blink182.com/previous/news/index.asp#newsitem973584000,7244,">This Is The Date The New blink Album Will Be Out!</a></span><span class="headdate"> - 11.7.2000 </span><br><br><br><br><br> <a href="previous/news/index.asp" target="blinkbody"><img src="img/morenews.gif" width="79" height="12" border="0"></a>&lt;/td><br> &lt;td width="25" height="278" colspan="1" rowspan="6" valign="top" align="left" xpos="278"><img height="278" width="25" src="img/b_182-main_12.gif">&lt;/td><br> &lt;td width="299" height="278" colspan="4" rowspan="6" valign="top" align="left" xpos="303"><csobj w="297" h="278" t="Button"><a href="#" overonmouse="return CSIShow(/*CMP*/''TheBigPicture'',1)" onmouseout="return CSIShow(/*CMP*/''TheBigPicture'',0)" whenclickedon="return CSButtonReturn()"><img src="img/TBP-girl.jpg" width="297" height="278" name="TheBigPicture" border="0"></a></csobj>&lt;/td><br> &lt;/tr><br> &lt;tr height="23"> <br> &lt;td width="1" height="23"><spacer type="block" width="1" height="23">&lt;/td><br> &lt;/tr><br> &lt;tr height="78"> <br> &lt;td width="1" height="78"><spacer type="block" width="1" height="78">&lt;/td><br> &lt;/tr><br><br> &lt;tr height="25"><br> &lt;td width="1" height="25"><spacer type="block" width="1" height="25">&lt;/td><br> &lt;td width="259" height="25" colspan="5" rowspan="1" valign="top" align="left" xpos="19"><img height="25" width="259" src="img/b_182-main_20.gif">&lt;/td><br> &lt;/tr><br> &lt;tr height="66"><br> &lt;td width="1" height="66"><spacer type="block" width="1" height="66">&lt;/td><br> &lt;td width="66" height="25" colspan="1" rowspan="1" valign="top" align="left" xpos="19"><a href="http://www.famoussas.com" target="_self"><img src="img/button_famous.gif" width="66" height="66" border="0"></a>&lt;/td><br> &lt;td width="32" height="66" colspan="1" valign="top" align="left" xpos="85"><img height="66" width="32" src="img/b_182-main_08.gif">&lt;/td><br> &lt;td width="66" height="25" colspan="1" rowspan="1" valign="top" align="left" xpos="117"><a href="http://www.loserkids.com" target="_self"><img src="img/button_loserkids.gif" width="66" height="66" border="0"></a>&lt;/td><br> &lt;td width="29" height="66" colspan="1" valign="top" align="left" xpos="183"><img height="66" width="29" src="img/b_182-main_10.gif">&lt;/td><br> &lt;td width="66" height="25" colspan="1" rowspan="1" valign="top" align="left" xpos="212"><a href="http://www.yride.com/" target="_blank"><img src="img/yridebluesquare.gif" width="66" height="66" name="Fenix-TX_Button" border="0"></a>&lt;/td><br> &lt;/tr><br> &lt;tr height="20"> <br> &lt;td width="1" height="20"><spacer type="block" width="1" height="20">&lt;/td><br> &lt;td width="259" height="20" colspan="5" rowspan="1" valign="top" align="left" xpos="19"><img height="20" width="259" src="img/b_182-main_24.gif">&lt;/td><br> &lt;/tr><br> &lt;tr height="16"> <br> &lt;td width="1" height="16"><spacer type="block" width="1" height="16">&lt;/td><br> &lt;td width="602" height="16" colspan="11" rowspan="1" valign="middle" align="left" xpos="0"> <br> &lt;form action="writedata.asp" method="post"><br> <div align="left"> </div><br> </form><br> &lt;/td><br> &lt;/tr><br> &lt;/table><br></center><br> &lt;/body><br><br>&lt;/html><br> </i>

This topic is closed to new replies.

Advertisement