//-----------------------------------------------------------------------------------
// Bismillahirrahmanirrahim  
//-----------------------------------------------------------------------------------
//																					|
//               MOS 2D Engine ( MEYDANERĘ OpenGL Software Engine)					|
//																				    |
// ----------------------------------------------------------------------------------
//    Yapimci = Vedat Meydaneri														|
//     email = Chenmy1@yahoo.com													|
//     web = www.turkop.cjb.net														|
//-----------------------------------------------------------------------------------
// MOS 2D Engine (Vedat Meydaneri ) - Olusturma tarihi :10/ Temmuz /2003 saat: 15:00 |
//************************************************************************************
//************************************************************************************
//************************************************************************************
//------------------------------------------------------------------------------------  



#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <mosfps.h>
#include "mostemp.h"
#include "resource.h"





bool OyunuYukle(void);
bool OyunEkrani(void);
bool OyunuKapat(void);

//MOS2D SDK
MOSEkran pencere;
MOSResim resim;
MOSButton button;


MOSFps fps;

CDXInput Input;

//Ekran karti bilgileri
char *vendorgl;
char *renderirgl;
char *versiongl;
char *extensiongl;

CDXPacker pack;

DWORD Ps;

void HTMLeki()
{


	g_log.bPrint("<html>");
g_log.bPrint("	<head>");
g_log.bPrint("<meta http-equiv='Content-Type' content='text/html'>");
g_log.bPrint("<style type='text/css'>");
g_log.bPrint("<!--");
g_log.bPrint("body          {margin-top:0; margin-left:0; margin-right:0; color: #FFFFFF; font-family: helvetica, arial, geneva, sans-serif; font-size: 10pt; scrollbar-face-color: #00365E; scrollbar-highlight-color: #A9D0ED; scrollbar-3dlight-color: #7CB6E0; scrollbar-darkshadow-color: #1C5077; scrollbar-shadow-color: #226291; scrollbar-arrow-color: #A9D0ED; scrollbar-track-color: #00365E}");
g_log.bPrint("table         {font-family: helvetica, arial, geneva, sans-serif; font-size: 10pt; text-decoration: none; color: #FFFFFF}");
g_log.bPrint("A:link        {font-family: helvetica, arial, geneva, sans-serif; font-size: 10pt; text-decoration: none; color: #7CB6E0}");
g_log.bPrint("A:visited     {font-family: helvetica, arial, geneva, sans-serif; font-size: 10pt; text-decoration: none; color: #7CB6E0}");
g_log.bPrint("A:hover       {font-family: helvetica, arial, geneva, sans-serif; font-size: 10pt; text-decoration: underline}");
g_log.bPrint("A:link.nav    {font-family: helvetica, arial, geneva, sans-serif; color: #7CB6E0}");
g_log.bPrint("A:visited.nav {font-family: helvetica, arial, geneva, sans-serif; color: #7CB6E0}");
g_log.bPrint("A:hover.nav   {font-family: helvetica, arial, geneva, sans-serif; text-decoration: underline}");
g_log.bPrint("//-->");
g_log.bPrint("</style>");
g_log.bPrint("</head>");
   g_log.bPrint("<body>");
   g_log.bPrint("<pre>");
   g_log.bPrint("<title>TurkOP - www.turkop.cjb.net</title>");
 

  // g_log.bPrint("<body bgcolor='#000000' text='#FFFFFF'>");
   g_log.bPrint("<body bgcolor='#00365E' text='#FFFFFF'>");
    g_log.bPrint(" <p align='center'><img border='0' src='data/spr/mos3d.bmp' width='260' height='160'><br> ");
	g_log.bPrint("<font size='5' color='#FF0000'><b>TURK-OP ( OYUN YAPIM GRUBU)<br>  ");
	g_log.bPrint(" VEDAT MEYDANERI&nbsp; 1999-2004</b></font></p> ");
	g_log.bPrint(" <p align='center'><font size='5' color='#FF0000'><b>Created MOS 2D/3D by VEDAT MEYDANERI ");
	g_log.bPrint(" <br>GAME DEBUG LOG</b></font></p> ");
 //   
 // g_log.bPrint("	<table width='' border='1' bordercolor='#1C5077'><tr><td>");
  g_log.bPrint(" wwww.TURKOP.cjb.net ");
 // g_log.bPrint("</td></tr><tr><td>");
 // g_log.bPrint("<h3>");

}

bool OyunuYukle(void)
{


      HTMLeki();
 

	if(!pencere.ZamaniBaslat())
	{

	}
	
	pencere.Olustur(640,480,16, PEN_SORU, "MOS2D - TEST");


	Input.Create( g_hInstance ,   g_hWnd ); 
	Input.SetMouseLimits(0,0,640 -9,480-9);

  

   
	vendorgl = strdup((char *) glGetString(GL_VENDOR));
    renderirgl = strdup((char *) glGetString(GL_RENDERER));
    versiongl = strdup((char *) glGetString(GL_VERSION));

	char	*token;										
	int		cnt=0;
//	int			maxtokens;

	char* text=(char *)malloc(strlen((char *)glGetString(GL_EXTENSIONS))+1);	
	strcpy (text,(char *)glGetString(GL_EXTENSIONS));		
	token=strtok(text," ");	




	g_log.bPrint("\n");
	g_log.bPrint("-------------------------------------");
	g_log.bPrint("MOS2D Engine : TURKOP");
	g_log.bPrint("  VEDAT MEYDANERI  2004-0cak-18");
	g_log.bPrint("-------------------------------------");
	g_log.bPrint("OpenGL Ekran Karti :");
	g_log.bPrint("-------------------------------------");

	
		while(token!=NULL)										
	{

		g_log.bPrint(token);
		token=strtok(NULL," ");								
	}

	free(text);
		
		
    Spriteinit();

	//sesler
	Dsoundinit();


	fps.OlusturTimer();


	Ps = PS_MENU;



	return TRUE;
}
void Yazilar()
{
	CHAR yaz[200];

	sprintf(yaz,"FPS : %.0f",pencere.g_fFPS);
	font.Yaz(10,20,yaz,1);
/*	font.Yaz(10,40,"Ekran Karti Bilgileri:",1);
	sprintf(yaz,"Yapimci : %s",vendorgl);
	font.Yaz(10,60,yaz,1);
	sprintf(yaz,"Turu : %s",renderirgl);
	font.Yaz(10,80,yaz,1);
	sprintf(yaz,"Versionu : %s",versiongl);
	font.Yaz(10,100,yaz,1);	*/
	sprintf(yaz,"MOS2D/3D Engine");
	font.Yaz(10,40,yaz,1);
	sprintf(yaz,"Olusturan Vedat MEYDANERI",versiongl);
	font.Yaz(350,440,yaz,1);	

	/*sprintf(yaz,"MouseX : %d ,MouseY : %d",mx,my);
	font.Yaz(10,180,yaz,1);*/
	
/*	sprintf(yaz,"zaman %f",pencere.g_ZamanSayaci*100);
	font.Yaz(10,180,yaz,1);*/

}
bool OyunMenu(void)
{
	LoopSes();

	pencere.EkraniTemizle();

	//Pencere LOOP kismi
	Klavye();
	

	//----------------------------------
	//Ekrani 2D yap
	//-----------------------------------
	pencere.Ekran2DCiz(ACIK);


	Spritelariciz();

	pencere.Ekran2DCiz(KAPALI);
	//----------------------------------
	//Ekrani 2D yapma

	//----------------------------------




	Yazilar();

	if(Input.GetKeyState(CDXKEY_F1)==CDXKEY_PRESS)
	{
		
		resim.EkranGoruntusu();

	}

//	fps.FPSKisitla(FPS_ATMIS);
	pencere.ZamaniGuncelle();
	pencere.vBufferSwap();	
	return TRUE;
}
bool OyunEkrani(void)
{

	LoopSes();

	pencere.EkraniTemizle();

	//Pencere LOOP kismi
	OyunKlavye();
	
	//----------------------------------
	//Ekrani 2D yap
	//-----------------------------------
	pencere.Ekran2DCiz(ACIK);


	Oyun();

	pencere.Ekran2DCiz(KAPALI);
	//----------------------------------
	//Ekrani 2D yapma
	//-----------------------------------


	OyunYazi();

	if(Input.GetKeyState(CDXKEY_F1)==CDXKEY_PRESS)
	{
		
		resim.EkranGoruntusu();

	}

//	fps.FPSKisitla(FPS_ATMIS);
	pencere.ZamaniGuncelle();
	pencere.vBufferSwap();	
	return TRUE;
}
bool OyunuKapat(void)
{

	 Dsoundkaldir();
     font.KillFont();
	pencere.vKapat();
	return false;
}
LRESULT CALLBACK WindowProc(HWND a_hWnd, UINT a_uiMsg, WPARAM a_wParam, LPARAM a_lParam)
{
	switch(a_uiMsg)
	{
		case WM_ACTIVATE:
			if(!HIWORD(a_wParam))
				pencere.g_PencereAktif= PEN_AKTIF;

			else
				pencere.g_PencereAktif= PEN_PASIF;
			return 0;
			break;

		case WM_CHAR:
		{
		
		}
		return 0;
		break;

		case WM_SYSCOMMAND:
			switch(a_wParam)
			{
				case SC_SCREENSAVE:
				case SC_MONITORPOWER:
				return 0;
			}
			break;

		case WM_CLOSE:
			PostQuitMessage(0);
			return 0;
			break;
			
		case WM_KEYDOWN:
		{
		
		}
		return 0;
		break;


		case WM_SIZE:
			pencere.g_EkranX = LOWORD(a_lParam);
			pencere.g_EkranY= HIWORD(a_lParam);

			pencere.glResizeScenep(pencere.g_EkranX, pencere.g_EkranY,pencere.kameraFOV);
			return 0;
			break;
	}

	return DefWindowProc(a_hWnd, a_uiMsg, a_wParam, a_lParam);
}
bool Loop()
{
	switch(Ps)
	{
	case PS_MENU:
		OyunMenu();
		break;
	case PS_OYUN:
		OyunEkrani();
		break;	
	case PS_RESETGAME:
		ResetGame();
		break;
	case PS_RELOAD:
		reload();
		break;
	}


	return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, 
				   HINSTANCE hPrevInstance, 
				   LPSTR	 lpCmdLine, 
				   int		 nCmdShow) 
{



	if(!OyunuYukle())
		return false;


	while(true)
	{
	
	if(!pencere.bHandleMessages())
			break;
		

		if(pencere.g_PencereAktif==PEN_AKTIF )
		{
			Input.Update();			

			if(!Loop())
				break;
		}
	} 

	OyunuKapat();
	return false;
}





