Thanks Oneka, your code help me get this far.
I'm finally getting around to needing to learn management of controlling how many times rendering, input, etc... needs to be done each second... ie: FPS.
The code below is just a rough hack to see if I can get to terms of this. It grabs the desktop width,height,depth for fullscreen.
In testing in a fullscreen 1680x1050 environment with this, my "RPS" (renders per second), is dropped almost in half( ie: from 60 to around 30 ). But yet, if I rem out the if statement that calls the dbSync 60 times a second, I'll get the full capped frame rate.
I tried to follow Oneka's code to do this where I can have alot of room in the frames per second. But, I'm struggling with finding a solution in this method to keep my "RPS" at 60fps and my "FPS" at a high rate.
Plus, I noticed this code's deltatime movement get's the small annoying jitters now and then.
Any help would be apprieciated. Thanks
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
char txt[256];
// ----------------- time variables
double timeStart;
double timeCurrent;
double timeOld;
int timeTick;
double timeLastRenderElasped;
double timeFPS;
double framerate;
double deltatime=0.0;
double deltatimeOld=0.0;
timeStart = (double)dbTimer()/1000.0;
timeCurrent = timeStart;
timeOld = (double)dbTimer()/1000.0;
timeTick = 0;
timeLastRenderElasped = 0.0;
timeFPS = 0.0;
framerate = (1000.0/60.0)/1000.0; // Target 60 Renders Per Second
// ----------------- number of displayed objects
int numofobjects;
numofobjects=200;
// ----------------- setup window/graphics
dbRandomize ( dbTimer() );
dbSyncOff();
dbAutoCamOff( );
int Desktop_Width;
int Desktop_Height;
int Dekstop_Depth;
Desktop_Width=GetSystemMetrics(0);
Desktop_Height=GetSystemMetrics(1);
HDC hdc;
hdc=GetDC(0);
Dekstop_Depth=GetDeviceCaps(hdc,12);
ReleaseDC(0,hdc);
dbSetWindowPosition(0,0);
dbSetDisplayMode(Desktop_Width,Desktop_Height,Dekstop_Depth);
dbSetWindowOff();
dbMakeCamera( 1 );
dbColorBackdrop( 1, dbRGB(8,16,16) );
// make some 3D objects
for ( int i = 1; i < numofobjects; i++ )
{
// make a sphere
dbMakeObjectSphere ( i, 1 );
// position the object in a random location
dbPositionObject ( i, dbRnd ( 80 )-40, dbRnd ( 80 )-40, dbRnd ( 80 )-40 );
// adjust scaling
dbScaleObject ( i, 10 + dbRnd ( 400 ), 10 + dbRnd ( 400 ), 10 + dbRnd ( 400 ) );
// give the object a color
dbColorObject ( i, dbRgb ( 255, 127+dbRnd ( 127 ), 0 ) );
// increase specular power
dbSetObjectSpecularPower ( i, 255 );
// turn off ambient lighting for this object
dbSetObjectAmbient ( i, 0 );
}
// move our camera back so we can view the objects
dbPositionCamera ( 1, 10, 10, -20 );
// now we come to our main loop, we call LoopGDK so some internal
// work can be carried out by the GDK
while ( LoopGDK ( ) )
{
timeTick++;
deltatime = ((double)dbTimer()/1000.0)-deltatimeOld;
deltatimeOld = (double)dbTimer()/1000.0;
// move the camera forwards
if ( dbUpKey ( ) )
dbMoveCamera ( 1,10*deltatime );
// move the camera backwards
if ( dbDownKey ( ) )
dbMoveCamera ( 1,-10*deltatime );
// rotate all of our objects
for ( int i = 1; i < numofobjects; i++ )
dbRotateObject ( i, dbObjectAngleX ( i ) + (10*deltatime), dbObjectAngleY ( i ) + (20*deltatime), dbObjectAngleZ ( i ) + (30*deltatime) );
timeLastRenderElasped = ((double)dbTimer()/1000.0)-timeOld;
if (timeLastRenderElasped>=framerate)
{
timeOld=(double)dbTimer()/1000.0;
sprintf(txt,"RPS=%d FPS=%f, framerate=%f",dbScreenFPS(),timeFPS,framerate);
dbText(10,70,txt);
dbSync ( );
}
timeCurrent = ((double)dbTimer()/1000.0)-timeStart;
if (timeCurrent >=1.0)
{
timeFPS = ((double)timeTick);
timeTick=0;
timeStart= (double)dbTimer()/1000.0;
}
}
// before quitting delete our objects
//for ( int i = 1; i < 50; i++ )
// dbDeleteObject ( i );
return;
}
Inspirational Music: Descent ][ Redbook Audio CD Soundtrack