void SmoothHeightMeshDrawer::Draw(float yoffset) {
    if (!drawEnabled)
        return;

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glLineWidth(1.0f);
    glDisable(GL_TEXTURE_2D);
    glActiveTexture(GL_TEXTURE0);
    glDisable(GL_TEXTURE_1D);
    glDisable(GL_CULL_FACE);

    const float quadSize = 4.0f * smoothGround->GetResolution();
    const unsigned int numQuadsX = smoothGround->GetFMaxX() / quadSize;
    const unsigned int numQuadsZ = smoothGround->GetFMaxY() / quadSize;

    CVertexArray* va = GetVertexArray();
    va->Initialize();
    va->EnlargeArrays((numQuadsX + 1) * (numQuadsZ + 1) * 4, 0, VA_SIZE_0);

    for (unsigned int zq = 0; zq <= numQuadsZ; zq++) {
        for (unsigned int xq = 0; xq <= numQuadsX; xq++) {
            const float x = xq * quadSize;
            const float z = zq * quadSize;
            const float h1 = smoothGround->GetHeightAboveWater(x,            z           ) + yoffset;
            const float h2 = smoothGround->GetHeightAboveWater(x + quadSize, z           ) + yoffset;
            const float h3 = smoothGround->GetHeightAboveWater(x + quadSize, z + quadSize) + yoffset;
            const float h4 = smoothGround->GetHeightAboveWater(x,            z + quadSize) + yoffset;

            va->AddVertexQ0(float3(x,            h1, z           ));
            va->AddVertexQ0(float3(x + quadSize, h2, z           ));
            va->AddVertexQ0(float3(x + quadSize, h3, z + quadSize));
            va->AddVertexQ0(float3(x,            h4, z + quadSize));
        }
    }

    glColor4ub(0, 255, 0, 255);
    va->DrawArray0(GL_QUADS);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
Example #2
0
void CSelectedUnits::Draw()
{
	glDisable(GL_TEXTURE_2D);
	glDepthMask(false);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND); // for line smoothing
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glLineWidth(cmdColors.UnitBoxLineWidth());

	GML_RECMUTEX_LOCK(grpsel); // Draw

	if (cmdColors.unitBox[3] > 0.0f) {
		glColor4fv(cmdColors.unitBox);

		const CUnitSet* unitSet;
		if (selectedGroup != -1) {
			unitSet = &grouphandlers[gu->myTeam]->groups[selectedGroup]->units;
		} else {
			unitSet = &selectedUnits;
		}

		CVertexArray* va = GetVertexArray();
		va->Initialize();
		va->EnlargeArrays(unitSet->size()*4, 0, VA_SIZE_0);
		CUnitSet::const_iterator ui;
		for (ui = unitSet->begin(); ui != unitSet->end(); ++ui) {
			const CUnit* unit = *ui;
			if (unit->isIcon) {
				continue;
			}

			va->AddVertexQ0(unit->drawPos.x + unit->xsize * 4, unit->drawPos.y, unit->drawPos.z + unit->zsize * 4);
			va->AddVertexQ0(unit->drawPos.x - unit->xsize * 4, unit->drawPos.y, unit->drawPos.z + unit->zsize * 4);
			va->AddVertexQ0(unit->drawPos.x - unit->xsize * 4, unit->drawPos.y, unit->drawPos.z - unit->zsize * 4);
			va->AddVertexQ0(unit->drawPos.x + unit->xsize * 4, unit->drawPos.y, unit->drawPos.z - unit->zsize * 4);
		}
		va->DrawArray0(GL_QUADS);
	}

	// highlight queued build sites if we are about to build something
	// (or old-style, whenever the shift key is being held down)
	if (cmdColors.buildBox[3] > 0.0f) {
		if (!selectedUnits.empty() &&
				((cmdColors.BuildBoxesOnShift() && keys[SDLK_LSHIFT]) ||
				 ((guihandler->inCommand >= 0) &&
					(guihandler->inCommand < int(guihandler->commands.size())) &&
					(guihandler->commands[guihandler->inCommand].id < 0)))) {

			GML_STDMUTEX_LOCK(cai); // Draw

			bool myColor = true;
			glColor4fv(cmdColors.buildBox);
			std::list<CBuilderCAI*>::const_iterator bi;
			for (bi = uh->builderCAIs.begin(); bi != uh->builderCAIs.end(); ++bi) {
				CBuilderCAI* builder = *bi;
				if (builder->owner->team == gu->myTeam) {
					if (!myColor) {
						glColor4fv(cmdColors.buildBox);
						myColor = true;
					}
					builder->DrawQuedBuildingSquares();
				}
				else if (teamHandler->AlliedTeams(builder->owner->team, gu->myTeam)) {
					if (myColor) {
						glColor4fv(cmdColors.allyBuildBox);
						myColor = false;
					}
					builder->DrawQuedBuildingSquares();
				}
			}
		}
	}

	glLineWidth(1.0f);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);
	glDepthMask(true);
	glEnable(GL_TEXTURE_2D);
}