Freezing problem

I’m showing 20000 points on the screen with FPS counter but every second(or so) the program freezes for a while(very short time but you can see it)

double GetTime()
{
	double deltatime=0;
	int i=0;
	static __int64 frequency=0;
	static __int64 old_count=0;
	__int64 count;
	if(frequency==0)								//if first time getting time 
	{														
		QueryPerformanceFrequency((LARGE_INTEGER*)&frequency);		//get frequency first
	}
	if(old_count==0)						//if first time getting time 
	{
		QueryPerformanceCounter((LARGE_INTEGER*)&old_count);		//set starting count to actuall
		count=old_count;
	}
	else											//if not first time 
		QueryPerformanceCounter((LARGE_INTEGER*)&count);
	if((count-old_count+200)>0)
	{
		deltatime=((double)(count-old_count+200))/(double)frequency;		//time is in seconds
	}
	else
		deltatime=10000.0f/(double)frequency;
	old_count=count;	
	return deltatime;
}
 
void DrawGLScene()
{
	int i;
	static int fps;
	static char fpsshow[10];
	static double time=0;
	time+=GetTime();
	if(time<0.0f)
			time=0.0f;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	glLoadIdentity();
	glBegin(GL_POINTS);
	for(i=0;i<MAX_PARTICLES;i++)
	{
		
		if(particles[i].life)												//if particle is active
		{
			glColor3f(particles[i].r,particles[i].g,particles[i].b);		//draw it
			glVertex3f(particles[i].x,particles[i].y,(float)particles[i].z);
			particles[i].z+=(time*particles[i].vz);
		}
		else																//else activate it
		{
			ActivateParticle(i);
		}
		if(particles[i].z>=1.0f)											//if particle is behind
		{																	//screen deactivate it
			particles[i].life=false;
		}
	}
	glEnd();
	if(time>=1.0f)
	{
		sprintf(fpsshow,"%d FPS",fps);
		fps=0;
		time-=1.0f;
	}
	ShowFPS(time,fpsshow);
	fps++;
}




 

Hi !

Without knowing anything about the OS and other parts of the code that is impossible to answer.

If it is all your own code running in one thread you should not see any lockups, but if you are using for example Windows with glut or something there may be a timer that kicks in every second, and if this takes up a little time then you will see this kind of behavior, but as I said, it is not possible to answer your question with the information you gave.

Mikael

fixed time variable was problem thanks anyway