Пример #1
0
void CDynWater::DrawRefraction(CGame* game)
{
	drawRefraction=true;
	camera->Update(false);

	refractRight=camera->right;
	refractUp=camera->up;
	refractForward=camera->forward;

	refractFBO.Bind();
	glViewport(0,0,refractSize,refractSize);

	glClearColor(mapInfo->atmosphere.fogColor[0],mapInfo->atmosphere.fogColor[1],mapInfo->atmosphere.fogColor[2],1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	float3 oldsun=unitDrawer->unitSunColor;
	float3 oldambient=unitDrawer->unitAmbientColor;

	unitDrawer->unitSunColor*=float3(0.5f,0.7f,0.9f);
	unitDrawer->unitAmbientColor*=float3(0.6f,0.8f,1.0f);

	game->SetDrawMode(CGame::refractionDraw);

	CBaseGroundDrawer *gd = readmap->GetGroundDrawer();
	gd->Draw(false,false,dwGroundRefractVP);

	glEnable(GL_CLIP_PLANE2);
	double plane[4]={0,-1,0,2};
	glClipPlane(GL_CLIP_PLANE2 ,plane);
	drawReflection=true;
	unitDrawer->Draw(false,true);
	featureDrawer->Draw();
	unitDrawer->DrawCloakedUnits(true,true);
	featureDrawer->DrawFadeFeatures(true,true); // FIXME: Make it fade out correctly without "noAdvShading"
	drawReflection=false;
	ph->Draw(false,true);
	eventHandler.DrawWorldRefraction();
	glDisable(GL_CLIP_PLANE2);

	game->SetDrawMode(CGame::normalDraw);

	drawRefraction=false;


	glViewport(gu->viewPosX,0,gu->viewSizeX,gu->viewSizeY);
	glClearColor(mapInfo->atmosphere.fogColor[0],mapInfo->atmosphere.fogColor[1],mapInfo->atmosphere.fogColor[2],1);

	unitDrawer->unitSunColor=oldsun;
	unitDrawer->unitAmbientColor=oldambient;
}
Пример #2
0
void CWorldDrawer::Draw()
{
	SCOPED_TIMER("WorldDrawer::Total");

	CBaseGroundDrawer* gd = readmap->GetGroundDrawer();

	if (globalRendering->drawSky) {
		sky->Draw();
	}

	if (globalRendering->drawGround) {
		SCOPED_TIMER("WorldDrawer::Terrain");
		gd->Draw(DrawPass::Normal);
		smoothHeightMeshDrawer->Draw(1.0f);
		treeDrawer->DrawGrass();
		gd->DrawTrees();
	}

	if (globalRendering->drawWater && !mapInfo->map.voidWater) {
		SCOPED_TIMER("WorldDrawer::Water");

		water->OcclusionQuery();
		if (water->IsDrawSolid()) {
			water->UpdateWater(game);
			water->Draw();
		}
	}

	selectedUnits.Draw();
	eventHandler.DrawWorldPreUnit();

	{
		SCOPED_TIMER("WorldDrawer::Models");
		DebugColVolDrawer::Draw();
		unitDrawer->Draw(false);
		modelDrawer->Draw();
		featureDrawer->Draw();

		pathDrawer->DrawAll();
	}

	//! transparent stuff
	glEnable(GL_BLEND);
	glDepthFunc(GL_LEQUAL);

	const bool noAdvShading = shadowHandler->shadowsLoaded;

	static const double plane_below[4] = {0.0f, -1.0f, 0.0f, 0.0f};
	static const double plane_above[4] = {0.0f,  1.0f, 0.0f, 0.0f};

	{
		glClipPlane(GL_CLIP_PLANE3, plane_below);
		glEnable(GL_CLIP_PLANE3);

		//! draw cloaked objects below water surface
		unitDrawer->DrawCloakedUnits(noAdvShading);
		featureDrawer->DrawFadeFeatures(noAdvShading);

		glDisable(GL_CLIP_PLANE3);
	}

	//! draw water
	if (globalRendering->drawWater && !mapInfo->map.voidWater) {
		SCOPED_TIMER("WorldDrawer::Water");

		if (!water->IsDrawSolid()) {
			//! Water rendering will overwrite features, so save them
			featureDrawer->SwapFeatures();
			water->UpdateWater(game);
			water->Draw();
			featureDrawer->SwapFeatures();
		}
	}

	{
		glClipPlane(GL_CLIP_PLANE3, plane_above);
		glEnable(GL_CLIP_PLANE3);

		//! draw cloaked objects above water surface
		unitDrawer->DrawCloakedUnits(noAdvShading);
		featureDrawer->DrawFadeFeatures(noAdvShading);

		glDisable(GL_CLIP_PLANE3);
	}

	{
		SCOPED_TIMER("WorldDrawer::Projectiles");
		projectileDrawer->Draw(false);
	}

	if (globalRendering->drawSky) {
		sky->DrawSun();
	}

	eventHandler.DrawWorld();

	LuaUnsyncedCtrl::DrawUnitCommandQueues();
	if (cmdColors.AlwaysDrawQueue() || guihandler->GetQueueKeystate()) {
		selectedUnits.DrawCommands();
	}

	lineDrawer.DrawAll();
	cursorIcons.Draw();
	cursorIcons.Clear();

	mouse->DrawSelectionBox();

	guihandler->DrawMapStuff(false);

	if (globalRendering->drawMapMarks && !game->hideInterface) {
		inMapDrawerView->Draw();
	}


	//! underwater overlay
	if (camera->pos.y < 0.0f) {
		glEnableClientState(GL_VERTEX_ARRAY);
		const float3& cpos = camera->pos;
		const float vr = globalRendering->viewRange * 0.5f;
		glDepthMask(GL_FALSE);
		glDisable(GL_TEXTURE_2D);
		glColor4f(0.0f, 0.5f, 0.3f, 0.50f);
		{
			float3 verts[] = {
				float3(cpos.x - vr, 0.0f, cpos.z - vr),
				float3(cpos.x - vr, 0.0f, cpos.z + vr),
				float3(cpos.x + vr, 0.0f, cpos.z + vr),
				float3(cpos.x + vr, 0.0f, cpos.z - vr)
			};
			glVertexPointer(3, GL_FLOAT, 0, verts);
			glDrawArrays(GL_QUADS, 0, 4);
		}

		{
			float3 verts[] = {
				float3(cpos.x - vr, 0.0f, cpos.z - vr),
				float3(cpos.x - vr,  -vr, cpos.z - vr),
				float3(cpos.x - vr, 0.0f, cpos.z + vr),
				float3(cpos.x - vr,  -vr, cpos.z + vr),
				float3(cpos.x + vr, 0.0f, cpos.z + vr),
				float3(cpos.x + vr,  -vr, cpos.z + vr),
				float3(cpos.x + vr, 0.0f, cpos.z - vr),
				float3(cpos.x + vr,  -vr, cpos.z - vr),
				float3(cpos.x - vr, 0.0f, cpos.z - vr),
				float3(cpos.x - vr,  -vr, cpos.z - vr),
			};
			glVertexPointer(3, GL_FLOAT, 0, verts);
			glDrawArrays(GL_QUAD_STRIP, 0, 10);
		}

		glDepthMask(GL_TRUE);
		glDisableClientState(GL_VERTEX_ARRAY);
	}

	//reset fov
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0,1,0,1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glEnable(GL_BLEND);
	glDisable(GL_DEPTH_TEST);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// underwater overlay, part 2
	if (camera->pos.y < 0.0f) {
		glEnableClientState(GL_VERTEX_ARRAY);
		glDisable(GL_TEXTURE_2D);
		glColor4f(0.0f, 0.2f, 0.8f, 0.333f);
		float3 verts[] = {
			float3 (0.f, 0.f, -1.f),
			float3 (1.f, 0.f, -1.f),
			float3 (1.f, 1.f, -1.f),
			float3 (0.f, 1.f, -1.f),
		};
		glVertexPointer(3, GL_FLOAT, 0, verts);
		glDrawArrays(GL_QUADS, 0, 4);
		glDisableClientState(GL_VERTEX_ARRAY);
	}
}
Пример #3
0
void CDynWater::DrawReflection(CGame* game)
{
//	CCamera *realCam = camera;
//	camera = new CCamera(*realCam);
	char realCam[sizeof(CCamera)];
	new (realCam) CCamera(*camera); // anti-crash workaround for multithreading

	camera->forward.y *= -1.0f;
	camera->pos.y *= -1.0f;
	camera->pos.y += 0.2f;
	camera->Update(false);
	reflectRight=camera->right;
	reflectUp=camera->up;
	reflectForward=camera->forward;

	reflectFBO.Bind();
	glViewport(0,0,512,512);

	glClearColor(0.5f,0.6f,0.8f,0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	game->SetDrawMode(CGame::reflectionDraw);

	sky->Draw();

	glEnable(GL_CLIP_PLANE2);
	double plane2[4]={0,-1,0,1.0f};
	glClipPlane(GL_CLIP_PLANE2 ,plane2);
	drawReflection=true;
	bool drawShadows=shadowHandler->drawShadows;
	shadowHandler->drawShadows=false;

	CBaseGroundDrawer *gd = readmap->GetGroundDrawer ();
	gd->Draw(true,false,dwGroundReflectIVP);

	double plane[4]={0,1,0,1.0f};
	glClipPlane(GL_CLIP_PLANE2 ,plane);

	gd->Draw(true);

	shadowHandler->drawShadows=drawShadows;

	unitDrawer->Draw(true);
	featureDrawer->Draw();
	unitDrawer->DrawCloakedUnits(false,true);
	featureDrawer->DrawFadeFeatures(false,true);

	ph->Draw(true);
	eventHandler.DrawWorldReflection();

	sky->DrawSun();

	game->SetDrawMode(CGame::normalDraw);

	drawReflection=false;
	glDisable(GL_CLIP_PLANE2);

	glViewport(gu->viewPosX,0,gu->viewSizeX,gu->viewSizeY);
	glClearColor(mapInfo->atmosphere.fogColor[0],mapInfo->atmosphere.fogColor[1],mapInfo->atmosphere.fogColor[2],1);

//	delete camera;
//	camera = realCam;
	camera->~CCamera();
	new (camera) CCamera(*(CCamera *)realCam);

	camera->Update(false);
}