Exemplo n.º 1
0
void GraphicsBase::draw()
{
	if (indices.empty())
		return;

	if (isWhite_ == false)
	{
		glPushColor();
		glMultColor(r_, g_, b_, a_);
	}

	if (data)
	{
		oglEnable(GL_TEXTURE_2D);

        oglBindTexture(GL_TEXTURE_2D, data->id());

		oglEnableClientState(GL_VERTEX_ARRAY);
		oglEnableClientState(GL_TEXTURE_COORD_ARRAY);

		glVertexPointer(2, GL_FLOAT, 0, &vertices[0]);
		glTexCoordPointer(2, GL_FLOAT, 0, &texcoords[0]);

		oglDrawElements(mode, indices.size(), GL_UNSIGNED_SHORT, &indices[0]);

		oglDisableClientState(GL_VERTEX_ARRAY);
		oglDisableClientState(GL_TEXTURE_COORD_ARRAY);
	}
	else
	{
		oglDisable(GL_TEXTURE_2D);

		oglEnableClientState(GL_VERTEX_ARRAY);

		glVertexPointer(2, GL_FLOAT, 0, &vertices[0]);

		oglDrawElements(mode, indices.size(), GL_UNSIGNED_SHORT, &indices[0]);

		oglDisableClientState(GL_VERTEX_ARRAY);
	}

	if (isWhite_ == false)
	{
		glPopColor();
	}
}
Exemplo n.º 2
0
void TileMap::doDraw(const CurrentTransform& transform, float hsx, float hsy, float hex, float hey)
{
	int sx, sy, ex, ey;
	{
        // inverse transformed hardware start/end x/y
        float x1, y1, x2, y2, x3, y3, x4, y4;
        Matrix inverse = transform.inverse();
        inverse.transformPoint(hsx, hsy, &x1, &y1);
        inverse.transformPoint(hex, hsy, &x2, &y2);
        inverse.transformPoint(hsx, hey, &x3, &y3);
        inverse.transformPoint(hex, hey, &x4, &y4);
        float thsx = std::min(std::min(x1, x2), std::min(x3, x4));
        float thsy = std::min(std::min(y1, y2), std::min(y3, y4));
        float thex = std::max(std::max(x1, x2), std::max(x3, x4));
        float they = std::max(std::max(y1, y2), std::max(y3, y4));

        // cell size width, cell size height
        float csw = std::max(std::max(tilewidth_, tileheight_), displaywidth_);
        float csh = std::max(std::max(tilewidth_, tileheight_), displayheight_);

        sx = floor((thsx - csw) / displaywidth_) + 1;
        sy = floor(thsy / displayheight_);
        ex = floor(thex / displaywidth_) + 1;
        ey = floor((they + csh) / displayheight_);

        // extra 1 block around
        sx--;
        sy--;
        ex++;
        ey++;

        sx = std::max(sx, 0);
        sy = std::max(sy, 0);
        ex = std::min(ex, width_);
        ey = std::min(ey, height_);
	}

	int tileCount = 0;
	for (int y = sy; y < ey; ++y)
		for (int x = sx; x < ex; ++x)
		{
			int index = x + y * width_;

            int tx = tileids_[index].x;
            int ty = tileids_[index].y;

			if (!isEmpty(tx, ty))
				tileCount++;
		}

	if (tileCount == 0)
		return;

	vertices.resize(tileCount * 12);
	texcoords.resize(tileCount * 12);

	int pos = 0;

	for (int y = sy; y < ey; ++y)
		for (int x = sx; x < ex; ++x)
		{
			int index = x + y * width_;

            int tx = tileids_[index].x;
            int ty = tileids_[index].y;
            int flip = tileids_[index].flip;

			if (!isEmpty(tx, ty))
			{
                bool flip_horizontal = (flip & FLIP_HORIZONTAL);
                bool flip_vertical = (flip & FLIP_VERTICAL);
                bool flip_diagonal = (flip & FLIP_DIAGONAL);

                float x0, y0, x1, y1;

                if (!flip_diagonal)
                {
                    x0 = x * displaywidth_;
                    y0 = y * displayheight_ - (tileheight_ - displayheight_);
                    x1 = x0 + tilewidth_;
                    y1 = y0 + tileheight_;
                }
                else
                {
                    x0 = x * displaywidth_;
                    y0 = y * displayheight_ - (tilewidth_ - displayheight_);
                    x1 = x0 + tileheight_;
                    y1 = y0 + tilewidth_;
                }

				vertices[pos + 0]  = x0; vertices[pos + 1]  = y0;
				vertices[pos + 2]  = x1; vertices[pos + 3]  = y0;
				vertices[pos + 4]  = x0; vertices[pos + 5]  = y1;
				vertices[pos + 6]  = x1; vertices[pos + 7]  = y0;
				vertices[pos + 8]  = x1; vertices[pos + 9]  = y1;
				vertices[pos + 10] = x0; vertices[pos + 11] = y1;

				int u0 = marginx_ + tx * (tilewidth_ + spacingx_);
				int v0 = marginy_ + ty * (tileheight_ + spacingy_);
				int u1 = marginx_ + tx * (tilewidth_ + spacingx_) + tilewidth_;
				int v1 = marginy_ + ty * (tileheight_ + spacingy_) + tileheight_;

                float fu0 = (float)u0 / (float)texture_->data->exwidth;
                float fv0 = (float)v0 / (float)texture_->data->exheight;
                float fu1 = (float)u1 / (float)texture_->data->exwidth;
                float fv1 = (float)v1 / (float)texture_->data->exheight;

                fu0 *= texture_->uvscalex;
                fv0 *= texture_->uvscaley;
                fu1 *= texture_->uvscalex;
                fv1 *= texture_->uvscaley;

                if (flip_horizontal)
                    std::swap(fu0, fu1);

                if (flip_vertical)
                    std::swap(fv0, fv1);

                if (flip_diagonal && (flip_vertical != flip_horizontal))
                {
                    std::swap(fu0, fu1);
                    std::swap(fv0, fv1);
                }

                fu0 += 0.0001f;
                fv0 += 0.0001f;
                fu1 -= 0.0001f;
                fv1 -= 0.0001f;

                if (!flip_diagonal)
                {
                    texcoords[pos + 0]  = fu0; texcoords[pos + 1]  = fv0;
                    texcoords[pos + 2]  = fu1; texcoords[pos + 3]  = fv0;
                    texcoords[pos + 4]  = fu0; texcoords[pos + 5]  = fv1;
                    texcoords[pos + 6]  = fu1; texcoords[pos + 7]  = fv0;
                    texcoords[pos + 8]  = fu1; texcoords[pos + 9]  = fv1;
                    texcoords[pos + 10] = fu0; texcoords[pos + 11] = fv1;
                }
                else
                {
                    texcoords[pos + 0]  = fu0; texcoords[pos + 1]  = fv0;
                    texcoords[pos + 2]  = fu0; texcoords[pos + 3]  = fv1;
                    texcoords[pos + 4]  = fu1; texcoords[pos + 5]  = fv0;
                    texcoords[pos + 6]  = fu0; texcoords[pos + 7]  = fv1;
                    texcoords[pos + 8]  = fu1; texcoords[pos + 9]  = fv1;
                    texcoords[pos + 10] = fu1; texcoords[pos + 11] = fv0;
                }

				pos += 12;
			}
		}

	oglEnable(GL_TEXTURE_2D);

    oglBindTexture(GL_TEXTURE_2D, texture_->data->id());

	oglArrayPointer(VertexArray,2, GL_FLOAT, &vertices[0]);
	oglEnableClientState(VertexArray);

	oglArrayPointer(TextureArray,2, GL_FLOAT, &texcoords[0]);
	oglEnableClientState(TextureArray);

	oglDrawArrays(GL_TRIANGLES, 0, tileCount * 6);

	oglDisableClientState(VertexArray);
	oglDisableClientState(TextureArray);
}
Exemplo n.º 3
0
static void drawIP(const char* ip, int size, int xx, int yy)
{
	static const char* chardot =	" "
							" "
							" "
							" "
							".";

	static const char* char0 =	"..."
							". ."
							". ."
							". ."
							"...";

	static const char* char1 =	"."
							"."
							"."
							"."
							".";

	static const char* char2 =	"..."
							"  ."
							"..."
							".  "
							"...";

	static const char* char3 =	"..."
							"  ."
							"..."
							"  ."
							"...";

	static const char* char4 =	".  "
							". ."
							". ."
							"..."
							"  .";

	static const char* char5 =	"..."
							".  "
							"..."
							"  ."
							"...";

	static const char* char6 =	"..."
							".  "
							"..."
							". ."
							"...";

	static const char* char7 =	"..."
							"  ."
							"  ."
							"  ."
							"  .";

	static const char* char8 =	"..."
							". ."
							"..."
							". ."
							"...";

	static const char* char9 =	"..."
							". ."
							"..."
							"  ."
							"...";

	static const char* loading =
		".   ... ... ..  . ... ...      "
		".   . . . . . . . . . .        "
		".   . . ... . . . . . . .      "
		".   . . . . . . . . . . .      "
		"... ... . . ..  . . . ... . . .";


	static const char* localip =
		".   ... ... ... .     . ...   . ... ... ...  "
		".   . . .   . . .     . . .   . . . .   . . ."
		".   . . .   ... .     . ...   . . . ..  . .  "
		".   . . .   . . .     . .     . . . .   . . ."
		"... ... ... . . ...   . .     . . . .   ...  ";

	static const char* ipinfo =
		". ...   . ... ... ...  "
		". . .   . . . .   . .  "
		". ...   . . . ..  . . ."
		". .     . . . .   . .  "
		". .     . . . .   ... .";

	static const char* version =
        "... ... . .     ... .  "
        "  . . . . . .   . . . ."
        "... . . . . .   . . . ."
        ".   . . . ...   . . ..."
        "... ... .   . . ...   .";

	static const char* chars[] = {char0, char1, char2, char3, char4, char5, char6, char7, char8, char9};

    gglColor4f(0, 0, 0, 1);

	oglDisable(GL_TEXTURE_2D);

	oglEnableClientState(GL_VERTEX_ARRAY);

	float v[8];
	glVertexPointer(2, GL_FLOAT, 0, v);

	int len = strlen(ip);
	for (int i = 0; i < len; ++i)
	{
		const char* chr;
		if (ip[i] == '.')
			chr = chardot;
		else if (ip[i] == 'I')
			chr = localip;
		else if (ip[i] == 'L')
			chr = loading;
		else if (ip[i] == 'V')
			chr = version;
		else
			chr = chars[ip[i] - '0'];

		int height = 5;
		int width = strlen(chr) / height;

		for (int y = 0; y < height; ++y)
			for (int x = 0; x < width; ++x)
			{
				if (chr[x + y * width] == '.')
				{
					//glBegin(GL_QUADS);
					//glVertex2i((x + xx)     * size, (y + yy)     * size);
					//glVertex2i((x + xx + 1) * size, (y + yy)     * size);
					//glVertex2i((x + xx + 1) * size, (y + yy + 1) * size);
					//glVertex2i((x + xx)     * size, (y + yy + 1) * size);
					//glEnd();

					v[0] = (x + xx)     * size; v[1] = (y + yy)     * size;
					v[2] = (x + xx + 1) * size; v[3] = (y + yy)     * size;
					v[4] = (x + xx)     * size; v[5] = (y + yy + 1) * size;
					v[6] = (x + xx + 1) * size; v[7] = (y + yy + 1) * size;

					oglDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
				}
			}

		xx = xx + width + 1;
	}

	oglDisableClientState(GL_VERTEX_ARRAY);
}