#include "slugmass.h"
#include "rend_event.h"


ggi_visual_t vis;

ggi_visual_t *render_init(void)
{
   if (ggiInit()) 
	{        /* Initialize LibGGI */
     printf("Ouch - ggiInit failed.\n");     /* oh - we failed ??? */
     exit(1);
   }
	
	/* Allocate a visual handle for the default visual (NULL) */
	if (NULL==(vis=ggiOpen(NULL)))
	{
		ggiExit();      /* Deinitialize the library properly */
		printf("Ouch - ggiOpen failed.\n");
		exit(2);
	}
	
	if (ggiSetSimpleMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO) != 0)
	{
		ggiPanic("Cannot set default mode!\n");
	}
	
	
	return &vis;
}



#include <time.h>

void render_main(void)
{
	ggi_pixel white;
	static ggi_pixel tmp = 0;
	ggi_color map;
	char teststr[256];
	static long frame=0;
	time_t t;
  	static time_t lt = 0;
	static int fps = 0, lfps = 0;
	
	t = time(NULL);
	
	map.r = map.g = map.b = 0xFFFF;
	white=ggiMapColor(vis, &map);
	
	ggiSetGCForeground(vis, white);
	
	sprintf(teststr, "frame = %ld", frame++);
	ggiPuts(vis, 1, 10, teststr);
	
	fps++;
	if(t > lt)
	{
		if (lfps != 0)
			sprintf(teststr, "Approx %d frames per second.", (fps + lfps)/2);
		else
			sprintf(teststr, "Approx %d frames per second.", fps);
		fps = 0;
		ggiPuts(vis, 1, 20, teststr);
		lfps = fps;
	}
	
	sprintf(teststr, "Color: %X ", tmp);
	ggiPuts(vis, 1, 30, teststr);
	
	ggiSetGCForeground(vis, tmp++);
	
	if(tmp > 0xFFFFFF)
		tmp=0;
	
	ggiDrawBox(vis, 50, 50, 300, 300);
	
	
	lt=t;
}



