void CDX9Renderer::Line(point p1, point p2, const color& c1, const color& c2)
	{
		// No support for textured lines
		SetTexture(NULL);

		BeginBatch(batch_lines);
		CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back());

		AddVertex(c1.getD3DCOLOR(), p1, 0.0f, 0.0f);
		AddVertex(c2.getD3DCOLOR(), p2, 1.0f, 1.0f);
		draw_op->vertex_count += 2;
	}
	void CDX9Renderer::Box(const rect& r, cr_float angle, point hotspot, const color& c)
	{
		// No support for textured lines
		SetTexture(NULL);

		quad q((r - hotspot).rotate_to_quad(angle, r.topleft()));

		BeginBatch(batch_linestrip);
		CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back());

		D3DCOLOR color = c.getD3DCOLOR();

		// 4 vertices and use 5th index to repeat first vertex closing the strip as a box
		AddVertex(color, q.tl, 0.0f, 0.0f);
		AddVertex(color, q.tr, 0.0f, 0.0f);
		AddVertex(color, q.br, 0.0f, 0.0f);
		AddVertex(color, q.bl, 0.0f, 0.0f);

		unsigned short index = draw_op->vertex_count;
		AddIndex(index);
		AddIndex(index + 1);
		AddIndex(index + 2);
		AddIndex(index + 3);
		AddIndex(index);

		draw_op->vertex_count += 4;
		draw_op->index_count += 5;
	}
	void CDX9Renderer::Box(const rect& r, const color& c)
	{
		// No support for textured lines
		SetTexture(NULL);

		BeginBatch(batch_linestrip);
		CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back());

		D3DCOLOR color = c.getD3DCOLOR();

		// 4 vertices and use 5th index to repeat first vertex closing the strip as a box
		AddVertex(color, r.topleft(), 0.0f, 0.0f);
		AddVertex(color, r.topright(), 0.0f, 0.0f);
		AddVertex(color, r.bottomright(), 0.0f, 0.0f);
		AddVertex(color, r.bottomleft(), 0.0f, 0.0f);

		unsigned short index = draw_op->vertex_count;
		AddIndex(index);
		AddIndex(index + 1);
		AddIndex(index + 2);
		AddIndex(index + 3);
		AddIndex(index);

		draw_op->vertex_count += 4;
		draw_op->index_count += 5;
	}
	void CDX9Renderer::Point(point p, const color& c)
	{
		BeginBatch(batch_points);
		CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back());

		AddVertex(c.getD3DCOLOR(), p, origin);
		draw_op->vertex_count++;
	}
	// Draw quad
	void CDX9Renderer::Quad(const quad& q, const color& filter, const rect* _uv)
	{
		if (current_texture != NULL && current_texture == current_rendertarget)
			throw error(_T("Illegal rendering operation attempted"), E_FAIL);	// Not allowed to draw with texture being the render target

		BeginBatch(batch_quads);

		CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back());

		rect uv;

		// No texture: UV coords don't matter
		if (current_texture == NULL)
			uv = zero_rect;
		else {
			
			// Texture supplied but no UV given: draw entire texture
			if (_uv == NULL)
				uv = point(current_texture->xf, current_texture->yf).make_rect();
			else
				uv = (*_uv) * point(current_texture->xf, current_texture->yf);
	
		}

		D3DCOLOR c = filter.getD3DCOLOR();

		AddVertex(c, q.tl + point(state.x_skew, 0.0),			uv.topleft());
		AddVertex(c, q.tr + point(state.x_skew, state.y_skew),	uv.topright());
		AddVertex(c, q.bl,										uv.bottomleft());
		AddVertex(c, q.br + point(0.0, state.y_skew),			uv.bottomright());

		unsigned short index = draw_op->vertex_count;
		AddIndex(index);
		AddIndex(index + 1);
		AddIndex(index + 2);
		AddIndex(index + 2);
		AddIndex(index + 1);
		AddIndex(index + 3);

		draw_op->vertex_count += 4;
		draw_op->index_count += 6;
	}