Example #1
0
//==========================================================================
//
// Draws a byte buffer
//
//==========================================================================
void gl_DrawBuffer(byte * sbuffer, int width, int height, int x, int y, int dx, int dy, PalEntry * palette)
{
	if (palette==NULL) palette=GPalette.BaseColors;

	byte *buffer = new byte[width * height * 4 + width * 4];

	for (int yy = 0; yy < height; yy++)
	{
		for (int xx = 0; xx < width; xx++)
		{
			int index = xx + (yy * width);
			PalEntry p = palette[sbuffer[index]];
			buffer[(index * 4) + 0] = p.r;
			buffer[(index * 4) + 1] = p.g;
			buffer[(index * 4) + 2] = p.b;
			buffer[(index * 4) + 3] = 255;
		}
	}

	GLTexture * gltex = new GLTexture(width, height, false, false);
	gltex->CreateTexture(buffer, width, height, false, 0, CM_DEFAULT);
	delete[] buffer;
	
	GLShader::Unbind();
	gl.Begin(GL_TRIANGLE_STRIP);
	gl.TexCoord2f(0, 0);
	gl.Vertex2i(x, y);
	gl.TexCoord2f(0, gltex->GetVB());
	gl.Vertex2i(x, y+dy);
	gl.TexCoord2f(gltex->GetUR(), 0);
	gl.Vertex2i(x+dx, y);
	gl.TexCoord2f(gltex->GetUR(), gltex->GetVB());
	gl.Vertex2i(x+dx, y+dy);
	gl.End();
	gl.Flush();
	delete gltex;
}