#include	<v_lib.h>

#define		A

int main(int argc,char *argv[])
{
	char c[16];
	vhandle_t w1, w2, w3, w4;
	u8_t *pixels;
	u32_t w,h;
	
	logStartConsoleLog();
	logUpperLevel(LOG_TRACE);

#if	defined(A)
	/* Multiple GL windows test */
	
	w1=vglCreateWindow("1",0,0,320,240);
	w2=vglCreateWindow("2",0,280,320,240);
	w3=vglCreateWindow("3",340,0,320,240);
	w4=vglCreateWindow("4",340,280,320,240);
	
	vglMakeCurrent(w1);
	glClearColor(0,1,1,0);
	glClear(GL_COLOR_BUFFER_BIT);
	vglSwapBuffers();
	
	vglMakeCurrent(w2);
	glClearColor(1,0,1,0);
	glClear(GL_COLOR_BUFFER_BIT);
	vglSwapBuffers();

	vglMakeCurrent(w3);
	glClearColor(1,1,0,0);
	glClear(GL_COLOR_BUFFER_BIT);
	vglSwapBuffers();

	vglMakeCurrent(w4);
	glClearColor(1,1,1,0);
	glClear(GL_COLOR_BUFFER_BIT);
	vglSwapBuffers();

	fgets(c,10,stdin);
	
	vglDestroyWindow(w1);
	vglDestroyWindow(w2);
	vglDestroyWindow(w3);
	vglDestroyWindow(w4);

#elif	defined(B)
	/* Fullscreen rendering */
	w1=vglCreateFullscreenWindow("FSOGL",640,480,16,100);

	glClearColor(0,(GLfloat).7,(GLfloat).7,0);
	glClear(GL_COLOR_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,319,239,0,-1,1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glBegin(GL_TRIANGLES);
		glColor3f(1,1,1);
		glVertex2f(10,10);
		glColor3f(1,0,1);
		glVertex2f(160,10);
		glColor3f(1,1,0);
		glVertex2f(10,120);
	glEnd();

	vglSwapBuffers();
	
	fgets(c,10,stdin);
	
	vglDestroyWindow(w1);
	
#elif	defined(C)

	/* Offscreen rendering */
	w1=vglCreateMappedWindow(320,240);

	glClearColor(0,(GLfloat).7,(GLfloat).7,0);
	glClear(GL_COLOR_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,319,239,0,-1,1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glBegin(GL_TRIANGLES);
		glColor3f(1,1,1);
		glVertex2f(10,10);
		glColor3f(1,0,1);
		glVertex2f(160,10);
		glColor3f(1,1,0);
		glVertex2f(10,120);
	glEnd();

	glColor3f(1,1,1);
	glBegin(GL_LINE_LOOP);
		glVertex2f(0,0);
		glVertex2f(319,0);
		glVertex2f(319,239);
		glVertex2f(0,239);
	glEnd();
	
	vglSwapBuffers();
	pixels=vglReadPixels(&w,&h);
	tgaSave("out.tga",w,h,pixels);
	memFree(pixels);

	vglDestroyWindow(w1);
	
#endif
	
	
	return 0;
}
