//********************************************************************
// This source file is part of Ninfa3D Engine
// 
// Copyright (C) 2008-2009 Viz_fuerte. All rights reserved.
// 
// LIMITED WARRANTY
// This software is provided "as-is", without any express or implied warranty.
// In no event shall the author be held liable for any damages arising from the use of this software.
// This is a contract. By accepting the Ninfa3D Engine (the SOFTWARE), 
// you (either an individual or a single entity, the LICENSEE) accept the terms and conditions of this licensing agreement.
// 
// If the LICENSEE does not accept the terms and conditions, then LICENSEE must not accept the SOFTWARE.
// If at a later time the LICENSEE decides not to continue licensing the SOFTWARE under these terms and 
// conditions, then the LICENSEE must delete permanently all files constituting the SOFTWARE.
//
// File: Graphics.cpp
//********************************************************************

/*--------------------------------------------------------------------
Includos*/

	#include "..\..\Header Files\Ninfa3D.h"

/*--------------------------------------------------------------------
Variables externas*/

	extern IVideoDriver* driver;

/*--------------------------------------------------------------------
Variables globales*/

	unsigned int gc_red = 255;
	unsigned int gc_green = 255;
	unsigned int gc_blue = 255;
	unsigned int gc_alpha = 255;

/*--------------------------------------------------------------------
Declaracion global de funciones*/

extern "C"
{

	/*================================================================
	Cambia la transparencia.*/

	DLL_EXPORT void DLL_APIENTRY Transparency(unsigned int Alpha)
	{
		gc_alpha = Alpha;
	}

	/*================================================================
	Cambia el color.*/

	DLL_EXPORT void DLL_APIENTRY Colors(unsigned int R,unsigned int G,unsigned int B)
	{
		gc_red = R;
		gc_green = G;
		gc_blue = B;
	}

	/*================================================================
	Muestra una imagen que previamente ha sido cargada.*/

	DLL_EXPORT void DLL_APIENTRY Image(const ITexture* texture,int X,int Y)
	{
		int W = texture->getOriginalSize().Width;
		int H = texture->getOriginalSize().Height;
		driver->draw2DImage(texture,position2d<s32>(X,Y),rect<s32>(0,0,W,H),0,SColor(gc_alpha,gc_red,gc_green,gc_blue),true);
	}


		/*================================================================
	Muestra una imagen que previamente ha sido cargada ---added by nespa.*/

	DLL_EXPORT void DLL_APIENTRY ImageSprites2D(const ITexture* texture,int X,int Y,int TX, int TY, int BX, int BY )

	{
		driver->draw2DImage(texture,position2d<s32>(X,Y),rect< s32 >(TX,TY,BX,BY),0,SColor(gc_alpha,gc_red,gc_green,gc_blue),true);
	}	
	/*================================================================
	Dibuja un rectangulo.*/

	DLL_EXPORT void DLL_APIENTRY Rect2D(int X,int Y,int Width,int Height)
	{
		driver->draw2DRectangle(SColor(gc_alpha,gc_red,gc_green,gc_blue),rect<s32>(X,Y,X+Width,Y+Height));
	}

	/*================================================================
	Dibuja una linea recta.*/

	DLL_EXPORT void DLL_APIENTRY Line2D(int X1,int Y1,int X2,int Y2)
	{
		driver->draw2DLine(position2d<s32>(X1,Y1),position2d<s32>(X2,Y2),SColor(gc_alpha,gc_red,gc_green,gc_blue));
	}

	/*================================================================
	Dibuja un pixel.*/

	DLL_EXPORT void DLL_APIENTRY Pixel(int X,int Y)
	{
		driver->drawPixel(X,Y,SColor(gc_alpha,gc_red,gc_green,gc_blue));
	}

	/*================================================================
	Dibuja un circulo.*/

	DLL_EXPORT void DLL_APIENTRY Oval(int X,int Y,float Radius)
	{
		driver->draw2DPolygon(position2d<s32>(X,Y),Radius,SColor(gc_alpha,gc_red,gc_green,gc_blue),32);
	}

	/*================================================================
	Dibuja una linea en el espacio en 3D* ---by nespa */

	DLL_EXPORT void DLL_APIENTRY Line3D(float sx,float sy,float sz,float ex,float ey,float ez,float t,unsigned int A,unsigned int R,unsigned int G,unsigned int B)
	{
		
		
		video::SMaterial material;
		material.setFlag(EMF_LIGHTING, false);
		material.setFlag(EMF_FOG_ENABLE, true);
		material.MaterialType=EMT_TRANSPARENT_ALPHA_CHANNEL;
		material.Thickness = t;
		driver->setMaterial(material);
		driver->setTransform(ETS_WORLD, core::IdentityMatrix);
		driver->draw3DLine(vector3df(sx,sy,sz),vector3df(ex,ey,ez),SColor(A,R,G,B));

	
	}

}