#include <v_lib.h>

vec_t alpha = 0.5f;

/*
#define	USE_COMPILED_IN_FONT
*/

/*
 * This function will be passed later to vglDrawToMetafile(),
 * so we need to declare it as 'V_CALL'
 */
void V_CALL draw_scene(void *param)
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-1,1,-1,1,-1,1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(-1,1,0);
    glScalef(.25f,.3f,.3f);
    glTranslatef(0,-1,0);

	glClearColor(0,0,0,1);
    glClear(GL_COLOR_BUFFER_BIT);

	glDisable(GL_DEPTH_TEST);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glEnable(GL_LINE_SMOOTH);
    glColor4f(0,1,1,alpha);
    glLineWidth(2.8f);

	/* vglPutsKoi8r("pRIWET !\n"); */
    vglPuts("Привет !\n\n");
    vglPuts("1234567890");
}

int main()
{
	input_record_t r;
    vhandle_t font = LIBV_INVALID_HANDLE;
    logStartConsoleLog();
    logUpperLevel(LOG_TRACE);
	vglCreateWindow("Stroke font demo",0,0,320,240);
#ifndef	USE_COMPILED_IN_FONT
    font = vglLoadBGIFontEx("../../../media/bgi-fonts/cyrgoth.chr",false);
	if(font != LIBV_INVALID_HANDLE)
	{
		vglSelectFont(font);
        /*
         * Note: fonts are reference-counted, so we can safe
         * call vglDestroyFont() befofe vglDestroyWindow().
         */
        vglDestroyFont(font);
	}
	else
	{
		vglDestroyWindow(vglGetCurrentWindow());
    	conlPuts(LOG_ERROR,"Error loading BGI font\n");
		return -1;
	}
#else	/* USE_COMPILED_IN_FONT */
	vglLoadDefaultFont();
#endif	/* !USE_COMPILED_IN_FONT */
   	/* Animate text */
    do
    {
    	while(!vglPending())
		{
			draw_scene(NULL);
     		vglSwapBuffers();
      		timeDelay(10);
       		alpha += 0.01f;
        	if(alpha >= 1.0f)
        		alpha = 0.5f;
		}
        vglNextEvent(&r);
	} while(r.event!=ev_key_down);
	vglDrawToMetafile("out.wmf",100,100,draw_scene,font);
#ifdef  __WIN32__
	/* Draw text to the system clipboard */
	vglDrawToMetafile("//./clipboard",100,100,draw_scene,font);
#endif  /* __WIN32__ */
	vglDestroyWindow(vglGetCurrentWindow());
	memPrintStats();
	return 0;
}
