/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///																																  ///
///		FICHIER :	ZooTexture.h																								  ///
///																																  ///
///		NATURE	:	Defines the class to manipulate ans product opengl texture for the textured material of the scene    		  ///
///																																  ///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





#ifndef __ZOOTEXTURE_H__
#define __ZOOTEXTURE_H__





#include	"..\Basic\ZooStd.h"

#include	"..\Loaders\PNG\png.h"
#include	"..\Loaders\PNG\readpng.h"


// Filter constants

const int TF_NONE		= 0;
const int TF_LINEAR		= 1;
const int TF_BILINEAR	= 2;
const int TF_TRILINEAR	= 3;






///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ZTexture Class
///
///		- Classe des textures : Image, filtre, et taille
///		- Méthodes pour le set des composantes et pour le chargement d'un BMP ou JPG
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class ZTexture : public ZData
{
protected:

	unsigned char	transpR , transpG , transpB , rate ;

public:

	int				Width;				// width
	int				Height;				// height

	unsigned char	*Image;				// memory block for the bitmap from the file
	unsigned char	*ImageModif;		// memory block for the bitmap modified

	int				filter;				// filtre NONE, LINEAR, BILINEAR

	unsigned int	texID;
	bool			ID_created;

	string			filename;

    bool			modified;			// flag of texture's properties modification

	bool			renamed;			// flag for describing if the texture has been renamed (so, if the flags as been changed)

	bool			activated;			// flag for describing the state of the texture (if u can use it or not)

	bool			accelerated;

	//$LB
	unsigned char            *bitmap24;



	
	// Filtres appliqués aux textures
	bool			C , X , Y , A , R , S ;				// A -> couleur de transparence
	int				value;



	///////////////////////////////////////////////////////////////////////////
	/// Constructor					 										///
	///////////////////////////////////////////////////////////////////////////
	ZTexture(bool accel);

	///////////////////////////////////////////////////////////////////////////
	/// Destructor					 										///
	///////////////////////////////////////////////////////////////////////////
	~ZTexture();


	///////////////////////////////////////////////////////////////////////////
	/// SetTextureFilter													///
	///////////////////////////////////////////////////////////////////////////
	void SetTextureFilter(int newfilter);
	//$BLG
	void BLG_SetTextureFilter(int newfilter);
	void BLG_SetupTexture();

	void SetTranspR(int tR)			{	transpR = tR;	}
	void SetTranspG(int tG)			{	transpG = tG;	}
	void SetTranspB(int tB)			{	transpB = tB;	}
	void SetRate(int r)				{	rate = r;		}

	int	 GetTranspR()				{	return transpR;	}
	int	 GetTranspG()				{	return transpG;	}
	int	 GetTranspB()				{	return transpB;	}
	int	 GetRate()					{	return rate;	}


	///////////////////////////////////////////////////////////////////////////
	/// Set the openGL parameters for the texture							///
	///////////////////////////////////////////////////////////////////////////
	void SetupTexture();

	bool StretchImage();
	bool StretchImageModif();

	
	///////////////////////////////////////////////////////////////////////////
	/// Loads a texture and returns the OpenGL index reference 				///
	///////////////////////////////////////////////////////////////////////////
	bool LoadTexture(char *filename);//, bool transpColor, unsigned char Red, unsigned char Green, unsigned char Blue, unsigned char tolerance);
	void SetParams(bool CC, bool XX, bool YY, bool AA, bool RR, bool SS, unsigned char Red, unsigned char Green, unsigned char Blue, unsigned char raterate);

	bool CreateModifiedImg();
	bool CreateModifiedImg_WithoutLoading_A();


	///////////////////////////////////////////////////////////////////////////
	/// Loads the image texture												///
	///////////////////////////////////////////////////////////////////////////
	bool LoadBMPTexture(char *filename);
	bool LoadJPGTexture(char *filename);
	bool LoadPNGTexture(char *filename);


	///////////////////////////////////////////////////////////////////////////
	/// Put the GL parameters  (obsolete)									///
	///////////////////////////////////////////////////////////////////////////
	void PutGLparams();

	////////////////////////////////////////////////////////////////////////////
	/// Pour le multitexturing												///
	///////////////////////////////////////////////////////////////////////////

	void PutGLMultiparams0();
	void PutGLMultiparams1();
	void PutGLMultiparams2();




	void SetFileName(char * newName);
	void SetFileName(string newName);


};




inline void ZTexture::SetParams(bool CC, bool XX, bool YY, bool AA, bool RR, bool SS, unsigned char Red, unsigned char Green, unsigned char Blue, unsigned char raterate)
{
	C = CC;
	X = XX;
	A = AA;
	R = RR;
	S = SS;

	transpR = Red;
	transpG = Green;
	transpB = Blue;

	rate = raterate;

	modified = true;
}




#endif