示例#1
0
int CBitmap::Render (CBitmap *destP,
							int xDest, int yDest, int wDest, int hDest,
							int xSrc, int ySrc, int wSrc, int hSrc,
							int bTransp, int bMipMaps, int bSmoothe,
							float fAlpha, tRgbaColorf* colorP)
{
	CBitmap*		bmoP;

if ((bmoP = HasOverride ()))
	return bmoP->Render (destP, xDest, yDest, wDest, hDest, xSrc, ySrc, wSrc, hSrc, bTransp, bMipMaps, bSmoothe, fAlpha, colorP);

	int			nTransp = (Flags () & BM_FLAG_TGA) ? -1 : HasTransparency () ? 2 : 0;
	bool			bLocal = Texture () == NULL;

//	ubyte *oldpal;
OglVertices (xDest, yDest, wDest, hDest, I2X (1), 0, destP);
tRgbaColorf color;
int nColors;
bool bBlend = bTransp && nTransp;

if (!colorP) {
	color.red = color.green = color.blue = 1.0f;
	color.alpha = bBlend ? fAlpha * gameStates.render.grAlpha : 1.0f;
	colorP = &color;
	nColors = 1;
	}
else
	nColors = 4;

if (!OglBeginRender (bBlend, bMipMaps, nTransp))
	return 1; // fail

m_render.u1 = m_render.v1 = 0;
if (wSrc < 0)
	m_render.u2 = float (destP->Width ()) / float (-wSrc);
else {
	m_render.u2 = float (wSrc) / float (Width ());
	if (m_render.u2 < 1.0f)
		m_render.u2 *= m_info.texP->U ();
	else
		m_render.u2 = m_info.texP->U ();
	}
if (hSrc < 0)
	m_render.v2 = float (destP->Height ()) / float (-hSrc);
else {
	m_render.v2 = float (hSrc) / float (Height ());
	if (m_render.v2 < 1.0f)
		m_render.v2 *= m_info.texP->V ();
	else
		m_render.v2 = m_info.texP->V ();
	}
OglRender (colorP, nColors, 0);
OglEndRender ();

if (bLocal) {
	m_info.texP->Destroy ();
	}
return 0;
}
示例#2
0
int GvMaterial::Apply(GglRenderTraversal &state,int matStatus,int texStatus)
{	int ret=0;

	gbool whiteDiffuse = (matStatus & MATERIAL_SET_DIFFUSE_WHITE) !=0;


#ifdef _OGL
		glSet();
		changed=0;
#endif

#ifdef _D3D
   float a;

   if (changed || !state.glState->SetMaterial(handle,whiteDiffuse)) {
	float am[4];
	float di[4];
	float sp[4];
	float em[4];
	if (transparency.Length()>0) {
		a = 1.0-transparency[0];
		if (a<1.0) ret |= MATERIAL_HAS_ALPHA;
	} else a = 1.0;

	ambientColor.GetRGBA(am,a);
	diffuseColor.GetRGBA(di,a);
	specularColor.GetRGBA(sp,a);
	emissiveColor.GetRGBA(em,a);

	if (IsEmissiveColorOnly()) {
		ret = matStatus |=  MATERIAL_IS_UNLIT;
	}

	if ( (matStatus & MATERIAL_IS_UNLIT) || state.glState->unlit) { // new 
			RGBAColor c;
			c.a = a;
			c.r = max(di[0],em[0]);
			c.g = max(di[1],em[1]);
			c.b = max(di[2],em[2]);
			// redefine handle
			state.glState->SetMaterial(handle,c);
		} else {


	
	float power;
	if (shininess.Length()>0) 
        power = shininess[0]*GV_SHININESS_GL_SCALE;
    else power = 3;

	TRACE("Redefining VRML 1.0 Material : texturing = %d  htex = %d White = %d \n",state.glState->texturing,state.glState->hTex,whiteDiffuse);

	// redefine handle 
    state.glState->SetMaterial(handle,am,di,sp,em,a,power,whiteDiffuse);
	}
	
	changed=0;
   } else { // 9.07.97 
	   // check alpha 
	   if (HasTransparency()) {
			if (transparency.Length()>0) {
				a = 1.0-transparency[0];
				if (a<1.0) ret |= MATERIAL_HAS_ALPHA;
			} else a = 1.0;
	   }

   }	

   // 28.03.97 same as Gv2Material::Apply
   if (ret & MATERIAL_HAS_ALPHA) {
			state.glState->SetMaterialAlpha(a);
   } 
   else  {
		if (texStatus & TEXTURE_HAS_ALPHA)
			state.glState->SetBlendFromMaterial(1);
		else 
			state.glState->SetMaterialAlphaOff();
   }	


#endif
   return(ret);
}