void OpenGLRender::blitLine(int pX1,
                            int pY1,
                            int pX2,
                            int pY2,
                            unsigned char pR,
                            unsigned char pG,
                            unsigned char pB,
                            unsigned char pA) {
	float r(static_cast<float>(pR) / 255.0f), g(static_cast<float>(pG) / 255.0f), b(static_cast<float>(pB) / 255.0f), a(static_cast<float>(pA) / 255.0f);
	//Fill the PIXEL structure
	fillPixel(&_pixels[0], static_cast<float>(pX1), static_cast<float>(pY1), r, g, b, a);
	fillPixel(&_pixels[1], static_cast<float>(pX2), static_cast<float>(pY2), r, g, b, a);

	//Render primitive - No textures
	setGLClientStateToPrimitive();

	// Color and transformation
	setForPrimitive(pA,true);

	//Line blitting
	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_LINES, 0, 2);

	
#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in Line blitting ", DebugApi::LogHeaderError);
	}
#endif

    //Reenable texturing
	setGLClientStateToTexturing();
}
/*!
\b Parameters:

\arg \b pX, \b pY                   Position in the screen
\arg \b pRadius                     Radius
\arg \b pN                          Number of sides
\arg \b pAngle                      Angle in degrees (if you change this parameter the polygon
                                    will rotate)
\arg \b pR, \b pG, \b pB            R, G, B components of the color
\arg \b pA                          Level of transparency. (255 = completly opaque)

\b Operation:

This function draws 2d regunr poly of n sides. If you need to draw circles you can use this method
using 30 or more sides.

This method is equivalent to use a combination of these methods:
- IND_Entity2d::setPrimitive2d()
- IND_Entity2d::setRadius()
- IND_Entity2d::setPosition()
- IND_Entity2d::setTint()
- IND_Entity2d::setTransparency()
*/
bool DirectXRender::blitRegularPoly(int pX,
                                    int pY,
                                    int pRadius,
                                    int pN,
                                    float pAngle,
                                    BYTE pR,
                                    BYTE pG,
                                    BYTE pB,
                                    BYTE pA) {
	int x, y, i;

	for (i = 0; i < pN; i++) {
		float c = i * 2 * (float)(PI / pN);
		x = (int)(pX + (pRadius * cos(c + D3DXToRadian(pAngle))));
		y = (int)(pY + (pRadius * sin(c + D3DXToRadian(pAngle))));

		fillPixel(&_pixels [i], x, y, pR, pG, pB);
	}

	fillPixel(&_pixels [i], pX + (int)(pRadius * cos(D3DXToRadian(pAngle))), pY + (int)(pRadius * sin(D3DXToRadian(pAngle))), pR, pG, pB);

	// Transformation
	setForPrimitive(pA);

	// Polygon blitting
	_info._device->DrawPrimitiveUP(D3DPT_LINESTRIP, i, &_pixels, sizeof(PIXEL));

	return 1;
}
/*
==================
Blits a bounding line
==================
*/
 void OpenGLRender::blitGridLine (int pPosX1, int pPosY1, int pPosX2, int pPosY2,  BYTE pR, BYTE pG, BYTE pB, BYTE pA)
{	
	float r(static_cast<float>(pR) / 255.0f), g(static_cast<float>(pG) / 255.0f), b(static_cast<float>(pB) / 255.0f), a(static_cast<float>(pA) / 255.0f);
	// Filling pixels
    fillPixel (&_pixels[0], static_cast<float>(pPosX1), static_cast<float>(pPosY1), r, g, b, a);
    fillPixel (&_pixels[1], static_cast<float>(pPosX2), static_cast<float>(pPosY2), r, g, b, a);

	//Render primitive - No textures
	glDisable(GL_TEXTURE_2D);
	// Color settings
    setRainbow2d (IND_OPAQUE, 1, 0, 0, IND_FILTER_POINT, pR, pG, pB, pA, 0, 0, 0, 255, 0, 0);

	//Blitting
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);

	//Polygon blitting
	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_LINE_STRIP, 0, 2);

#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in grid line blitting ", 2);
	}
#endif
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);	
}
/*
==================
Blits a bounding line
==================
*/
 void OpenGLRender::blitGridLine (int pPosX1, int pPosY1, int pPosX2, int pPosY2,  unsigned char pR, unsigned char pG, unsigned char pB, unsigned char pA)
{	
	float r(static_cast<float>(pR) / 255.0f), g(static_cast<float>(pG) / 255.0f), b(static_cast<float>(pB) / 255.0f), a(static_cast<float>(pA) / 255.0f);
	// Filling pixels
    fillPixel (&_pixels[0], static_cast<float>(pPosX1), static_cast<float>(pPosY1), r, g, b, a);
    fillPixel (&_pixels[1], static_cast<float>(pPosX2), static_cast<float>(pPosY2), r, g, b, a);

	//Render primitive - No textures
	setGLClientStateToPrimitive();
    
	// Color settings
    setRainbow2d (IND_OPAQUE, 1, 0, 0, IND_FILTER_POINT, pR, pG, pB, pA, 0, 0, 0, 255, 0, 0);

	//Polygon blitting
	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_LINE_STRIP, 0, 2);

#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in grid line blitting ", DebugApi::LogHeaderError);
	}
#endif

    //Reenable texturing
	setGLClientStateToTexturing();
}
/*
==================
Blits a bounding line
==================
*/
void DirectXRender::BlitGridLine(int pPosX1, int pPosY1, int pPosX2, int pPosY2,  BYTE pR, BYTE pG, BYTE pB, BYTE pA, D3DXMATRIX pWorldMatrix) {
	setTransform2d(0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0);

	// Untransformed Points
	D3DXVECTOR2 mP1Untransformed((float) pPosX1, (float) pPosY1);
	D3DXVECTOR2 mP2Untransformed((float) pPosX2, (float) pPosY2);

	D3DXVECTOR4 mP1, mP2;
	D3DXVec2Transform(&mP1, &mP1Untransformed, &pWorldMatrix);
	D3DXVec2Transform(&mP2, &mP2Untransformed, &pWorldMatrix);

	// Color
	setRainbow2d(IND_OPAQUE, 1, 0, 0, IND_FILTER_POINT, pR, pG, pB, pA, 0, 0, 0, 255, 0, 0);

	// Color
	_info._device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);

	// Pixel format
	_info._device->SetFVF(D3DFVF_PIXEL);

	// Filling pixels
	fillPixel(&_pixels [0], (int) mP1.x, (int) mP1.y, pR, pG, pB);
	fillPixel(&_pixels [1], (int) mP2.x, (int) mP2.y, pR, pG, pB);

	// Blitting line
	_info._device->DrawPrimitiveUP(D3DPT_LINESTRIP, 1, &_pixels, sizeof(PIXEL));
}
bool OpenGLRender::blitRegularPoly(int pX,
                                   int pY,
                                   int pRadius,
                                   int pN,
                                   float pAngle,
                                   BYTE pR,
                                   BYTE pG,
                                   BYTE pB,
                                   BYTE pA) {
	int x, y, i;
	float r(static_cast<float>(pR) / 255.0f), g(static_cast<float>(pG) / 255.0f), b(static_cast<float>(pB) / 255.0f), a(static_cast<float>(pA) / 255.0f);

	//LOOP - Fill pixels structure
	for (i = 0; i < pN; i++) {
		float c = i * 2 * static_cast<float>(PI / pN);
		x = static_cast<int>(pX + (pRadius * cos(c + _math.angleToRadians(pAngle))));
		y = static_cast<int>(pY + (pRadius * sin(c + _math.angleToRadians(pAngle))));

		fillPixel(&_pixels [i], static_cast<float>(x), static_cast<float>(y), r, g, b, a);
	}//LOOP END

	fillPixel(&_pixels [i], pX + (pRadius * cos(_math.angleToRadians(pAngle))), pY + (pRadius * sin(_math.angleToRadians(pAngle))), r, g, b, a);
	
	//Render primitive - No textures
	glDisable(GL_TEXTURE_2D);

	// Color and transformation
	setForPrimitive(pA,true);

	//Blitting
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);

	//Polygon blitting
	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_LINE_STRIP, 0, pN+1);

#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in triangle list blitting ", 2);
	}
#endif
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);

	return 1;
}
void OpenGLRender::blitPixel(int pX,
                             int pY,
                             BYTE pR,
                             BYTE pG,
                             BYTE pB,
                             BYTE pA) {
	
	float r(static_cast<float>(pR) / 255.0f), g(static_cast<float>(pG) / 255.0f), b(static_cast<float>(pB) / 255.0f), a(static_cast<float>(pA) / 255.0f);
	// Fill the PIXEL structure
	fillPixel (&_pixels [0], static_cast<float>(pX), static_cast<float>(pY), r, g, b, a);
	
	//Render primitive - No textures
	glDisable(GL_TEXTURE_2D);

	// Color and transformation
	setForPrimitive (pA, true);

	// Pixel drawing
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_POINTS, 0,1);	

	
#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in pixel blitting ", 2);
	}
#endif	

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
}
void OpenGLRender::blitColoredTriangle(int pX1,
                                       int pY1,
                                       int pX2,
                                       int pY2,
                                       int pX3,
                                       int pY3,
                                       BYTE pR1, BYTE pG1, BYTE pB1,
                                       BYTE pR2, BYTE pG2, BYTE pB2,
                                       BYTE pR3, BYTE pG3, BYTE pB3,
                                       BYTE pA) {
	
    float r1(static_cast<float>(pR1) / 255.0f), g1(static_cast<float>(pG1) / 255.0f), b1(static_cast<float>(pB1) / 255.0f);
    float r2(static_cast<float>(pR2) / 255.0f), g2(static_cast<float>(pG2) / 255.0f), b2(static_cast<float>(pB2) / 255.0f);
    float r3(static_cast<float>(pR3) / 255.0f), g3(static_cast<float>(pG3) / 255.0f), b3(static_cast<float>(pB3) / 255.0f);
    float a(static_cast<float>(pA) / 255.0f);
	
    // Fill PIXEL structures
	fillPixel (&_pixels[0], static_cast<float>(pX1), static_cast<float>(pY1), r1, g1, b1, a);
	fillPixel (&_pixels[1], static_cast<float>(pX2), static_cast<float>(pY2), r2, g2, b2, a);
	fillPixel (&_pixels[2], static_cast<float>(pX3), static_cast<float>(pY3), r3, g3, b3, a);

	//Render primitive - No textures
	glDisable(GL_TEXTURE_2D);

	// Color and transformation
	setForPrimitive(pA,true);

	//Single Colored Triangle blitting
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);

	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_TRIANGLES, 0, 3);

#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in colored triangle blitting ", 2);
	}
#endif
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);

}
/*!
\b Parameters:

\arg \b pX1, \b pY1             Origin point
\arg \b pX2, pY2                Destiny point
\arg \b pR, \b pG, \b pB        R, G, B components of the color
\arg \b pA                      Level of transparency. (255 = completly opaque)

\b Operation:

This function draws a line into the screen

Using this method is equivalent to using all of these methods:
- IND_Entity2d::setPrimitive2d()
- IND_Entity2d::setLine()
- IND_Entity2d::setTint()
- IND_Entity2d::setTransparency()
*/
void DirectXRender::blitLine(int pX1,
                             int pY1,
                             int pX2,
                             int pY2,
                             BYTE pR,
                             BYTE pG,
                             BYTE pB,
                             BYTE pA) {
	// Fill the PIXEL structure
	fillPixel(&_pixels [0], pX1, pY1, pR, pG, pB);
	fillPixel(&_pixels [1], pX2, pY2, pR, pG, pB);

	// Transformation
	setForPrimitive(pA);

	// Line blitting
	_info._device->DrawPrimitiveUP(D3DPT_LINESTRIP, 1, &_pixels, sizeof(PIXEL));
}
void OpenGLRender::blitColoredTriangle(int pX1,
                                       int pY1,
                                       int pX2,
                                       int pY2,
                                       int pX3,
                                       int pY3,
                                       unsigned char pR1, unsigned char pG1, unsigned char pB1,
                                       unsigned char pR2, unsigned char pG2, unsigned char pB2,
                                       unsigned char pR3, unsigned char pG3, unsigned char pB3,
                                       unsigned char pA) {
	
    float r1(static_cast<float>(pR1) / 255.0f), g1(static_cast<float>(pG1) / 255.0f), b1(static_cast<float>(pB1) / 255.0f);
    float r2(static_cast<float>(pR2) / 255.0f), g2(static_cast<float>(pG2) / 255.0f), b2(static_cast<float>(pB2) / 255.0f);
    float r3(static_cast<float>(pR3) / 255.0f), g3(static_cast<float>(pG3) / 255.0f), b3(static_cast<float>(pB3) / 255.0f);
    float a(static_cast<float>(pA) / 255.0f);
	
    // Fill PIXEL structures
	fillPixel (&_pixels[0], static_cast<float>(pX1), static_cast<float>(pY1), r1, g1, b1, a);
	fillPixel (&_pixels[1], static_cast<float>(pX2), static_cast<float>(pY2), r2, g2, b2, a);
	fillPixel (&_pixels[2], static_cast<float>(pX3), static_cast<float>(pY3), r3, g3, b3, a);

	//Render primitive - No textures
	setGLClientStateToPrimitive();

	// Color and transformation
	setForPrimitive(pA,true);

	//Single Colored Triangle blitting
	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_TRIANGLES, 0, 3);

#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in colored triangle blitting ", DebugApi::LogHeaderError);
	}
#endif

    //Reenable texturing
	setGLClientStateToTexturing();
}
void OpenGLRender::blitRectangle(int pX1,
                                 int pY1,
                                 int pX2,
                                 int pY2,
                                 BYTE pR,
                                 BYTE pG,
                                 BYTE pB,
                                 BYTE pA) {
	float r(static_cast<float>(pR) / 255.0f), g(static_cast<float>(pG) / 255.0f), b(static_cast<float>(pB) / 255.0f), a(static_cast<float>(pA) / 255.0f);
 	
	// Fill PIXEL structures
	fillPixel (&_pixels [0], static_cast<float>(pX1),static_cast<float>(pY1),      r, g, b,a);
	fillPixel (&_pixels [1], static_cast<float>(pX2), static_cast<float>(pY1),      r, g, b,a);
	fillPixel (&_pixels [2], static_cast<float>(pX2), static_cast<float>(pY2),      r, g, b,a);
	fillPixel (&_pixels [3], static_cast<float>(pX1), static_cast<float>(pY2),      r, g, b,a);
	fillPixel (&_pixels [4], static_cast<float>(pX1), static_cast<float>(pY1),      r, g, b,a);
	
	//Render primitive - No textures
	glDisable(GL_TEXTURE_2D);

	// Color and transformation
	setForPrimitive (pA,true);

	//rectangle blitting
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_LINE_STRIP, 0, 5);

#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in rectangle blitting ", 2);
	}
#endif

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);

}
/*!
\b Parameters:

\arg \b pX1, \b pY1                 Upper left corner of the rectangle
\arg \b pX2, \b pY2                 Lower right corner of the rectangle
\arg \b pR, \b pG, \b pB            R, G, B components of the color
\arg \b pA                          Level of transparency. (255 = completly opaque)

\b Operation:

This function draws a rectangle filled with a color into the screen. The A component is the
transparency level (255 = complety opaque).

Using this method is equivalent to using all of these methods:
- IND_Entity2d::setPrimitive2d()
- IND_Entity2d::setRectangle()
- IND_Entity2d::setTint()
- IND_Entity2d::setTransparency()
*/
void DirectXRender::blitFillRectangle(int pX1,
                                      int pY1,
                                      int pX2,
                                      int pY2,
                                      BYTE pR,
                                      BYTE pG,
                                      BYTE pB,
                                      BYTE pA) {
	// Fill PIXEL structures
	fillPixel(&_pixels [0], pX2, pY1,      pR, pG, pB);
	fillPixel(&_pixels [1], pX2, pY2,      pR, pG, pB);
	fillPixel(&_pixels [2], pX1, pY1,      pR, pG, pB);
	fillPixel(&_pixels [3], pX1, pY2,      pR, pG, pB);

	// Transformation
	//setTransform2d(0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0);

	// Color transformation
	setForPrimitive(pA);

	// Rectangle blitting
	_info._device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, &_pixels, sizeof(PIXEL));
}
/*
==================
Blits a bounding circle area
==================
*/
void DirectXRender::blitCollisionCircle(int pPosX, int pPosY, int pRadius, float pScale,  BYTE pR, BYTE pG, BYTE pB, BYTE pA, IND_Matrix pIndWorldMatrix) {
	if (pScale != 1.0f) pRadius = (int)(pRadius * pScale);

	setTransform2d(0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0);


	IND_Vector3 mP1 (static_cast<float>(pPosX),static_cast<float>(pPosY),0.0f);
	_math->transformVector3DbyMatrix4D(mP1,pIndWorldMatrix);

	// Color
	setRainbow2d(IND_OPAQUE, 1, 0, 0, IND_FILTER_POINT, pR, pG, pB, pA, 0, 0, 0, 255, 0, 0);

	// Color
	_info._device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);

	// Pixel format
	_info._device->SetFVF(D3DFVF_PIXEL);

	// Blitting
	int x, y, i;
	float c = 2 * (float)(PI / SIDES_PER_CIRCLE);
	int points (SIDES_PER_CIRCLE + 1);
	assert (0 != points);
	for (i = 0; i <= points; i++) {
		
		x = (int)(mP1._x + (pRadius * cos((i * c) + D3DXToRadian(0))));
		y = (int)(mP1._y + (pRadius * sin((i* c) + D3DXToRadian(0))));

		fillPixel(&_pixels [i], x, y, pR, pG, pB);
	}

	fillPixel(&_pixels [i], (int) mP1._x + (int)(pRadius * cos(D3DXToRadian(0))), (int) mP1._y + (int)(pRadius * sin(D3DXToRadian(0))), pR, pG, pB);

	// Blitting circle
	_info._device->DrawPrimitiveUP(D3DPT_LINESTRIP, points, &_pixels, sizeof(PIXEL));
}
/*
==================
Blits a bounding line
==================
*/
void DirectXRender::blitCollisionLine(int pPosX1, int pPosY1, int pPosX2, int pPosY2,  BYTE pR, BYTE pG, BYTE pB, BYTE pA, IND_Matrix pIndWorldMatrix) {
	setTransform2d(0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0);

	IND_Vector3 mP1 (static_cast<float>(pPosX1),static_cast<float>(pPosY1),0.0f);
	IND_Vector3 mP2 (static_cast<float>(pPosX2),static_cast<float>(pPosY2),0.0f);
	_math->transformVector3DbyMatrix4D(mP1,pIndWorldMatrix);
	_math->transformVector3DbyMatrix4D(mP2,pIndWorldMatrix);

	// Color
	setRainbow2d(IND_OPAQUE, 1, 0, 0, IND_FILTER_POINT, pR, pG, pB, pA, 0, 0, 0, 255, 0, 0);

	// Color
	_info._device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);

	// Pixel format
	_info._device->SetFVF(D3DFVF_PIXEL);

	// Filling pixels
	fillPixel(&_pixels [0], (int) mP1._x, (int) mP1._y, pR, pG, pB);
	fillPixel(&_pixels [1], (int) mP2._x, (int) mP2._y, pR, pG, pB);

	// Blitting line
	_info._device->DrawPrimitiveUP(D3DPT_LINESTRIP, 1, &_pixels, sizeof(PIXEL));
}
void DirectXRender::blitColoredTriangle(int pX1,
                                        int pY1,
                                        int pX2,
                                        int pY2,
                                        int pX3,
                                        int pY3,
                                        BYTE pR1, BYTE pG1, BYTE pB1,
                                        BYTE pR2, BYTE pG2, BYTE pB2,
                                        BYTE pR3, BYTE pG3, BYTE pB3,
                                        BYTE pA) {
	// Fill PIXEL structures
	fillPixel(&_pixels [0], pX1, pY1, pR1, pG1, pB1);
	fillPixel(&_pixels [1], pX2, pY2, pR2, pG2, pB2);
	fillPixel(&_pixels [2], pX3, pY3, pR3, pG3, pB3);

	// Transformation
	//setTransform2d(0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0);

	// Color transformation
	setForPrimitive(pA);

	// Rectangle blitting
	_info._device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, &_pixels, sizeof(PIXEL));
}
/*!
\b Parameters:

\arg \b pX, \b pY               Position in the screen
\arg \b pR, \b pG, \b pB        R, G, B components of the color
\arg \b pA                      Level of transparency. (255 = completly opaque)

\b Operation:

This function draws a pixel into the screen. This is a really slow method when the number of pixels is
big.

This method is equivalent to use a combination of these methods:
- IND_Entity2d::setPrimitive2d()
- IND_Entity2d::setLine()
- IND_Entity2d::setTint()
- IND_Entity2d::setTransparency()
*/
void DirectXRender::blitPixel(int pX,
                              int pY,
                              BYTE pR,
                              BYTE pG,
                              BYTE pB,
                              BYTE pA) {

	// Fill the PIXEL structure
	fillPixel(&_pixels [0], pX, pY, pR, pG, pB);

	// Transformation
	setForPrimitive(pA);

	// Pixel drawing
	_info._device->DrawPrimitiveUP(D3DPT_POINTLIST, 1, &_pixels, sizeof(PIXEL));
}
void OpenGLRender::blitTriangleList(IND_Point *pTrianglePoints,
                                    int pNumPoints,
                                    BYTE pR,
                                    BYTE pG,
                                    BYTE pB,
                                    BYTE pA) {

	//TODO: CHECK MAX POLYGONS PER CALL...
	if (pNumPoints < 3)
		return;

    float r(static_cast<float>(pR) / 255.0f), g(static_cast<float>(pG) / 255.0f), b(static_cast<float>(pB) / 255.0f), a(static_cast<float>(pA) / 255.0f);

	//LOOP - Fill pixels structure
	for (int i = 0; i < pNumPoints; i++) {
		fillPixel(&_pixels[i], static_cast<float>(pTrianglePoints[i].x), static_cast<float>(pTrianglePoints[i].y), r, g, b, a);
	}//LOOP END

	//Render primitive - No textures
	glDisable(GL_TEXTURE_2D);

	// Color and transformation
	setForPrimitive(pA,true);

	//Triangle strip blitting
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);

	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, pNumPoints);

#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in triangle list blitting ", 2);
	}
#endif
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);

}
bool OpenGLRender::blitPoly2d(IND_Point *pPolyPoints,
                              int pNumLines,
                              BYTE pR,
                              BYTE pG,
                              BYTE pB,
                              BYTE pA) {

	if (!pPolyPoints)   return 0;
	if (pNumLines < 1)  return 0;

    float r(static_cast<float>(pR) / 255.0f), g(static_cast<float>(pG) / 255.0f), b(static_cast<float>(pB) / 255.0f), a(static_cast<float>(pA) / 255.0f);

	// Fill PIXEL structures
    for (int i = 0; i < pNumLines + 1; i++){
	    fillPixel (&_pixels [i], static_cast<float>(pPolyPoints [i].x), static_cast<float>(pPolyPoints [i].y), r, g, b,a);
    }

	//Render primitive - No textures
	glDisable(GL_TEXTURE_2D);

	// Color and transformation
	setForPrimitive(pA,true);

	// Polygon blitting
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);

	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_LINE_STRIP, 0, pNumLines+1);

#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in triangle poly2d blitting ", 2);
	}
#endif
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);

	return 1;
}
/*
==================
Blits a bounding circle area
==================
*/
void OpenGLRender::blitCollisionCircle(int pPosX, int pPosY, int pRadius, float pScale,  BYTE pR, BYTE pG, BYTE pB, BYTE pA, IND_Matrix pIndWorldMatrix) {
	float r(static_cast<float>(pR) / 255.0f), g(static_cast<float>(pG) / 255.0f), b(static_cast<float>(pB) / 255.0f), a(static_cast<float>(pA) / 255.0f);

	// Filling pixels
	float x (0.0f);
	float y (0.0f);
	int points (SIDES_PER_CIRCLE + 1);
	assert(0 != points);
	float angle (2*PI / SIDES_PER_CIRCLE);
	for (int i = 0; i <= points ; i++) {
		x = pPosX + (pRadius * cosf(angle*i));
		y = pPosY + (pRadius * sinf(angle*i));
		fillPixel (&_pixels[i], x, y, r, g, b, a);
	}
    
	//Render primitive - No textures
	glDisable(GL_TEXTURE_2D);
	//Transform
	setTransform2d(pIndWorldMatrix);

	// Color settings
    setRainbow2d (IND_OPAQUE, 1, 0, 0, IND_FILTER_POINT, pR, pG, pB, pA, 0, 0, 0, 255, 0, 0);

	//Blitting
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);

	//Polygon blitting
	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_LINE_STRIP, 0, points);

#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in circle blitting ", 2);
	}
#endif
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);	

}
/*!
\b Parameters:

\arg \b pPixel                      Pointer to a points array ::IND_Point. Example: ::IND_Point mPoly3 [ ] = { {60, 10},  {20, 15},  {50, 90},  {170, 190} } => Sets 3 points (each one with x and y coordinates).
\arg \b pNumLines                   Number of edges to draw
\arg \b pR, \b pG, \b pB            R, G, B components of the color
\arg \b pA                          Level of transparency. (255 = completly opaque)

\b Operation:

This function draws a 2d poly

Using this method is equivalent to using all of these methods:
- IND_Entity2d::setPrimitive2d()
- IND_Entity2d::setPolyPoints()
- IND_Entity2d::setNumSides()
- IND_Entity2d::setTint()
- IND_Entity2d::setTransparency()
*/
bool DirectXRender::blitPoly2d(IND_Point *pPolyPoints,
                               int pNumLines,
                               BYTE pR,
                               BYTE pG,
                               BYTE pB,
                               BYTE pA) {
	if (!pPolyPoints)   return 0;
	if (pNumLines < 1)  return 0;

	// Fill PIXEL structures
	for (int i = 0; i < pNumLines + 1; i++)
		fillPixel(&_pixels [i], pPolyPoints [i].x, pPolyPoints [i].y, pR, pG, pB);

	// Transformation
	setForPrimitive(pA);

	// Polygon blitting
	_info._device->DrawPrimitiveUP(D3DPT_LINESTRIP, pNumLines, &_pixels, sizeof(PIXEL));

	return 1;
}
/*!
\b Parameters:

\arg \b pTrianglePoints             Triangle Points allocated array
\arg \b pNumPoints                  Number of points passed (numtriangles =  pNumPoints - 2)
\arg \b pR, \b pG, \b pB            R, G, B components of the color in outer vertexs
\arg \b pA                          Level of transparency. (255 = completly opaque)

\b Operation:

This function draws a complete triangle fan. The triangle fan is a set of triangles which
share a central vertex (http://msdn.microsoft.com/en-us/library/ee422512(VS.85).aspx)
The A parameter is transparency (255 = complety opaque).
*/
void DirectXRender::blitTriangleList(IND_Point *pTrianglePoints,
                                     int pNumPoints,
                                     BYTE pR,
                                     BYTE pG,
                                     BYTE pB,
                                     BYTE pA) {
	//TODO: CHECK MAX POLYGONS PER CALL...  mD3dcap.MaxPrimitiveCount
	if (pNumPoints < 3)
		return;

	//LOOP - Fill pixels structure
	for (int i = 0; i < pNumPoints; i++) {
		fillPixel(&_pixels[i], pTrianglePoints[i].x, pTrianglePoints[i].y, pR, pG, pB);
	}//LOOP END

	//Transformation
	setForPrimitive(pA);

	//Blitting
	_info._device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, pNumPoints - 2, &_pixels, sizeof(PIXEL));
}
void OpenGLRender::blitTriangleList(IND_Point *pTrianglePoints,
                                    int pNumPoints,
                                    unsigned char pR,
                                    unsigned char pG,
                                    unsigned char pB,
                                    unsigned char pA) {

	//TODO: CHECK MAX POLYGONS PER CALL...
	if (pNumPoints < 3)
		return;

    float r(static_cast<float>(pR) / 255.0f), g(static_cast<float>(pG) / 255.0f), b(static_cast<float>(pB) / 255.0f), a(static_cast<float>(pA) / 255.0f);

	//LOOP - Fill pixels structure
	for (int i = 0; i < pNumPoints; i++) {
		fillPixel(&_pixels[i], static_cast<float>(pTrianglePoints[i].x), static_cast<float>(pTrianglePoints[i].y), r, g, b, a);
	}//LOOP END

	//Render primitive - No textures
	setGLClientStateToPrimitive();

	// Color and transformation
	setForPrimitive(pA,true);

	//Triangle strip blitting
	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, pNumPoints);

#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in triangle list blitting ", DebugApi::LogHeaderError);
	}
#endif

    //Reenable texturing
	setGLClientStateToTexturing();
}
bool OpenGLRender::blitPoly2d(IND_Point *pPolyPoints,
                              int pNumLines,
                              unsigned char pR,
                              unsigned char pG,
                              unsigned char pB,
                              unsigned char pA) {

	if (!pPolyPoints)   return 0;
	if (pNumLines < 1)  return 0;

    float r(static_cast<float>(pR) / 255.0f), g(static_cast<float>(pG) / 255.0f), b(static_cast<float>(pB) / 255.0f), a(static_cast<float>(pA) / 255.0f);

	// Fill PIXEL structures
    for (int i = 0; i < pNumLines + 1; i++){
	    fillPixel (&_pixels [i], static_cast<float>(pPolyPoints [i].x), static_cast<float>(pPolyPoints [i].y), r, g, b,a);
    }

	//Render primitive - No textures
	setGLClientStateToPrimitive();

	// Color and transformation
	setForPrimitive(pA,true);

	// Polygon blitting
	glVertexPointer(3, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._x);
	glColorPointer(4, GL_FLOAT, sizeof(PIXEL), &_pixels[0]._colorR);
	glDrawArrays(GL_LINE_STRIP, 0, pNumLines+1);

#ifdef _DEBUG
    GLenum glerror = glGetError();
	if (glerror) {
		g_debug->header("OpenGL error in triangle poly2d blitting ", DebugApi::LogHeaderError);
	}
#endif

    //Reenable texturing
	setGLClientStateToTexturing();
	return 1;
}