#include "win_vga.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

#define	width	640
#define	height	480

#define	DIRTY

int main(int argc,char *argv[])
{
	int i,x,y,start,end;
	char msg[256];
	if(!graphInitWinDIB(width,height))
	{
		puts("graphInitWinDIB() failed.");
		return -1;
	}
	graphSetWindowTitle("FPS test (graphClear())");
	start=GetTickCount();
	for(i=0;i<256;i++)
	{
		unsigned r,g,b,color;
		r=rand()%256;
		g=rand()%256;
		b=rand()%256;
		color=r<<16 | g<<8 | b;
#ifndef	DIRTY
		graphLockBackbuffer();
#endif
		graphClear(color);
#ifndef	DIRTY
		graphUnlockBackbuffer();
#endif
		graphSwapBuffers();
	}
	end=GetTickCount();
	sprintf(msg,"%d clears, %g fps",i,(double)i/(double)(end-start)*1000);
	MessageBox(GetActiveWindow(),msg,"test",0);
	graphSetWindowTitle("FPS test (graphSetPixel32())");
	start=GetTickCount();
	for(i=0;i<256;i++)
	{
		unsigned r,g,b,color;
		r=rand()%256;
		g=rand()%256;
		b=rand()%256;
		color=r<<16 | g<<8 | b;
#ifndef	DIRTY
		graphLockBackbuffer();
#endif
		for(y=0;y<height;y++)
			for(x=0;x<width;x++)
			{
				graphSetPixel32(x,y,color);
			}
#ifndef	DIRTY
		graphUnlockBackbuffer();
#endif
		graphSwapBuffers();
	}
	end=GetTickCount();
	sprintf(msg,"%d clears, %g fps",i,(double)i/(double)(end-start)*1000);
	MessageBox(GetActiveWindow(),msg,"test",0);
	graphShutdownWinDIB();
	return 0;
}
