Example #1
0
VertexArray VertexArray::operator+ (const VertexArray & v) const
{
	VertexArray out;

	COMBINEVECTORS(colors);

	COMBINEVECTORS(normals);

	COMBINEVECTORS(vertices);

	int idxoffset = vertices.size() / 3;
	out.faces.reserve(faces.size() + v.faces.size());
	out.faces.insert(out.faces.end(), faces.begin(), faces.end());
	for (size_t i = 0; i < v.faces.size(); i++)
	{
		out.faces.push_back(v.faces[i]+idxoffset);
	}

	int maxtcsets = GetTexCoordSets();
	if (v.GetTexCoordSets() > maxtcsets)
		maxtcsets = v.GetTexCoordSets();
	int tcsets1 = GetTexCoordSets();
	int tcsets2 = v.GetTexCoordSets();
	out.SetTexCoordSets(maxtcsets);
	for (int i = 0; i < maxtcsets; i++)
	{
		if (i >= tcsets1 && i < tcsets2)
		{
			out.texcoords[i] = v.texcoords[i];
		}
		else if (i < tcsets1 && i >= tcsets2)
		{
			out.texcoords[i] = texcoords[i];
		}
		else if (i < tcsets1 && i < tcsets2)
		{
			COMBINEVECTORS(texcoords[i]);
		}
	}

	return out;
}
Example #2
0
float TextDraw::RenderCharacter(
	const Font & font, char c,
	float x, float y, float scalex, float scaley,
	VertexArray & output_array)
{
	const Font::CharInfo * ci = 0;
	if (!font.GetCharInfo(c, ci)) return 0;

	float invsize = font.GetInvSize();
	float x1 = x + ci->xoffset * invsize * scalex;
	float x2 = x1 + ci->width * invsize * scalex;
	float y1 = y - ci->yoffset * invsize * scaley;
	float y2 = y1 + ci->height * invsize * scaley;

	float u1 = ci->x;
	float u2 = u1 + ci->width;
	float v1 = ci->y;
	float v2 = v1 + ci->height;

	float v[] = {x1, y1, 0, x2, y1, 0, x2, y2, 0, x1, y2, 0};
	float t[] = {u1, v1, u2, v1, u2, v2, u1, v2};
	int f[] = {0, 1, 2, 0, 2, 3};

	if (output_array.GetTexCoordSets() == 0)
	{
		output_array.SetFaces(f, 6);
		output_array.SetVertices(v, 12);
		output_array.SetTexCoordSets(1);
		output_array.SetTexCoords(0, t, 8);
	}
	else
	{
		float * n = 0;
		output_array.Add(0, 0, n, 0, v, 12, f, 6, t, 8);
	}

	return ci->xadvance * invsize * scalex;
}
Example #3
0
void RenderInputScene::DrawVertexArray(const VertexArray & va, float linesize) const
{
	const float * verts;
	int vertcount;
	va.GetVertices(verts, vertcount);
	if (verts)
	{
		glVertexPointer(3, GL_FLOAT, 0, verts);
		glEnableClientState(GL_VERTEX_ARRAY);

		const unsigned char * cols;
		int colcount;
		va.GetColors(cols, colcount);
		if (cols)
		{
			glColorPointer(4, GL_UNSIGNED_BYTE, 0, cols);
			glEnableClientState(GL_COLOR_ARRAY);
		}

		const int * faces;
		int facecount;
		va.GetFaces(faces, facecount);
		if (faces)
		{
			const float * norms;
			int normcount;
			va.GetNormals(norms, normcount);
			if (norms)
			{
				glNormalPointer(GL_FLOAT, 0, norms);
				glEnableClientState(GL_NORMAL_ARRAY);
			}

			const float * tc = 0;
			int tccount;
			if (va.GetTexCoordSets() > 0)
			{
				va.GetTexCoords(0, tc, tccount);
				if (tc)
				{
					glEnableClientState(GL_TEXTURE_COORD_ARRAY);
					glTexCoordPointer(2, GL_FLOAT, 0, tc);
				}
			}

			glDrawElements(GL_TRIANGLES, facecount, GL_UNSIGNED_INT, faces);

			if (tc)
				glDisableClientState(GL_TEXTURE_COORD_ARRAY);

			if (norms)
				glDisableClientState(GL_NORMAL_ARRAY);
		}
		else if (linesize > 0)
		{
			glLineWidth(linesize);
			glDrawArrays(GL_LINES, 0, vertcount / 3);
		}

		if (cols)
			glDisableClientState(GL_COLOR_ARRAY);

		glDisableClientState(GL_VERTEX_ARRAY);
	}
}