• Advertisement

Archived

This topic is now archived and is closed to further replies.

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

This topic is 6385 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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++; }

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
oops, include above should be
#include <time.h>

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
  • Share this post


    Link to post
    Share on other sites
    Guest Anonymous Poster




    <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")[s].style; }
    function CSNSStyl(s) { return CSFindElement(s,0); }
    function CSFindElement(n,ly) { if (CSBVers < 4) return document[n];
    var curDoc = ly ? ly.document : document; var elem = curDoc[n];
    if (!elem) { for (var i=0;i elem = CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}
    return elem;
    }
    function CSButtonReturn () {
    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 false; // follow link
    else return true; // follow link
    }
    CSIm = new Object();
    function CSIShow(n,i) {
    if (document.images) {
    if (CSIm[n]) {
    var img = (!IsIE()) ? CSFindElement(n,0) : document[n];
    if (img && typeof(CSIm[n][i].src) != "undefined") {img.src = CSIm[n][i].src;}
    if(i != 0)
    self.status = CSIm[n][3];
    else
    self.status = " ";
    return true;
    }
    }
    return false;
    }
    function CSILoad(action) {
    im = action[1];
    if (document.images) {
    CSIm[im] = new Object();
    for (var i=2;i<5;i++) {
    if (action[i] != '''') { CSIm[im][i-2] = new Image(); CSIm[im][i-2].src = action[i]; }
    else CSIm[im][i-2] = 0;
    }
    CSIm[im][3] = action[5];
    }
    }
    CSStopExecution = false;

    function CSAction(array) {
    return CSAction2(CSAct, array);
    }
    function CSAction2(fct, array) {
    var result;
    for (var i=0;i if(CSStopExecution) return false;
    var actArray = fct[array[i]];
    if(actArray == null) return false;

    var tempArray = new Array;
    for(var j=1;j if((actArray[j] != null) && (typeof(actArray[j]) == "object") && (actArray[j].length == 2)) {
    if(actArray[j][0] == "VAR") {
    tempArray[j] = CSStateArray[actArray[j][1]];
    }
    else {
    if(actArray[j][0] == "ACT") {
    tempArray[j] = CSAction(new Array(new String(actArray[j][1])));
    }
    else
    tempArray[j] = actArray[j];
    }
    }
    else
    tempArray[j] = actArray[j];
    }
    result = actArray[0](tempArray);
    }
    return result;
    }
    CSAct = new Object;
    function CSSetImageURL(action) {
    var img = null;
    if (document.images) {
    if (!IsIE()) img = CSFindElement(action[1],0);
    else img = document.images[action[1]];
    if (img) img.src = action[2];
    }
    }
    // --></script>

    <script>
    <!--
    <!--
    CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''TheGuysIcon'',/*URL*/''img/rollo_guys.gif'',/*URL*/''img/rollo_guys-on.gif'',/*URL*/'''','''');
    CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''TheGirlsIcon'',/*URL*/''img/rollo_girl.gif'',/*URL*/''img/rollo_girl-on.gif'',/*URL*/'''','''');
    CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''TheClinicIcon'',/*URL*/''img/rollo_clinic.gif'',/*URL*/''img/rollo_clinic-on.gif'',/*URL*/'''','''');
    CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''TRL_Button'',/*URL*/''img/button_TRL.gif'',/*URL*/'''',/*URL*/'''','''');
    CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''Roids_Button'',/*URL*/''img/button_roids.gif'',/*URL*/'''',/*URL*/'''','''');
    CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''Tour_Button'',/*URL*/''img/button_tour.gif'',/*URL*/'''',/*URL*/'''','''');
    CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''TheBigPicture'',/*URL*/''img/TBP-girl.jpg'',/*URL*/'''',/*URL*/'''','''');
    CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''LoserKids_Button'',/*URL*/''img/button_loserkids.gif'',/*URL*/'''',/*URL*/'''','''');
    CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''BlinkTV_Button'',/*URL*/''img/button_blink-tv.gif'',/*URL*/'''',/*URL*/'''','''');
    CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''Fenix-TX_Button'',/*URL*/''img/button_fenix-tx.gif'',/*URL*/'''',/*URL*/'''','''');
    CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/''TextBox'',/*URL*/''img/text_generic.gif'',/*URL*/'''',/*URL*/'''','''');
    CSAct[/*CMP*/ ''B430044A0''] = new Array(CSSetImageURL,/*CMP*/ ''TheBigPicture'',/*URL*/ ''img/TBP-guys.jpg'');
    CSAct[/*CMP*/ ''B430047C2''] = new Array(CSSetImageURL,/*CMP*/ ''TheBigPicture'',/*URL*/ ''img/TBP-girl.jpg'');
    CSAct[/*CMP*/ ''B430049C4''] = new Array(CSSetImageURL,/*CMP*/ ''TheBigPicture'',/*URL*/ ''img/TBP-clinic.jpg'');
    CSAct[/*CMP*/ ''B430059D7''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_TRL.gif'');
    CSAct[/*CMP*/ ''B43005A88''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_generic.gif'');
    CSAct[/*CMP*/ ''B43005BF9''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_roids.gif'');
    CSAct[/*CMP*/ ''B43005CE10''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_generic.gif'');
    CSAct[/*CMP*/ ''B43005D911''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_tour.gif'');
    CSAct[/*CMP*/ ''B43005E612''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_generic.gif'');
    CSAct[/*CMP*/ ''B43005F113''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_loserkids.gif'');
    CSAct[/*CMP*/ ''B43005FF14''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_generic.gif'');
    CSAct[/*CMP*/ ''B430060A15''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_blink-tv.gif'');
    CSAct[/*CMP*/ ''B430061516''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_generic.gif'');
    CSAct[/*CMP*/ ''B430062017''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_fenix-tx.gif'');
    CSAct[/*CMP*/ ''B430063018''] = new Array(CSSetImageURL,/*CMP*/ ''TextBox'',/*URL*/ ''img/text_generic.gif'');

    // -->

    function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
    }
    //-->
    </script>

    <style type="text/css">
    <!--
    p { font-size: 11px; margin: 8px 0px}
    -->






    <table cool width="603" height="314" border="0" cellpadding="0" cellspacing="0" gridx="1" showgridx usegridx gridy="1" showgridy usegridy>
    <tr height="1" cntrlrow>
    <td width="1" height="1"></td>
    <td width="19" height="1"></td>
    <td width="66" height="1"></td>
    <td width="32" height="1"></td>
    <td width="66" height="1"></td>
    <td width="29" height="1"></td>
    <td width="66" height="1"></td>
    <td width="25" height="1"></td>
    <td width="24" height="1"></td>
    <td width="18" height="1"></td>
    <td width="21" height="1"></td>
    <td width="236" height="1"></td>
    </tr>
    <tr height="19">
    <td width="1" height="19"></td>
    <td width="303" height="19" colspan="7" rowspan="1" valign="top" align="left" xpos="0"></td>
    <td width="24" height="19" colspan="1" rowspan="1" valign="top" align="left" xpos="303"></td>
    <td width="18" height="19" colspan="1" rowspan="1" valign="top" align="left" xpos="327"></td>
    <td width="21" height="19" colspan="1" rowspan="1" valign="top" align="left" xpos="345"></td>
    <td width="236" height="19" colspan="1" rowspan="1" valign="top" align="left" xpos="366"></td>
    </tr>
    <tr height="66">
    <td width="1" height="66"></td>
    <td width="19" height="278" colspan="1" rowspan="6" valign="top" align="left" xpos="0"></td>
    <td width="259" height="155" colspan="5" rowspan="3" valign="top" align="left" xpos="19">




    blink on MTV This Weekend - 8.31.2000





    blink 182 wins the KERRANG award for Best Video - 8.30.2000





    This Is The Date The New blink Album Will Be Out! - 11.7.2000




    </td>
    <td width="25" height="278" colspan="1" rowspan="6" valign="top" align="left" xpos="278"></td>
    <td width="299" height="278" colspan="4" rowspan="6" valign="top" align="left" xpos="303"></td>
    </tr>
    <tr height="23">
    <td width="1" height="23"></td>
    </tr>
    <tr height="78">
    <td width="1" height="78"></td>
    </tr>

    <tr height="25">
    <td width="1" height="25"></td>
    <td width="259" height="25" colspan="5" rowspan="1" valign="top" align="left" xpos="19"></td>
    </tr>
    <tr height="66">
    <td width="1" height="66"></td>
    <td width="66" height="25" colspan="1" rowspan="1" valign="top" align="left" xpos="19"></td>
    <td width="32" height="66" colspan="1" valign="top" align="left" xpos="85"></td>
    <td width="66" height="25" colspan="1" rowspan="1" valign="top" align="left" xpos="117"></td>
    <td width="29" height="66" colspan="1" valign="top" align="left" xpos="183"></td>
    <td width="66" height="25" colspan="1" rowspan="1" valign="top" align="left" xpos="212"></td>
    </tr>
    <tr height="20">
    <td width="1" height="20"></td>
    <td width="259" height="20" colspan="5" rowspan="1" valign="top" align="left" xpos="19"></td>
    </tr>
    <tr height="16">
    <td width="1" height="16"></td>
    <td width="602" height="16" colspan="11" rowspan="1" valign="middle" align="left" xpos="0">
    <form action="writedata.asp" method="post">


    </td>
    </tr>
    </table>

    </body>

    </html>

    Share this post


    Link to post
    Share on other sites

    • Advertisement