Hi!!
I have made an fps counter that doesn''t seem to work right. If the fps is between 33 and 50 the counter shows correctly but when it goes below or above it just show 33 or 50. I dont undertand why because as I see it this is just some simple math.
if(CURRENTTIME - FRAMESTART >= FRAMETIME)
{
FRAMES = 1000/(CURRENTTIME - FRAMESTART);
FRAMESTART = timeGetTime();
DrawScene();
}
CURRENTTIME = timeGetTime();
void ShowFrames(UINT frames)
{
UCHAR THOUSANDS,HUNDREDS,TENS,NUMBERS;
THOUSANDS = frames/1000;
HUNDREDS = (frames/100)%10;
TENS = (frames/10)%10;
NUMBERS = frames%10;
switch(THOUSANDS)
{
case 0:
D3dDevice->SetTexture(0, t_FrameNumber[0]);
break;
case 1:
D3dDevice->SetTexture(0, t_FrameNumber[1]);
break;
case 2:
D3dDevice->SetTexture(0, t_FrameNumber[2]);
break;
case 3:
D3dDevice->SetTexture(0, t_FrameNumber[3]);
break;
case 4:
D3dDevice->SetTexture(0, t_FrameNumber[4]);
break;
case 5:
D3dDevice->SetTexture(0, t_FrameNumber[5]);
break;
case 6:
D3dDevice->SetTexture(0, t_FrameNumber[6]);
break;
case 7:
D3dDevice->SetTexture(0, t_FrameNumber[7]);
break;
case 8:
D3dDevice->SetTexture(0, t_FrameNumber[8]);
break;
case 9:
D3dDevice->SetTexture(0, t_FrameNumber[9]);
break;
}
D3dDevice->SetStreamSource(0, vb_FrameCounter[3], sizeof(PANELVERTEX));
D3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
switch(HUNDREDS)
{
case 0:
D3dDevice->SetTexture(0, t_FrameNumber[0]);
break;
case 1:
D3dDevice->SetTexture(0, t_FrameNumber[1]);
break;
case 2:
D3dDevice->SetTexture(0, t_FrameNumber[2]);
break;
case 3:
D3dDevice->SetTexture(0, t_FrameNumber[3]);
break;
case 4:
D3dDevice->SetTexture(0, t_FrameNumber[4]);
break;
case 5:
D3dDevice->SetTexture(0, t_FrameNumber[5]);
break;
case 6:
D3dDevice->SetTexture(0, t_FrameNumber[6]);
break;
case 7:
D3dDevice->SetTexture(0, t_FrameNumber[7]);
break;
case 8:
D3dDevice->SetTexture(0, t_FrameNumber[8]);
break;
case 9:
D3dDevice->SetTexture(0, t_FrameNumber[9]);
break;
}
D3dDevice->SetStreamSource(0, vb_FrameCounter[2], sizeof(PANELVERTEX));
D3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
switch(TENS)
{
case 0:
D3dDevice->SetTexture(0, t_FrameNumber[0]);
break;
case 1:
D3dDevice->SetTexture(0, t_FrameNumber[1]);
break;
case 2:
D3dDevice->SetTexture(0, t_FrameNumber[2]);
break;
case 3:
D3dDevice->SetTexture(0, t_FrameNumber[3]);
break;
case 4:
D3dDevice->SetTexture(0, t_FrameNumber[4]);
break;
case 5:
D3dDevice->SetTexture(0, t_FrameNumber[5]);
break;
case 6:
D3dDevice->SetTexture(0, t_FrameNumber[6]);
break;
case 7:
D3dDevice->SetTexture(0, t_FrameNumber[7]);
break;
case 8:
D3dDevice->SetTexture(0, t_FrameNumber[8]);
break;
case 9:
D3dDevice->SetTexture(0, t_FrameNumber[9]);
break;
}
D3dDevice->SetStreamSource(0, vb_FrameCounter[1], sizeof(PANELVERTEX));
D3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
switch(NUMBERS)
{
case 0:
D3dDevice->SetTexture(0, t_FrameNumber[0]);
break;
case 1:
D3dDevice->SetTexture(0, t_FrameNumber[1]);
break;
case 2:
D3dDevice->SetTexture(0, t_FrameNumber[2]);
break;
case 3:
D3dDevice->SetTexture(0, t_FrameNumber[3]);
break;
case 4:
D3dDevice->SetTexture(0, t_FrameNumber[4]);
break;
case 5:
D3dDevice->SetTexture(0, t_FrameNumber[5]);
break;
case 6:
D3dDevice->SetTexture(0, t_FrameNumber[6]);
break;
case 7:
D3dDevice->SetTexture(0, t_FrameNumber[7]);
break;
case 8:
D3dDevice->SetTexture(0, t_FrameNumber[8]);
break;
case 9:
D3dDevice->SetTexture(0, t_FrameNumber[9]);
break;
}
D3dDevice->SetStreamSource(0, vb_FrameCounter[0], sizeof(PANELVERTEX));
D3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
}
Any comments on how to optimize is also welcom....
Thanks!!!
True words are not always beautiful, beautiful words are not always truthful.