void DebugVisualizerTextUtil::renderText(const VC3 &position, int offsetX, int offsetY, const char *text)
	{
		if (ui::defaultIngameFont != NULL)
		{
			IStorm3D_Font *f = ((OguiStormFont *)ui::defaultIngameFont)->fnt;

			if (text == NULL)
				text = "(null)";

			VC3 pos = position;
			VC3 result = VC3(0,0,0);
			float rhw = 0;
			float real_z = 0;
			IStorm3D_Camera *cam = disposable_scene->GetCamera();
			bool infront = cam->GetTransformedToScreen(pos, result, rhw, real_z);

			if (infront)
			{
				bool offscreen = false;
				int x = (int)(result.x * scr_width);
				int y = (int)(result.y * scr_height);
				if (x < 0 || y < 0 || x >= scr_width || y >= scr_height)
					offscreen = true;

				if (!offscreen)
				{
					float scrfloatx = (float)(x + offsetX);
					float scrfloaty = (float)(y + offsetY);
					float alpha = 1.0f;
					COL col = COL(1,1,1);
					disposable_scene->Render2D_Text(f, VC2(scrfloatx, scrfloaty), VC2(16, 16), text, alpha, col);
				}
			}
		}
	}
Example #2
0
void ModelGroup::update(Storm &storm, const VC3 &position)
{
	QUAT quat;
	//quat.MakeFromAngles(0, rotation, 0);
	quat = frozenbyte::editor::getRotation(rotationEul);
	MAT tm;
	tm.CreateRotationMatrix(quat);

	for(int i = 0; i < int(models.size()); ++i)
	{
		if(!models[i])
			continue;

		const GroupList::Instance &instance = objectGroup.instances[i];

		VC3 pos = instance.position;
		tm.RotateVector(pos);
		pos += position;
		pos.y = storm.getHeight(VC2(pos.x, pos.z)) + heightOffset;
		pos.y += objectGroup.instances[i].position.y;
		models[i]->SetPosition(pos);

		VC3 angles = getRotation(storm, i);
		quat = frozenbyte::editor::getRotation(angles);

		//QUAT q;
		//q.MakeFromAngles(0, rotation, 0);
		//quat = quat * q;

		models[i]->SetRotation(quat);
	}
}
	void spawn(DecalIdentifier &identifier, int id, const VC3 &position, const QUAT &rotation, const COL &light, bool inBuilding)
	{
		assert(id >= 0 && id < int(effects.size()));

		Effect &effect = effects[id];
		if(effect.spawners.empty())
			return;

		float size = effect.sizeMin;
		float sizeDelta = effect.sizeMax - effect.sizeMin;
		size += (rand() / float(RAND_MAX)) * sizeDelta;

		int spawnerIndex = rand() % effect.spawners.size();

		DecalSpawner &spawner = *effect.spawners[spawnerIndex];
		spawner.setSize(VC2(size, size));

		if(!effect.randomRotation)
			spawner.spawnDecal(identifier, position, rotation, light, inBuilding);
		else
		{
			float angle = rand() % 6000 / 1000.f;
			QUAT r;
			r.MakeFromAngles(0, 0, angle);
			r = r * rotation;

			spawner.spawnDecal(identifier, position, r, light, inBuilding);
		}
	}
Example #4
0
	void renderFakeLights(const VC2I &renderSize)
	{
		// Renders fake light (not shadows)?
		device.SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
		device.SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);

		//device.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
		device.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_INVDESTCOLOR);
		device.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
		device.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
		device.SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);

        device.SetStdProgram(GfxDevice::SSF_2D_POS | GfxDevice::SSF_COLOR | GfxDevice::SSF_TEXTURE);
        device.SetFVF(FVF_P2DUV);

        VC2 pixsz = device.pixelSize();
        float scalex = renderSize.x * pixsz.x;
        float scaley = renderSize.y * pixsz.y;

		FakeLightList::iterator it = fakeLights.begin();
		for(; it != fakeLights.end(); ++it)
		{
			Storm3D_LightTexture &lightTexture = *it;
			DWORD color = 0xFF000000 | lightTexture.color.GetAsD3DCompatibleARGB();

			float x1 = frozenbyte::storm::convX_SCtoDS(lightTexture.start.x, scalex);
			float y1 = frozenbyte::storm::convY_SCtoDS(lightTexture.start.y, scaley);
			float x2 = frozenbyte::storm::convX_SCtoDS(lightTexture.end.x, scalex);
			float y2 = frozenbyte::storm::convY_SCtoDS(lightTexture.end.y, scaley);

            Vertex_P2DUV buffer[4] = {
                { VC2(x1, y2), color, VC2(0.f, 1.f) },
                { VC2(x1, y1), color, VC2(0.f, 0.f) },
                { VC2(x2, y2), color, VC2(1.f, 1.f) },
                { VC2(x2, y1), color, VC2(1.f, 0.f) },
            };

			lightTexture.texture->Apply(0);
			device.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, buffer, sizeof(Vertex_P2DUV));
		}

		device.SetTexture(0, 0);
		device.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
		device.SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
		device.SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);

		device.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
		device.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
	}
	void DecalPositionCalculator::calculateDecalRotation(game::GameScene *gameScene, const VC3 &position, QUAT &resultRotation, float yAngle, VC3 &normal)
	{
		VC2 p2(position.x, position.z);
		//normal = gameScene->getTerrain()->getInterpolatedNormal(p2);
		//normal = gameScene->getTerrain()->getFaceNormal(p2);
		getNormal(gameScene, position, VC2(0.5f, 0.5f), normal);

		QUAT rotation;
		rotation.MakeFromAngles(-PI*.5f, yAngle, 0);
		rotateToward(normal, VC3(0,1.f,0), resultRotation);

		resultRotation = rotation * resultRotation;


		/*
		VC3 x(rand() % 1000 / 999.f, 0, rand() % 1000 / 999.f);
		if(x.GetSquareLength() > 0.0001f)
			x.Normalize();
		else
			x = VC3(1.f, 0, 0);

		x -= hitNormal * x.GetDotWith(hitNormal);
		VC3 y = -x.GetCrossWith(hitNormal);

		assert(fabsf(x.GetDotWith(y)) < 0.0001f);
		assert(fabsf(x.GetDotWith(hitNormal)) < 0.0001f);

		MAT tm;
		tm.Set(0, x.x);
		tm.Set(1, x.y);
		tm.Set(2, x.z);
		tm.Set(4, y.x);
		tm.Set(5, y.y);
		tm.Set(6, y.z);
		tm.Set(8, hitNormal.x);
		tm.Set(9, hitNormal.y);
		tm.Set(10, hitNormal.z);

		resultRotation = tm.GetRotation();
		*/
	}
Example #6
0
/*!
	\param present
	\return polygon count
*/
int Storm3D_Scene::RenderScene(bool present)
{
	// Reset polygon counter
	poly_counter = 0;
	
	{
		static int haxValue = 0;
		++haxValue;

		IStorm3D_Texture *target = Storm3D2->getReflectionTexture();
		if(target /*&& haxValue > 1*/) 
		{
			haxValue = 0;

			enableLocalReflection = true;
			frozenbyte::storm::setInverseCulling(true);
			active_visibility = 1;

			Storm3D_Camera camback = camera;
			camback.Apply();

			Storm3D_Texture *render_target = (Storm3D_Texture *) target;
			if (!render_target->IsCube())
			{
				bool renderHalved = true;
				bool renderDistortion = true;
				bool renderGlow = true;
				bool renderGlowImproved = true;
				bool renderFakes = true;
				bool renderFakeShadows = true;
				bool renderSpotShadows = true;
				bool renderParticles = true;

				if(!terrains.empty())
				{
					IStorm3D_TerrainRenderer &renderer = (*terrains.begin())->getRenderer();
					bool shouldRenderHalved = Storm3D2->halfReflection;
					bool shouldRenderDistortion = false;
					bool shouldRenderGlow = false;
					bool shouldRenderGlowImproved = false;
					bool shouldRenderFakes = false;
					bool shouldRenderFakeShadows = false;
					bool shouldRenderSpotShadows = false;

					// Particle reflection hacky
					bool shouldRenderParticleReflection = false;
					shouldRenderParticleReflection = renderer.enableFeature(IStorm3D_TerrainRenderer::ParticleReflection, false);
					renderer.enableFeature(IStorm3D_TerrainRenderer::ParticleReflection, shouldRenderParticleReflection);
					renderParticles = renderer.enableFeature(IStorm3D_TerrainRenderer::Particles, shouldRenderParticleReflection);

					if(Storm3D2->reflectionQuality >= 100)
					{
						shouldRenderDistortion = true;
						shouldRenderGlow = true;
					}

					renderHalved = renderer.enableFeature(IStorm3D_TerrainRenderer::HalfRendering, shouldRenderHalved);
					renderDistortion = renderer.enableFeature(IStorm3D_TerrainRenderer::Distortion, shouldRenderDistortion);
					renderGlow = renderer.enableFeature(IStorm3D_TerrainRenderer::Glow, shouldRenderGlow);
					renderGlowImproved = renderer.enableFeature(IStorm3D_TerrainRenderer::BetterGlowSampling, shouldRenderGlowImproved);
					renderFakes = renderer.enableFeature(IStorm3D_TerrainRenderer::FakeLights, shouldRenderFakes);
					renderFakeShadows = renderer.enableFeature(IStorm3D_TerrainRenderer::FakeShadows, shouldRenderFakeShadows);
					renderSpotShadows = renderer.enableFeature(IStorm3D_TerrainRenderer::SpotShadows, shouldRenderSpotShadows);

					// If we already have features disabled, don't enable them for reflection
					if(renderHalved)
						renderer.enableFeature(IStorm3D_TerrainRenderer::HalfRendering, true);
					if(!renderDistortion)
						renderer.enableFeature(IStorm3D_TerrainRenderer::Distortion, false);
					if(!renderGlowImproved)
						renderer.enableFeature(IStorm3D_TerrainRenderer::BetterGlowSampling, false);
					if(!renderGlow)
						renderer.enableFeature(IStorm3D_TerrainRenderer::Glow, false);
					if(!renderFakes)
						renderer.enableFeature(IStorm3D_TerrainRenderer::FakeLights, false);
					if(!renderFakeShadows)
						renderer.enableFeature(IStorm3D_TerrainRenderer::FakeShadows, false);
					if(!renderSpotShadows)
						renderer.enableFeature(IStorm3D_TerrainRenderer::SpotShadows, false);
				}

				VC3 position = camera.GetPosition();
				VC3 target = camera.GetTarget();

				// Mirror relative to reflection plane
				position.y = reflection_height - (position.y - reflection_height);
				target.y = reflection_height - (target.y - reflection_height);

				camera.SetPosition(position);
				camera.SetTarget(target);
				camera.ForceViewProjection(&camback);
				RenderSceneWithParams(false,false,false,true,render_target);

				igios_unimplemented();

				if(!terrains.empty())
				{
					IStorm3D_TerrainRenderer &renderer = (*terrains.begin())->getRenderer();

					renderer.enableFeature(IStorm3D_TerrainRenderer::HalfRendering, renderHalved);
					renderer.enableFeature(IStorm3D_TerrainRenderer::Distortion, renderDistortion);
					renderer.enableFeature(IStorm3D_TerrainRenderer::Glow, renderGlow);
					renderer.enableFeature(IStorm3D_TerrainRenderer::BetterGlowSampling, renderGlowImproved);
					renderer.enableFeature(IStorm3D_TerrainRenderer::FakeLights, renderFakes);
					renderer.enableFeature(IStorm3D_TerrainRenderer::FakeShadows, renderFakeShadows);
					renderer.enableFeature(IStorm3D_TerrainRenderer::SpotShadows, renderSpotShadows);
					renderer.enableFeature(IStorm3D_TerrainRenderer::Particles, renderParticles);
				}

				// debugging code
				if(false){
					static IStorm3D_Material *hax = this->Storm3D2->CreateNewMaterial("..");
					hax->SetBaseTexture(render_target);
					this->Render2D_Picture(hax, VC2(300,10), VC2(512,512), 1.f, 0.f, 0.f, 0.f, 1.f, 1.f, false);
				}
			}

			active_visibility = 0;
			enableLocalReflection = false;
			frozenbyte::storm::setInverseCulling(false);

			camera = camback;
		}
	}

	// Render with flip
	RenderSceneWithParams(present, false);

	// Return polygon count
	return poly_counter;
}
Example #7
0
/*!
	\param mat material
	\param vertices vertices
	\param numVertices number of vertices
	\param alpha alpha
	\param wrap true to wrap
*/
void Storm3D_Scene::Render2D_Picture(IStorm3D_Material *mat,struct VXFORMAT_2D *vertices, int numVertices, float alpha, bool wrap)
{
	// Create new
	Storm3D_Scene_PicList_Picture *pl=new Storm3D_Scene_PicList_Picture(Storm3D2,this,(Storm3D_Material*)mat,VC2(0,0),VC2(1,1),alpha,0,0,0,1,1,wrap);
	pl->createCustomShape(vertices, numVertices);

	// Add to list
	piclist.push_back(pl);
}
	VC3 CameraAutotilter::getTilt(const VC3 &position, float alphaAngle)
	{
		VC3 ret = VC3(0,0,0);

		assert(gameMap != NULL);

		// FIXME: need to rotate based on camera!!!
		// if camera points to some other direction, tilt
		// won't work corretly!!!

		int px = gameMap->scaledToObstacleX(position.x);
		int py = gameMap->scaledToObstacleY(position.z);

		//assert(px >= 0 && py >= 0 && px < gameMap->getObstacleSizeX()
		//	&& py < gameMap->getObstacleSizeY());

		if(px <= 0 || py < 0 || px >= gameMap->getObstacleSizeX()
			|| py >= gameMap->getObstacleSizeY())
		{
			return ret;
		}

		float rotAngle = 90 + alphaAngle;
		if (rotAngle < 0) rotAngle += 360;
		if (rotAngle >= 360) rotAngle -= 360;

		// FIXME: rotated_x_vec is not correct!
		// therefore, returned y-axis rotation result is incorrect!!!

		VC2 rotated_y_vec = VC2(sinf(UNIT_ANGLE_TO_RAD(rotAngle)), cosf(UNIT_ANGLE_TO_RAD(rotAngle)));
		VC2 rotated_x_vec = -VC2(cosf(UNIT_ANGLE_TO_RAD(rotAngle)), sinf(UNIT_ANGLE_TO_RAD(rotAngle)));

		int obstSizeX = gameMap->getObstacleSizeX();
		int obstSizeY = gameMap->getObstacleSizeY();

		for (int y = -1; y > -CAMERATILT_CHECK_DISTANCE; y--)
		{
			int tx = int(px + rotated_y_vec.x * float(y));
			int ty = int(py + rotated_y_vec.y * float(y));
			if (tx >= 0 && ty >= 0 && tx < obstSizeX && ty < obstSizeY)
			{
				if (gameMap->getObstacleHeight(tx, ty) > CAMERATILT_ABOVE_OBSTACLE_HEIGHT
					&& !gameMap->isMovingObstacle(tx, ty))
				{
  				ret.x = float(-CAMERATILT_CHECK_DISTANCE - y) * 2;
					break;
				}
			}
		}

		int x;
		int minx = -CAMERATILT_CHECK_DISTANCE;
		for (x = 1; x < CAMERATILT_CHECK_DISTANCE; x++)
		{
			int tx = int(px + rotated_x_vec.x * float(x));
			int ty = int(py + rotated_x_vec.y * float(x));
			if (tx >= 0 && ty >= 0 && tx < obstSizeX && ty < obstSizeY)
			{
				if (gameMap->getObstacleHeight(tx, ty) > CAMERATILT_ABOVE_OBSTACLE_HEIGHT
					&& !gameMap->isMovingObstacle(tx, ty))
				{
					minx = -x;
					ret.y = float(CAMERATILT_CHECK_DISTANCE - x);
					break;
				}
			}
		}
		for (x = -1; x >= minx; x--)
		{
			int tx = int(px + rotated_x_vec.x * float(x));
			int ty = int(py + rotated_x_vec.y * float(x));
			if (tx >= 0 && ty >= 0 && tx < obstSizeX && ty < obstSizeY)
			{
				if (gameMap->getObstacleHeight(tx, ty) > CAMERATILT_ABOVE_OBSTACLE_HEIGHT
					&& !gameMap->isMovingObstacle(tx, ty))
				{
					if (x == minx)
					{
						ret.y = 0.0f;
					} else {
						ret.y = float(-CAMERATILT_CHECK_DISTANCE - x);
					}
					break;
				}
			}
		}
		ret.y = -ret.y;

		int curTime = Timer::getTime();
		int timeDiff = curTime - lastTime;
		if (timeDiff > 100) 
		{
			timeDiff = 100;
			lastTime = curTime;
		}
		if (timeDiff < 0)
		{
			timeDiff = 0;
			lastTime = curTime;
		}
		if (lastTime < curTime)
			lastTime += timeDiff;

		float confFactor = 0.02f * game::SimpleOptions::getInt(DH_OPT_I_CAMERA_AUTOTILT_AMOUNT);
		if (fabs(ret.y - lastRotation.y) <= 2 * confFactor)
		{
			ret.y = lastRotation.y;
		}
		if (fabs(ret.x - lastRotation.x) <= 2 * confFactor)
		{
			ret.x = lastRotation.x;
		}
		float timeFactor = confFactor * 0.01f * float(timeDiff);

		VC3 posDiffVector = position - lastPosition;
		VC3 posDiffVectorRotated = VC3(
			posDiffVector.x * cosf(UNIT_ANGLE_TO_RAD(rotAngle)) 
			+ posDiffVector.z * sinf(UNIT_ANGLE_TO_RAD(rotAngle)),
			0,
			posDiffVector.x * sinf(UNIT_ANGLE_TO_RAD(rotAngle)) 
			+ posDiffVector.z * cosf(UNIT_ANGLE_TO_RAD(rotAngle)));

		//if (posDiffVectorRotated.z < -0.01f)
		//	Logger::getInstance()->error("z m");
		//if (posDiffVectorRotated.z > 0.01f)
		//	Logger::getInstance()->error("z p");

		if (ret.x < lastRotation.x)
		{
			//if (position.z < lastPosition.z)
			//if (posDiffVectorRotated.z < -0.01f)
				ret.x = lastRotation.x - timeFactor;
			//else
			//	ret.x = lastRotation.x;
		}
		if (ret.x > lastRotation.x)
		{
			//if (position.z > lastPosition.z)
			//if (posDiffVectorRotated.z > 0.01f)
				ret.x = lastRotation.x + timeFactor;
			//else
			//	ret.x = lastRotation.x;
		}

		if (ret.y < lastRotation.y)
		{
			//if (position.x > lastPosition.x)
			//if (posDiffVectorRotated.x < -0.01f)
				ret.y = lastRotation.y - timeFactor;
			//else
			//	ret.y = lastRotation.y;
		}
		if (ret.y > lastRotation.y)
		{
			//if (position.x < lastPosition.x)
			//if (posDiffVectorRotated.x > 0.01f)
				ret.y = lastRotation.y + timeFactor;
			//else
			//	ret.y = lastRotation.y;
		}

		lastRotation = ret;
		lastPosition = position;

		return ret;
	}
void Storm3D_Scene_PicList_Picture::Render()
{
    gfx::Renderer& renderer = Storm3D2->renderer;
    gfx::Device& device = renderer.device;
    gfx::ProgramManager& programManager = renderer.programManager;

    if(wrap)
	{
		device.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
		device.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
	}

	IStorm3D_Material::ATYPE alphaType = IStorm3D_Material::ATYPE_NONE;
	if(material)
	{
		alphaType = material->GetAlphaType();
		if(alpha < 0.99f && alphaType == IStorm3D_Material::ATYPE_NONE)
			material->SetAlphaType(IStorm3D_Material::ATYPE_USE_TEXTRANSPARENCY);

		// Apply the texture
		material->ApplyBaseTextureExtOnly();

		// Animate
		{
			IStorm3D_Texture *ti = material->GetBaseTexture();
			// FIXED: crashed to null pointer here. -jpk
			if (ti != NULL)
			{
				Storm3D_Texture *t = static_cast<Storm3D_Texture *> (ti);
				t->AnimateVideo();
			}
		}
	}

	// Create 3d-vector
	VC2 pos(position.x,position.y);

	// Create color (color+alpha)
	DWORD col = 0xFFFFFFFF;
	if(material)
	{
		COL c(1.f, 1.f, 1.f);
		float newAlpha = 1.f;
		c = material->GetColor();
		newAlpha = alpha * (1-material->GetTransparency());
		col=D3DCOLOR_ARGB((int)((newAlpha)*255.0f),(int)(c.r*255.0f),(int)(c.g*255.0f),(int)(c.b*255.0f));
	}

	// Render it
    programManager.setStdProgram(device, gfx::ProgramManager::SSF_2D_POS | gfx::ProgramManager::SSF_COLOR | gfx::ProgramManager::SSF_TEXTURE);
    renderer.setFVF(FVF_P2DUV);

    Storm3D_SurfaceInfo& si = Storm3D2->GetScreenSize();
    VC2 pixsz = VC2(2.0f/si.width, 2.0f/si.height);

	// render with custom shape
	if(customShape && customShape->vertices)
	{
		// use combined alpha
		float alpha_mul = 1.0f;
		if(material)
		{
			alpha_mul = alpha * (1.0f - material->GetTransparency());
		}
        for (int i = 0; i < customShape->numVertices; i++)
        {
            DWORD c = customShape->vertices[i].d;
            int newAlpha = (int)((c >> 24) * alpha_mul);
            c &= 0x00FFFFFF;
            c |= (newAlpha & 0xFF) << 24;
            customShape->vertices[i].d = c;
            customShape->vertices[i].p.x = frozenbyte::storm::convX_SCtoDS(customShape->vertices[i].p.x-0.5f, pixsz.x);
            customShape->vertices[i].p.y = frozenbyte::storm::convY_SCtoDS(customShape->vertices[i].p.y-0.5f, pixsz.y);
        }
		renderer.drawPrimitiveUP(D3DPT_TRIANGLELIST,customShape->numVertices/3,customShape->vertices,sizeof(Vertex_P2DUV));
	}
Example #10
0
VC2 AlignUnits::getAlignedPosition(const VC2 &position) const
{
	VC3 result = getAlignedPosition(VC3(position.x, 0, position.y));
	return VC2(result.x, result.z);	
}
Example #11
0
  void SelectionBox::render()
  {
    if (selectionActive())
    {
			// this most certainly does not work
			// first of all, nothing happens...
			// and secondly, if something would happen, this would actually
			// make new lines constantly and not remove the old ones.
			// thus causing lots of lines...
			// and if would draw the lines to world coordinates (near terrain)
      IStorm3D *s3d = game->getGameScene()->getStorm3D();
      IStorm3D_Scene *scene = game->getGameScene()->getStormScene();
			/*
			IStorm3D_Line *line = s3d->CreateNewLine();

			SceneSelection dragUpperLeft=game->gameUI->cursorRayTrace(boxStartX,boxStartY);
			SceneSelection dragUpperRight=game->gameUI->cursorRayTrace(currentX,currentY);
			SceneSelection dragLowerLeft=game->gameUI->cursorRayTrace(boxStartX,currentY);
			SceneSelection dragLowerRight=game->gameUI->cursorRayTrace(currentX,currentY);
			
			VC3 v1(dragUpperLeft.scaledMapX, 
				game->gameMap->getScaledHeightAt(
				dragUpperLeft.scaledMapX, dragUpperLeft.scaledMapY), 
				dragUpperLeft.scaledMapY);
			VC3 v2(dragUpperRight.scaledMapX, 
				game->gameMap->getScaledHeightAt(
				dragUpperRight.scaledMapX, dragUpperRight.scaledMapY), 
				dragUpperRight.scaledMapY);
			VC3 v3(dragLowerRight.scaledMapX, 
				game->gameMap->getScaledHeightAt(
				dragLowerRight.scaledMapX, dragLowerRight.scaledMapY), 
				dragLowerRight.scaledMapY);
			VC3 v4(dragLowerLeft.scaledMapX, 
				game->gameMap->getScaledHeightAt(
				dragLowerLeft.scaledMapX, dragLowerLeft.scaledMapY), 
				dragLowerLeft.scaledMapY);

			line->AddPoint(v1);
			line->AddPoint(v2);
			line->AddPoint(v3);
			line->AddPoint(v4);
			line->AddPoint(v1);
			line->SetColor(0x00ff00);
			scene->AddLine(line, false);
			*/
			int sx = boxStartX * renderScaleX / OGUI_SCALE_MULTIPLIER;
			int sy = boxStartY * renderScaleY / OGUI_SCALE_MULTIPLIER;
			int cx = currentX * renderScaleX / OGUI_SCALE_MULTIPLIER;
			int cy = currentY * renderScaleY / OGUI_SCALE_MULTIPLIER;
			if (sx > cx) { sx ^= cx; cx ^= sx; sx ^= cx; }
			if (sy > cy) { sy ^= cy; cy ^= sy; sy ^= cy; }

			VC2 p1 = VC2((float)sx, (float)sy);
			VC2 s1 = VC2((float)(cx - sx + 1), 1);
			VC2 p2 = VC2((float)sx, (float)sy);
			VC2 s2 = VC2(1, (float)(cy - sy + 1));
			VC2 p3 = VC2((float)sx, (float)cy);
			VC2 s3 = VC2((float)(cx - sx + 1), 1);
			VC2 p4 = VC2((float)cx, (float)sy);
			VC2 s4 = VC2(1, (float)(cy - sy + 1));

			scene->Render2D_Picture(selectionbox_mat, p1, s1);
			scene->Render2D_Picture(selectionbox_mat, p2, s2);
			scene->Render2D_Picture(selectionbox_mat, p3, s3);
			scene->Render2D_Picture(selectionbox_mat, p4, s4);
    }
  }
//------------------------------------------------------------------
// Storm3D_Scene_PicList_Font::Render
//------------------------------------------------------------------
void Storm3D_Scene_PicList_Font::Render()
{
	// Calculate complete letter amount and letters per texture
	int letters_per_texture=font->tex_letter_rows*font->tex_letter_columns;
	int letter_amt=font->texture_amount*letters_per_texture;

	// Create 3d-vector
	VC3 pos(position.x,position.y,0);

	// Create color (color+alpha)
	COL color = font->GetColor();
	color *= colorFactor;
	color.Clamp();

	//DWORD col=font->GetColor().GetAsD3DCompatibleARGB();
	//DWORD col=color.GetAsD3DCompatibleARGB();
	DWORD col = D3DCOLOR_ARGB((int)((alpha)*255.0f),(int)(color.r*255.0f),(int)(color.g*255.0f),(int)(color.b*255.0f));
	Storm3D2->GetD3DDevice()->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);

	if(font->font && font->sprite)
	{
		#pragma message("**                                             **")
		#pragma message("** Size to screen boundary and enable clipping **")
		#pragma message("**                                             **")

		//VC2 _position,VC2 _size
		RECT rc = { int(position.x), int(position.y), int(position.x + size.x + 100), int(position.y + size.y + 1000) };
		//if(uniText)
		//	font->font->DrawTextW(0, uniText, wcslen(uniText), &rc, DT_SINGLELINE | DT_LEFT | DT_NOCLIP, col);
		//else if(text)
		//	font->font->DrawText(0, text, strlen(text), &rc, DT_SINGLELINE | DT_LEFT | DT_NOCLIP, col);

		DWORD flags = D3DXSPRITE_SORT_TEXTURE | D3DXSPRITE_ALPHABLEND;
		font->sprite->Begin(flags);

		if(uniText)
			font->font->DrawTextW(font->sprite, uniText, wcslen(uniText), &rc, DT_LEFT | DT_NOCLIP, col);
		else if(text)
			font->font->DrawText(font->sprite, text, strlen(text), &rc, DT_LEFT | DT_NOCLIP, col);

		font->sprite->End();
	}
	else if(text)
	{
		for(int l=0;l<int(strlen(text));l++)
		{
			// Search for letter
			int let=-1;
			for (int i=0;i<letter_amt;i++) 
			{
				if (font->letter_characters[i]==text[l]) 
				{
					let=i;
					// doh, why not break now when we found it and save time!
					break; 
				} 
				else 
				{
					// if we find the null terminator, just stop there, because
					// otherwise we'll go past the character array size if it
					// does not contain character definitions for total of letter_amt
					// characters. In my opininion requiring such a thing is not nice.
					if (font->letter_characters[i] == '\0') 
						break;
				}
			}

			// Is this letter in font
			if (let>=0)
			{
				// Apply the correct texture
				font->textures[let/letters_per_texture]->Apply(0);

				// Calculate x/y
				int x=let%font->tex_letter_columns;
				int y=(let%letters_per_texture)/font->tex_letter_columns;

				// Calculate texture coordinates
				float tx1=1/(float)font->tex_letter_columns;
				float ty1=1/(float)font->tex_letter_rows;
				float fx=(float)x*tx1;
				float fy=(float)y*ty1;

				// Create a quad
				VXFORMAT_2D vx[4];
				vx[0]=VXFORMAT_2D(pos+VC3(0,size.y,0),1,
					col,VC2(fx,fy+ty1));
		
				vx[1]=VXFORMAT_2D(pos,1,
					col,VC2(fx,fy));
		
				vx[2]=VXFORMAT_2D(pos+VC3(size.x,size.y,0),1,
					col,VC2(fx+tx1,fy+ty1));

				vx[3]=VXFORMAT_2D(pos+VC3(size.x,0,0),1,
					col,VC2(fx+tx1,fy));

				// Clip
				if (Clip2DRectangle(Storm3D2,vx[1],vx[2])) 
				{
					// Copy clipping
					vx[0].position.x=vx[1].position.x;
					vx[0].texcoords.x=vx[1].texcoords.x;
					vx[3].position.y=vx[1].position.y;
					vx[3].texcoords.y=vx[1].texcoords.y;
					vx[0].position.y=vx[2].position.y;
					vx[0].texcoords.y=vx[2].texcoords.y;
					vx[3].position.x=vx[2].position.x;
					vx[3].texcoords.x=vx[2].texcoords.x;

					for(int i = 0; i < 4; ++i)
					{
						vx[i].position.x -= .5f;
						vx[i].position.y -= .5f;
					}

					// Render it
					Storm3D2->GetD3DDevice()->SetVertexShader(0);
					Storm3D2->GetD3DDevice()->SetFVF(FVF_VXFORMAT_2D);

					frozenbyte::storm::validateDevice(*Storm3D2->GetD3DDevice(), Storm3D2->getLogger());
					Storm3D2->GetD3DDevice()->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,vx,sizeof(VXFORMAT_2D));
					scene->AddPolyCounter(2);
				}
			}

			// Add x-koordinate
			if (let>=0) pos.x+=((float)font->letter_width[let]/64.0f)*size.x;
				else pos.x+=size.x/2.0f;
		}
	}
}
Example #13
0
//------------------------------------------------------------------
// Storm3D_Material::Apply
// Applies material. Use pass parameter to tell with pass to
// render. Start with pass=0, and increase it until this routine
// returns false. (=all passes rendered)
// 
// Returns:
// false = this was last pass
// true = new pass must be rendered
//------------------------------------------------------------------
bool Storm3D_Material::Apply(Storm3D_Scene *scene,int pass,DWORD fvf,D3DMATRIX *mtx)
{
	/*
	Basic config:

	All textures = NULL

	Stage0:
	colorop = modulate
	colorarg1 = texture
	colorarg2 = diffuse
	alphaop = disable
	texturetransformflags = disable
	texcoordindex = 0

	Stage1-3:
	colorarg1 = texture
	colorarg2 = current
	alphaop = disable
	texturetransformflags = disable
	texcoordindex = 0
	
	After rendering material's UnApply() is called, and it
	returns these states, if it changes them.

	*/

	// BETA: UnApply() all (very slow!)
	Storm3D2->device.SetRenderState(D3DRS_LIGHTING,TRUE);
	Storm3D2->device.SetRenderState(D3DRS_ALPHATESTENABLE,FALSE);
	Storm3D2->device.SetTexture(0,NULL);
	Storm3D2->device.SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
	Storm3D2->device.SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
	Storm3D2->device.SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
	Storm3D2->device.SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_DISABLE);
	Storm3D2->device.SetTextureStageState(0,D3DTSS_TEXCOORDINDEX,0);
	Storm3D2->device.SetTextureStageState(0,D3DTSS_TEXTURETRANSFORMFLAGS,D3DTTFF_DISABLE);

	//	FixMe:
	//	Setting this causes debug runtime to halt (set only to supported stages)
		//for (int i=1;i<3;i++)
	for (int i=0;i<2;i++)
	{
		Storm3D2->device.SetTexture(i,NULL);
		Storm3D2->device.SetTextureStageState(i,D3DTSS_COLORARG1,D3DTA_TEXTURE);
		Storm3D2->device.SetTextureStageState(i,D3DTSS_COLORARG2,D3DTA_CURRENT);
		Storm3D2->device.SetTextureStageState(i,D3DTSS_ALPHAOP,D3DTOP_DISABLE);
		Storm3D2->device.SetTextureStageState(i,D3DTSS_TEXCOORDINDEX,i);
		Storm3D2->device.SetTextureStageState(i,D3DTSS_TEXTURETRANSFORMFLAGS,D3DTTFF_DISABLE);
	}

	// Animate textures
	if (texture_base) texture_base->texture->AnimateVideo();
	if (texture_base2) texture_base2->texture->AnimateVideo();
	if (texture_reflection) texture_reflection->texture->AnimateVideo();
	if (texture_bump) texture_bump->texture->AnimateVideo();

	// The superb if(TM) multitexturing (no effects/techniques needed anymore!)	
	// This routine is much faster than DX8-effect system (and bugfree also;)...
	if (multitexture_type==MTYPE_COLORONLY)			// COL only
	{
		// Set stages (color only)
		//Storm3D2->device.SetTexture(0,NULL);

		// psd: assume lightmap if base2 defined
		if(texture_base2)
		{
			texture_base2->texture->Apply(0);
			Storm3D2->device.SetTextureStageState(0,D3DTSS_COLOROP,texture_base2->GetDX8MultitexBlendingOp());
		}
		else
		{
			Storm3D2->device.SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1);
			Storm3D2->device.SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_DIFFUSE);
			Storm3D2->device.SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_DISABLE);
		}
	}
	else if (multitexture_type==MTYPE_TEXTURE)		// Base
	{
		// Set stage (base)
		texture_base->texture->Apply(0);

		// Disable last stage
		Storm3D2->device.SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_DISABLE);
	}
	else if (multitexture_type==MTYPE_DUALTEX)		// Base+Base2
	{
		// Set stage (base)
		texture_base->texture->Apply(0);
		
		// Set stage (base2)
		texture_base2->texture->Apply(1);
		Storm3D2->device.SetTextureStageState(1,D3DTSS_COLOROP,texture_base2->GetDX8MultitexBlendingOp());

		// Disable last stage
		Storm3D2->device.SetTextureStageState(2,D3DTSS_COLOROP,D3DTOP_DISABLE);
	}
	else if (multitexture_type==MTYPE_REF)			// Reflection
	{		
		// Set stage (reflection)
		texture_reflection->texture->Apply(0);
	
		// Reflection texture (or projective?)
		if (texture_reflection->texcoord_gen==TEX_GEN_REFLECTION)
		{
			Storm3D2->device.SetTextureStageState(0,D3DTSS_TEXCOORDINDEX,D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);

			// Correct number of texturecoordinates
			if (texture_reflection->texture->IsCube())
				Storm3D2->device.SetTextureStageState(0,D3DTSS_TEXTURETRANSFORMFLAGS,D3DTTFF_COUNT3);
			else
				Storm3D2->device.SetTextureStageState(0,D3DTSS_TEXTURETRANSFORMFLAGS,D3DTTFF_COUNT2);
		

			// Rotate the reflection
			VC3 camdir=scene->camera.GetDirection();
			float angle_y=VC2(camdir.x,camdir.z).CalculateAngle();
			float angle_x=VC2(VC2(camdir.x,camdir.z).GetLength(),camdir.y).CalculateAngle();
			MAT mat;
			mat.CreateRotationMatrix(QUAT(-angle_x,-angle_y,0));

			if (!texture_reflection->texture->IsCube())
			{	
				// Fix reflection (v2.3)
				float mt[16]=
				{
					0.5,	0,		0,	0,
					0,		-0.5,	0,	0,
					0,		0,		1,	0,
					0.5,	0.5,	0,	1
				};
				MAT mat2(mt);
				mat.Multiply(mat2);
			
				// Flip texture upside down
				//mat.Multiply(MAT(VC3(1,-1,1)));	
			}

			// Set texture rotation matrix
			D3DMATRIX dxmat;
			mat.GetAsD3DCompatible4x4((float*)&dxmat);
			Storm3D2->device.SetTransform(D3DTS_TEXTURE0,&dxmat);
		}
		else	// Projective texture
		{
			// Create matrix, tu=(0.5+0.87*x)/z, tv=(0.5-0.87*y)/z 
		    D3DXMATRIX mat;
			mat._11=0.866f;mat._12=0.0f;mat._13=0.0f;
			mat._21=0.0f;mat._22=-0.866f;mat._23=0.0f;
			mat._31=0.5f;mat._32=0.5f;mat._33=1.0f;
			mat._41=0.0f;mat._42=0.0f;mat._43=0.0f;
			
			// If it's mirror negate _11
			if (texture_reflection->texcoord_gen==TEX_GEN_PROJECTED_MIRROR)
				mat._11*=-1;

		    Storm3D2->device.SetTransform(D3DTS_TEXTURE0,&mat);
			Storm3D2->device.SetTextureStageState(0,D3DTSS_TEXTURETRANSFORMFLAGS,D3DTTFF_COUNT3|D3DTTFF_PROJECTED);
			Storm3D2->device.SetTextureStageState(0,D3DTSS_TEXCOORDINDEX,D3DTSS_TCI_CAMERASPACEPOSITION);
		}

		// Disable last stage
		Storm3D2->device.SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_DISABLE);
	}
	else if (multitexture_type==MTYPE_TEX_REF)		// Base+Reflection
	{
		// Set stage (base)
		texture_base->texture->Apply(0);

		// Set stage (reflection)
		texture_reflection->texture->Apply(1);
		Storm3D2->device.SetTextureStageState(1,D3DTSS_COLOROP,texture_reflection->GetDX8MultitexBlendingOp());
		
		// Reflection texture (or projective?)
		if (texture_reflection->texcoord_gen==TEX_GEN_REFLECTION)
		{
			Storm3D2->device.SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);

			// Correct number of texturecoordinates
			if (texture_reflection->texture->IsCube())
				Storm3D2->device.SetTextureStageState(1,D3DTSS_TEXTURETRANSFORMFLAGS,D3DTTFF_COUNT3);
			else
				Storm3D2->device.SetTextureStageState(1,D3DTSS_TEXTURETRANSFORMFLAGS,D3DTTFF_COUNT2);

			// Rotate the reflection
			VC3 camdir=scene->camera.GetDirection();
			float angle_y=VC2(camdir.x,camdir.z).CalculateAngle();
			float angle_x=VC2(VC2(camdir.x,camdir.z).GetLength(),camdir.y).CalculateAngle();
			MAT mat;
			mat.CreateRotationMatrix(QUAT(-angle_x,-angle_y,0));

			if (!texture_reflection->texture->IsCube())
			{	
				// Fix reflection (v2.3)
				float mt[16]=
				{
					0.5,	0,		0,	0,
					0,		-0.5,	0,	0,
					0,		0,		1,	0,
					0.5,	0.5,	0,	1
				};
				MAT mat2(mt);
				mat.Multiply(mat2);
			}

			// Set texture rotation matrix
			D3DMATRIX dxmat;
			mat.GetAsD3DCompatible4x4((float*)&dxmat);
			Storm3D2->device.SetTransform(D3DTS_TEXTURE1,&dxmat);
		}
		else	// Projective mirror texture
		{
			// Create matrix, tu=(0.5+0.87*x)/z, tv=(0.5-0.87*y)/z 
			D3DXMATRIX mat;
			mat._11=0.866f;mat._12=0.0f;mat._13=0.0f;
			mat._21=0.0f;mat._22=-0.866f;mat._23=0.0f;
			mat._31=0.5f;mat._32=0.5f;mat._33=1.0f;
			mat._41=0.0f;mat._42=0.0f;mat._43=0.0f;

			// If it's mirror negate _11
			if (texture_reflection->texcoord_gen==TEX_GEN_PROJECTED_MIRROR)
				mat._11*=-1;

			Storm3D2->device.SetTransform(D3DTS_TEXTURE1,&mat);
			Storm3D2->device.SetTextureStageState(1,D3DTSS_TEXTURETRANSFORMFLAGS,D3DTTFF_COUNT3|D3DTTFF_PROJECTED);
			Storm3D2->device.SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,D3DTSS_TCI_CAMERASPACEPOSITION);
		}

		// Disable last stage
		Storm3D2->device.SetTextureStageState(2,D3DTSS_COLOROP,D3DTOP_DISABLE);
	}

	// Setup material
	D3DMATERIAL9 mat;

	// Set diffuse
	mat.Diffuse.r=mat.Ambient.r=color.r;
	mat.Diffuse.g=mat.Ambient.g=color.g;
	mat.Diffuse.b=mat.Ambient.b=color.b;
	mat.Diffuse.a=mat.Ambient.a=0;

	// Set self.illum
	mat.Emissive.r=self_illum.r;
	mat.Emissive.g=self_illum.g;
	mat.Emissive.b=self_illum.b;
	mat.Emissive.a=0;

	// Set specular
	mat.Specular.r=specular.r;
	mat.Specular.g=specular.g;
	mat.Specular.b=specular.b;
	mat.Specular.a=0;
	mat.Power=specular_sharpness;

	// Set specular on only if it's used
	if ((specular_sharpness>1)&&
		((specular.r>0.01f)||(specular.g>0.01f)||(specular.b>0.01f)))
	{
		Storm3D2->device.SetRenderState(D3DRS_SPECULARENABLE,TRUE);
	} else Storm3D2->device.SetRenderState(D3DRS_SPECULARENABLE,FALSE);

	// Set 2sided
//	if (doublesided) Storm3D2->device.SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
//		else Storm3D2->device.SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);

	// Set wireframe
	if (wireframe) Storm3D2->device.SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
		else Storm3D2->device.SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
	
	// BETA!!!
	//Storm3D2->device.SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);

	// Set alphablending
	if (alphablend_type==ATYPE_NONE)
	{
		Storm3D2->device.SetRenderState(D3DRS_ZWRITEENABLE,TRUE);
		Storm3D2->device.SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
	}
	else if (alphablend_type==ATYPE_USE_TRANSPARENCY)
	{
		if (transparency>0.001f)
		{
			mat.Diffuse.a=1.0f-transparency;
			Storm3D2->device.SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
			Storm3D2->device.SetRenderState(D3DRS_ALPHATESTENABLE,FALSE);
			Storm3D2->device.SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
			Storm3D2->device.SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE);
			Storm3D2->device.SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
			Storm3D2->device.SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
			Storm3D2->device.SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);				
		}
		else
		{
			Storm3D2->device.SetRenderState(D3DRS_ZWRITEENABLE,TRUE);
			Storm3D2->device.SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
		}
	}
	else if (alphablend_type==ATYPE_USE_TEXTRANSPARENCY || alphablend_type==IStorm3D_Material::ATYPE_USE_ALPHATEST)
	{
		mat.Diffuse.a=1.0f-transparency;

		Storm3D2->device.SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);

		if(alphablend_type==IStorm3D_Material::ATYPE_USE_ALPHATEST)
			Storm3D2->device.SetRenderState(D3DRS_ZWRITEENABLE,TRUE);
		else
			Storm3D2->device.SetRenderState(D3DRS_ZWRITEENABLE,FALSE);

		if ((multitexture_type==MTYPE_DOT3_TEX)||(multitexture_type==MTYPE_DOT3_REF))
		{
			// Stage 1 alphamap (no diffuse)
			Storm3D2->device.SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE);
			Storm3D2->device.SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
			Storm3D2->device.SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG2);
			Storm3D2->device.SetTextureStageState(1,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
			Storm3D2->device.SetTextureStageState(1,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
			Storm3D2->device.SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
		}
		else	
		{
			// Stage 0 alphamap * diffuse
			Storm3D2->device.SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
			Storm3D2->device.SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE);
			Storm3D2->device.SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
		}
		Storm3D2->device.SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
		Storm3D2->device.SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

		Storm3D2->device.SetRenderState(D3DRS_ALPHAREF,(DWORD)0x00000001);
		Storm3D2->device.SetRenderState(D3DRS_ALPHAFUNC,D3DCMP_GREATEREQUAL);
		Storm3D2->device.SetRenderState(D3DRS_ALPHATESTENABLE,TRUE);
	}
	else if (alphablend_type==ATYPE_ADD)
	{
		Storm3D2->device.SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		Storm3D2->device.SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
		Storm3D2->device.SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);
		Storm3D2->device.SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
	}
	else if (alphablend_type==ATYPE_MUL)
	{
		Storm3D2->device.SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		Storm3D2->device.SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ZERO);
		Storm3D2->device.SetRenderState(D3DRS_DESTBLEND,D3DBLEND_SRCCOLOR);
		Storm3D2->device.SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
	}
	else if (alphablend_type==ATYPE_MUL2X)
	{
		Storm3D2->device.SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		Storm3D2->device.SetRenderState(D3DRS_SRCBLEND,D3DBLEND_DESTCOLOR);
		Storm3D2->device.SetRenderState(D3DRS_DESTBLEND,D3DBLEND_SRCCOLOR);
		Storm3D2->device.SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
	}

	// Use this material
	Storm3D2->device.SetMaterial(&mat);
/* PSD
	// Apply shader
	if (!ApplyShaderIfAvailable(scene,mtx)) Storm3D2->device.SetVertexShader(fvf);
*/
	// Set active material
	Storm3D2->active_material=this;

	return false;
}
Example #14
0
void Storm3D_Material::ResetScrollPosition()
{
	scrollOffset1 = VC2();
	scrollOffset2 = VC2();
}
	bool initStormResources()
	{
		if(width == 0 || height == 0)
			return false;

		if(useDynamicTextures)
		{
			/*
			if(downscaled)
			{
				width /= 2;
				height /= 2;
			}
			*/

			IStorm3D_Texture::TEXTYPE textype = IStorm3D_Texture::TEXTYPE_DYNAMIC_LOCKABLE;

			texture1.reset(static_cast<Storm3D_Texture *> (storm.CreateNewTexture(width, height, textype)), std::mem_fun(&Storm3D_Texture::Release));
			texture2.reset(static_cast<Storm3D_Texture *> (storm.CreateNewTexture(width, height, textype)), std::mem_fun(&Storm3D_Texture::Release));

			activeTexture = texture1;
			if(!texture1 || !texture2)
				return false;
		}
		else
		{
			ramTexture.reset(new Storm3D_Texture(&storm, width, height, IStorm3D_Texture::TEXTYPE_RAM), std::mem_fun(&Storm3D_Texture::Release));
			texture1.reset(static_cast<Storm3D_Texture *> (storm.CreateNewTexture(width, height, IStorm3D_Texture::TEXTYPE_DYNAMIC)), std::mem_fun(&Storm3D_Texture::Release));
			texture2.reset(static_cast<Storm3D_Texture *> (storm.CreateNewTexture(width, height, IStorm3D_Texture::TEXTYPE_DYNAMIC)), std::mem_fun(&Storm3D_Texture::Release));

			activeTexture = texture1;
			if(!texture1 || !texture2 || !ramTexture)
				return false;
		}

		material.reset(new Storm3D_Material(&storm, "video material"));
		if(!material)
			return false;

		Storm3D_SurfaceInfo info = storm.GetScreenSize();
		int windowSizeX = info.width;
		int windowSizeY = info.height;

		if(useDynamicTextures)
		{
			material->SetBaseTexture(activeTexture.get());
		}
		else
		{
			material->SetBaseTexture(activeTexture.get());
		}

		int x1 = 0;
		int y1 = 0;
		int x2 = windowSizeX;
		int y2 = windowSizeY;

		float textureRatio = float(width) / float(height);
		y2 = int(windowSizeX / textureRatio);
		y1 = (windowSizeY - y2) / 2;
		y2 += y1;

		start = VC2(float(x1), float(y1));
		end = VC2(float(x2-x1), float(y2-y1));

		return true;
	}
//------------------------------------------------------------------
// Storm3D_Scene_LightHandler::RenderLensFlares
//------------------------------------------------------------------
void Storm3D_Scene_LightHandler::RenderLensFlares(Storm3D_Scene *scene)
{	
	// RStates on
	//Storm3D2->D3DDevice->SetRenderState(D3DRS_ZENABLE,FALSE);
	Storm3D2->D3DDevice->SetRenderState(D3DRS_ZENABLE,TRUE);
	Storm3D2->D3DDevice->SetRenderState(D3DRS_ZWRITEENABLE,FALSE);

	// Loop through each light in set
	for (set<IStorm3D_Light*>::iterator it=lights.begin();it!=lights.end();it++)
	{
		// Typecast (to simplify code)
		IStorm3D_Light *lgt=(*it);

		// Skip directional lights
		if (lgt->GetLightType()==IStorm3D_Light::LTYPE_DIRECTIONAL) continue;

		// Typecasts (to simplify code)
		IStorm3D_Light_Point *pl=(IStorm3D_Light_Point*)lgt;
		Storm3D_LensFlare *lfl=(Storm3D_LensFlare*)pl->GetLensFlare();

		// If has lensflare: render it
		if (lfl)
		{
			// Calculate position on screen
			VC3 scpos;
			float w,rz;

			// Calculate position, and render only if flare is visible
			if ((scene->camera.GetTransformedToScreen(pl->GetGlobalPosition(),scpos,w,rz))
				&&(rz<scene->camera.vis_range))
			// BETA: here should be x/y visibility test
			{
				// Flare vis-multiplier
				//float sizemul=0;

				//Storm3D_CollisionInfo cinf;
				/*
				VC3 dir=pl->GetGlobalPosition()-scene->camera.GetPosition();
				float len=dir.GetLength();
				dir*=1/len;
				scene->RayTrace(scene->camera.GetPosition(),dir,len,cinf);
				*/
				
				// Test visibility (visbuffer)
				/*if (cinf.hit)
				{
					// Flare visibility (fades out)
					if (pl->GetLightType()==IStorm3D_Light::LTYPE_SPOT)
					{
						((Storm3D_Light_Spot*)pl)->flarevis-=scene->time_dif/100.0f;
						if (((Storm3D_Light_Spot*)pl)->flarevis<0)
							((Storm3D_Light_Spot*)pl)->flarevis=0;
						sizemul=((Storm3D_Light_Spot*)pl)->flarevis;
					}
					else
					{
						((Storm3D_Light_Point*)pl)->flarevis-=scene->time_dif/100.0f;
						if (((Storm3D_Light_Point*)pl)->flarevis<0)
							((Storm3D_Light_Point*)pl)->flarevis=0;
						sizemul=((Storm3D_Light_Point*)pl)->flarevis;
					}
				}
				else
				{
					// Flare visibility (fades in)
					if (pl->GetLightType()==IStorm3D_Light::LTYPE_SPOT)
					{
						((Storm3D_Light_Spot*)pl)->flarevis+=scene->time_dif/100.0f;
						if (((Storm3D_Light_Spot*)pl)->flarevis>1) 
							((Storm3D_Light_Spot*)pl)->flarevis=1;
						sizemul=((Storm3D_Light_Spot*)pl)->flarevis;
					}
					else
					{
						((Storm3D_Light_Point*)pl)->flarevis+=scene->time_dif/100.0f;
						if (((Storm3D_Light_Point*)pl)->flarevis>1) 
							((Storm3D_Light_Point*)pl)->flarevis=1;
						sizemul=((Storm3D_Light_Point*)pl)->flarevis;
					}
				}*/

				// Do not render invisible flares
				//if (sizemul<0.01f) continue;

				// Get viewport size
				Storm3D_SurfaceInfo ss=Storm3D2->GetScreenSize();

				// Create 3d-vector
				VC3 pos=VC3(scpos.x*ss.width,scpos.y*ss.height,scpos.z);

				// Render glow
				if (lfl->tex_glow)
				{
					// Calculate size
					//float hsizex=(lfl->glow_size/rz)*sizemul*width;
					//float hsizey=(lfl->glow_size/rz)*sizemul*height;
					float hsizex=(lfl->glow_size/rz)*ss.width;
					float hsizey=(lfl->glow_size/rz)*ss.height;

					// Create color (color+alpha)
					DWORD col=lgt->GetColor().GetAsD3DCompatibleARGB();

					// Apply the texture
					lfl->tex_glow->Apply(0);

					// Create a quad
					VXFORMAT_2D vx[4];
					vx[0]=VXFORMAT_2D(pos+VC3(-hsizex,hsizey,0),1,col,VC2(0,1));
					vx[1]=VXFORMAT_2D(pos+VC3(-hsizex,-hsizey,0),1,col,VC2(0,0));
					vx[2]=VXFORMAT_2D(pos+VC3(hsizex,hsizey,0),1,col,VC2(1,1));
					vx[3]=VXFORMAT_2D(pos+VC3(hsizex,-hsizey,0),1,col,VC2(1,0));

					// Clip
					if (Clip2DRectangle(Storm3D2,vx[1],vx[2])) 
					{
						// Copy clipping
						vx[0].position.x=vx[1].position.x;
						vx[0].texcoords.x=vx[1].texcoords.x;
						vx[3].position.y=vx[1].position.y;
						vx[3].texcoords.y=vx[1].texcoords.y;
						vx[0].position.y=vx[2].position.y;
						vx[0].texcoords.y=vx[2].texcoords.y;
						vx[3].position.x=vx[2].position.x;
						vx[3].texcoords.x=vx[2].texcoords.x;

						// Render it
						Storm3D2->D3DDevice->SetVertexShader(FVF_VXFORMAT_2D);
						Storm3D2->D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,vx,sizeof(VXFORMAT_2D));
						scene->AddPolyCounter(2);
					}
				}

				// Calc position (origin transformed to center of screen)
				//VC3 gp=pos-VC3(width*0.5f,height*0.5f,0);

				// Render ring
				/*if (lfl->tex_ring)
				{
					pos=gp*(0.6f)+VC3(width*0.5f,height*0.5f,0);

					// Calculate size
					float hsizex=(lfl->ring_size/rz)*sizemul*width;
					float hsizey=(lfl->ring_size/rz)*sizemul*height;

					// Create color (color+alpha)
					DWORD col=(lgt->GetColor()*0.5f).GetAsD3DCompatibleARGB();

					// Apply the texture
					lfl->tex_ring->Apply(0);

					// Create a quad
					VXFORMAT_2D vx[4];
					vx[0]=VXFORMAT_2D(pos+VC3(-hsizex,hsizey,0),1,col,VC2(0,1));
					vx[1]=VXFORMAT_2D(pos+VC3(-hsizex,-hsizey,0),1,col,VC2(0,0));
					vx[2]=VXFORMAT_2D(pos+VC3(hsizex,hsizey,0),1,col,VC2(1,1));
					vx[3]=VXFORMAT_2D(pos+VC3(hsizex,-hsizey,0),1,col,VC2(1,0));

					// Clip
					if (Clip2DRectangle(Storm3D2,vx[1],vx[2])) 
					{
						// Copy clipping
						vx[0].position.x=vx[1].position.x;
						vx[0].texcoords.x=vx[1].texcoords.x;
						vx[3].position.y=vx[1].position.y;
						vx[3].texcoords.y=vx[1].texcoords.y;
						vx[0].position.y=vx[2].position.y;
						vx[0].texcoords.y=vx[2].texcoords.y;
						vx[3].position.x=vx[2].position.x;
						vx[3].texcoords.x=vx[2].texcoords.x;

						// Render it
						Storm3D2->D3DDevice->SetVertexShader(FVF_VXFORMAT_2D);
						Storm3D2->D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,vx,sizeof(VXFORMAT_2D));	
					}
				}*/

					// Renderoidaan ympyrät (pienet)
					/*if (lflare[dxlight_handle[lg].owner->lensflare].pic_circle>=0)
					for (float f=-2.3f;f<2.5f;f+=0.7f)
					{
						sx=0.5f+(gxp*f);
						sy=0.5f+(gyp*f);
						float xsiz=xl*(fabsf(f)*0.2f+0.1f);
						float ysiz=yl*(fabsf(f)*0.2f+0.1f);
						RenderTexture(lflare[dxlight_handle[lg].owner->lensflare].pic_circle,sx-(xsiz/2.0f),sy-(ysiz/2.0f),-1,xsiz,ysiz,
							dxlight_handle[lg].owner->r/4.0f,dxlight_handle[lg].owner->g/4.0f,dxlight_handle[lg].owner->b/4.0f,0,0,1,1,0,ST3D_ALPHA_ADD);
					}*/

			}
			/*else
			{
				// Flare visibility (fades out)
				if (pl->GetLightType()==IStorm3D_Light::LTYPE_SPOT)
				{
					((Storm3D_Light_Spot*)pl)->flarevis-=scene->time_dif/100.0f;
					if (((Storm3D_Light_Spot*)pl)->flarevis<0)
						((Storm3D_Light_Spot*)pl)->flarevis=0;
				}
				else
				{
					((Storm3D_Light_Point*)pl)->flarevis-=scene->time_dif/100.0f;
					if (((Storm3D_Light_Point*)pl)->flarevis<0)
						((Storm3D_Light_Point*)pl)->flarevis=0;
				}
			}*/
		}
	}

	// RStates off
	Storm3D2->D3DDevice->SetRenderState(D3DRS_ZENABLE,TRUE);
}