void	CRenderTarget::u_calc_tc_noise		(Fvector2& p0, Fvector2& p1)
{
	CTexture*	T					= RCache.get_ActiveTexture	(2);
	VERIFY2		(T, "Texture #3 in noise shader should be setted up");
	u32			tw					= iCeil(float(T->get_Width	())*param_noise_scale+EPS_S);
	u32			th					= iCeil(float(T->get_Height ())*param_noise_scale+EPS_S);
	VERIFY2		(tw && th, "Noise scale can't be zero in any way");

	// calculate shift from FPSes
	im_noise_time					-= Device.fTimeDelta;
	if (im_noise_time<0)			{
		im_noise_shift_w			= ::Random.randI(tw?tw:1);
		im_noise_shift_h			= ::Random.randI(th?th:1);
		float	fps_time			= 1/param_noise_fps;
		while (im_noise_time<0)		im_noise_time += fps_time;
	}

	u32			shift_w				= im_noise_shift_w;
	u32			shift_h				= im_noise_shift_h;
	float		start_u				= (float(shift_w)+.5f)/(tw);
	float		start_v				= (float(shift_h)+.5f)/(th);
	u32			_w					= Device.dwWidth;
	u32			_h					= Device.dwHeight;
	u32			cnt_w				= _w / tw;
	u32			cnt_h				= _h / th;
	float		end_u				= start_u + float(cnt_w) + 1;
	float		end_v				= start_v + float(cnt_h) + 1;
 
	p0.set		(start_u,	start_v	);
	p1.set		(end_u,		end_v	);
}
Exemple #2
0
void CUICustomItem::Render(FVF::TL*& Pointer, const Fvector2& pos, u32 color, 
						   float x1, float y1, float x2, float y2)
{
	CTexture* T		= RCache.get_ActiveTexture(0);
	Fvector2		ts;
	ts.set			(float(T->get_Width()),float(T->get_Height()));
	
	if (!(uFlags&flValidRect)){
		SetRect		(0,0,ts.x,ts.y);
	}
	if (!(uFlags&flValidOriginalRect)){
		iOriginalRect.set(0,0,ts.x,ts.y);
		uFlags |= flValidOriginalRect;
	}

	Fvector2 LTp,RBp;
	Fvector2 LTt,RBt;
	//координаты на экране в пикселях
	UI()->ClientToScreenScaled	(LTp, x1,y1);
	LTp.add						(pos);

	UI()->ClientToScreenScaled	(RBp, x2,y2);
	RBp.add						(pos);

	//текстурные координаты
	LTt.set			( iOriginalRect.x1/ts.x, iOriginalRect.y1/ts.y);
	RBt.set			( iOriginalRect.x2/ts.x, iOriginalRect.y2/ts.y);

	// Check mirror mode
	if (tmMirrorHorisontal == eMirrorMode || tmMirrorBoth == eMirrorMode)	std::swap	(LTt.x,RBt.x);
	if (tmMirrorVertical == eMirrorMode || tmMirrorBoth == eMirrorMode)		std::swap	(LTt.y,RBt.y);
	// clip poly
	sPoly2D			S; S.resize(4);
	S[0].set		(LTp.x-0.5f,LTp.y-0.5f,	LTt.x,LTt.y);	// LT
	S[1].set		(RBp.x-0.5f,LTp.y-0.5f,	RBt.x,LTt.y);	// RT
	S[2].set		(RBp.x-0.5f,RBp.y-0.5f,	RBt.x,RBt.y);	// RB
	S[3].set		(LTp.x-0.5f,RBp.y-0.5f,	LTt.x,RBt.y);	// LB
	
	sPoly2D D;
//	const C2DFrustum& FF = UI()->ScreenFrustum();
	sPoly2D* R		= UI()->ScreenFrustum().ClipPoly(S,D);
//	sPoly2D* R		= &S;
	if (R&&R->size()){
		for (u32 k=0; k<R->size()-2; k++){
			Pointer->set	((*R)[0+0].pt.x, (*R)[0+0].pt.y,	color, (*R)[0+0].uv.x, (*R)[0+0].uv.y); Pointer++;
			Pointer->set	((*R)[k+1].pt.x, (*R)[k+1].pt.y,	color, (*R)[k+1].uv.x, (*R)[k+1].uv.y); Pointer++;
			Pointer->set	((*R)[k+2].pt.x, (*R)[k+2].pt.y,	color, (*R)[k+2].uv.x, (*R)[k+2].uv.y); Pointer++;
		}
	}
}
Exemple #3
0
void CUICustomItem::Render(FVF::TL*& Pointer, const Fvector2& pos_ns, u32 color, float angle)
{
//.	angle = -0.3f;
	CTexture* T		= RCache.get_ActiveTexture(0);
	Fvector2		ts;
	Fvector2		hp;
	ts.set			(float(T->get_Width()),float(T->get_Height()));
	hp.set			(0.5f/ts.x,0.5f/ts.y);

	if (!(uFlags&flValidRect))	SetRect		(0,0,ts.x,ts.y);

	if (!(uFlags&flValidOriginalRect)){
		iOriginalRect.set(0,0,ts.x,ts.y);
		uFlags		|= flValidOriginalRect;
	}

	Fvector2							pivot,offset,SZ;
	SZ.set								(iVisRect.rb);

//	UI()->ClientToScreenScaled			(SZ, iVisRect.x2, iVisRect.y2);

	float cosA							= _cos(angle);
	float sinA							= _sin(angle);

	// Rotation
	if(!(uFlags&flValidHeadingPivot))	pivot.set(iVisRect.x2/2.f, iVisRect.y2/2.f);
	else								pivot.set(iHeadingPivot.x, iHeadingPivot.y);

//.	UI()->ClientToScreenScaled			(pivot, pivot.x, pivot.y);
	pivot.set							(pivot);
	offset.set							(pos_ns);

	Fvector2							LTt,RBt;
	LTt.set								(iOriginalRect.x1/ts.x+hp.x, iOriginalRect.y1/ts.y+hp.y);
	RBt.set								(iOriginalRect.x2/ts.x+hp.x, iOriginalRect.y2/ts.y+hp.y);
	// Check mirror mode
	if (tmMirrorHorisontal == eMirrorMode || tmMirrorBoth == eMirrorMode)	std::swap	(LTt.x,RBt.x);
	if (tmMirrorVertical == eMirrorMode || tmMirrorBoth == eMirrorMode)		std::swap	(LTt.y,RBt.y);
	// clip poly
	sPoly2D			S; S.resize(4);
	// LT
	S[0].set		(0.f,0.f,LTt.x,LTt.y);
	S[0].rotate_pt	(pivot,cosA,sinA);
	S[0].pt.add		(offset);
	// RT
	S[1].set		(SZ.x,0.f,RBt.x,LTt.y);
	S[1].rotate_pt	(pivot,cosA,sinA);
	S[1].pt.add		(offset);
	// RB
	S[2].set		(SZ.x,SZ.y,RBt.x,RBt.y);
	S[2].rotate_pt	(pivot,cosA,sinA);
	S[2].pt.add		(offset);
	// LB
	S[3].set		(0.f,SZ.y,LTt.x,RBt.y);
	S[3].rotate_pt	(pivot,cosA,sinA);
	S[3].pt.add		(offset);
	
	sPoly2D D;
	sPoly2D* R		= UI()->ScreenFrustum().ClipPoly(S,D);
	if (R&&R->size())
		for (u32 k=0; k<R->size(); k++,Pointer++)
		{
			Fvector2 _pt;
			UI()->ClientToScreenScaled			(_pt, (*R)[k].pt.x, (*R)[k].pt.y);
			Pointer->set						(_pt.x, _pt.y,	color, (*R)[k].uv.x, (*R)[k].uv.y); 
		}
}
Exemple #4
0
void dxUIRender::GetActiveTextureResolution(Fvector2 &res)
{
	CTexture* T		= RCache.get_ActiveTexture(0);
	res.set			(float(T->get_Width()),float(T->get_Height()));
}
Exemple #5
0
void CGameFont::OnRender()
{
	VERIFY				(g_bRendering);
	if (pShader)		RCache.set_Shader	(pShader);

	if (!(uFlags&fsValid)){
		CTexture* T		= RCache.get_ActiveTexture(0);
		vTS.set			((int)T->get_Width(),(int)T->get_Height());
/*
		vHalfPixel.set	(0.5f/float(vTS.x),0.5f/float(vTS.y));
		for (int i=0; i<256; i++){
			Fvector& tc	= TCMap[i];
			tc.x		/= float(vTS.x);
			tc.y		/= float(vTS.y);
			tc.z		/= float(vTS.x);
		}
		fTCHeight		= fHeight/float(vTS.y);
		uFlags			|= fsValid;
*/
		fTCHeight		= fHeight/float(vTS.y);
		uFlags			|= fsValid;
	}

	for (u32 i=0; i<strings.size(); ){
		// calculate first-fit
		int		count	=	1;
		int		length	=	xr_strlen(strings[i].string);
		while	((i+count)<strings.size()) {
			int	L	=	xr_strlen(strings[i+count].string);
			if ((L+length)<MAX_CHARS){
				count	++;
				length	+=	L;
			}
			else		break;
		}

		// lock AGP memory
		u32	vOffset;
		FVF::TL* v		= (FVF::TL*)RCache.Vertex.Lock	(length*4,pGeom.stride(),vOffset);
		FVF::TL* start	= v;

		// fill vertices
		u32 last		= i+count;
		for (; i<last; i++) {
			String		&PS	= strings[i];
			int			len	= xr_strlen(PS.string);
			if (len) {
				float	X	= float(iFloor(PS.x));
				float	Y	= float(iFloor(PS.y));
				float	S	= PS.height*g_current_font_scale.y;
				float	Y2	= Y+S;

				switch(PS.align)
				{
				case alCenter:	
						X	-= ( iFloor(SizeOf_(PS.string,PS.height)*.5f) ) * g_current_font_scale.x;	
						break;
				case alRight:	
						X	-=	iFloor(SizeOf_(PS.string,PS.height));		
						break;
				}

				u32	clr,clr2;
				clr2 = clr	= PS.c;
				if (uFlags&fsGradient){
					u32	_R	= color_get_R	(clr)/2;
					u32	_G	= color_get_G	(clr)/2;
					u32	_B	= color_get_B	(clr)/2;
					u32	_A	= color_get_A	(clr);
					clr2	= color_rgba	(_R,_G,_B,_A);
				}

				float	tu,tv;
				for (int j=0; j<len; j++)
				{
					int c			= GetCharRM	(PS.string[j]);
					
					Fvector l		= GetCharTC	(PS.string[j]);
					float scw		= l.z * g_current_font_scale.x;
					
//.					float scw		= vTS.x * l.z * g_current_font_scale.x;
					
					float fTCWidth	= l.z/vTS.x;

					if ((c>=0)&&!fis_zero(l.z))
					{
						tu			= l.x/vTS.x;//+vHalfPixel.x;
						tv			= l.y/vTS.y;//+vHalfPixel.y;
						v->set		(X-0.5f,		Y2-0.5f,	clr2,tu,			tv+fTCHeight);	v++;
						v->set		(X-0.5f,		Y-0.5f,		clr, tu,			tv);			v++;
						v->set		(X+scw-0.5f,	Y2-0.5f,	clr2,tu+fTCWidth,	tv+fTCHeight);	v++;
						v->set		(X+scw-0.5f,	Y-0.5f,		clr, tu+fTCWidth,	tv);			v++;
					}
					X+=scw*vInterval.x;
				}
			}
		}

		// Unlock and draw
		u32 vCount = (u32)(v-start);
		RCache.Vertex.Unlock		(vCount,pGeom.stride());
		if (vCount){
			RCache.set_Geometry		(pGeom);
			RCache.Render			(D3DPT_TRIANGLELIST,vOffset,0,vCount,0,vCount/2);
		}
	}
	strings.clear_not_free			();
}