// Author : Chris Tolley
// Date   : 2/21/2004
// texture.h contains a bitmap texture class to use with OpenGL

#ifndef TEXTURE_H
#define TEXTURE_H

#include <windows.h>
#include <vector>
using std::vector;

class texture
{
public:
	// Constructor
	texture() {};

	// Constructor with argument.  filename is the name of the 
	// file that holds the bitmap
	texture( const char* filename );

	// Destructor
	virtual ~texture();

	// Loads a bitmap into memory from filename
	void load( const char* filename );

	// Points r,g,b to the RGB values of the (x,z)th pixel
	void getPixel( int x, int z, unsigned char& r, unsigned char& g,
													unsigned char& b );

	// Points r,g,b to the RGB values of the (x,z)th pixel after wrapping
	// x,z around like this texture was tilted
	void getTitledPixel( int x, int z, unsigned char& r, unsigned char& g,
													unsigned char& b );

	// Tells OpenGL to use this texture when rendering any
	// 2d texture coordinates
	virtual void select() const;

	// Tells OpenGL to use the default texture
	virtual void deselect() const;

	// Returns the height data
	virtual vector< unsigned char >& GetData();

	// Returns the height of this texture
	inline int GetHeight() const { return infoHeader_.biHeight; };

	// Returns the width of this texture
	inline int GetWidth() const { return infoHeader_.biWidth; };

	// Returns a pointer to the pixel at x,y
	unsigned char* At( const int x, const int y ) 
	{ return &data_[ ( y * infoHeader_.biWidth + x ) * 3 ]; };
protected:
	// A bitmap infomation header to store the information of the bitmap
	BITMAPINFOHEADER infoHeader_;

	// The actual color data.
	vector< unsigned char > data_;

	// The id of this texture.  OpenGL uses this and is set
	// by OpenGL in the glGenTexture function call.
	unsigned int id_;
};

#endif