void Material::createDevicePrimitives( RenderContext & context ) { DisplayDevice * pDisplay = context.display(); ASSERT( pDisplay ); m_Material = NULL; // clear any previous primitive pDisplay->create( m_Material ); if ( context.alpha() < 1.0f ) { m_Material->setMaterial( Color( m_Diffuse.r, m_Diffuse.g, m_Diffuse.b, (u8)(context.alpha() * m_Diffuse.a) ), m_Ambient, m_Emissive, m_Specular, m_SpecularPower ); m_Material->setPass( DisplayDevice::SECONDARY ); if ( m_Blending == PrimitiveMaterial::NONE ) m_Material->setBlending( PrimitiveMaterial::ALPHA ); else m_Material->setBlending( m_Blending ); } else { m_Material->setMaterial( m_Diffuse, m_Ambient, m_Emissive, m_Specular, m_SpecularPower ); m_Material->setPass( m_nPass ); m_Material->setBlending( m_Blending ); } m_Material->setLightEnable( m_LightEnable ); m_Material->setDoubleSided( m_DoubleSided ); if ( m_sShader.length() > 0 ) m_Material->setShader( m_sShader ); if (! m_bSurfaceReady ) createDeviceSurfaces( context.display() ); // attach the surfaces to the material now if ( m_Surfaces.size() > 0 ) { Array< PrimitiveSurface::Ref > & surfaces = m_Surfaces[ 0 ]; ASSERT( surfaces.size() == m_Textures.size() ); for(int i=0;i<surfaces.size();++i) { Texture & texture = m_Textures[ i ]; m_Material->addSurface( surfaces[i], texture.m_eType, texture.m_nIndex, texture.m_nUV, texture.m_fParams ); } } m_nLastFrame = 0; m_fLastAlpha = context.alpha(); }
void NounShip::preRender( RenderContext &context, const Matrix33 & frame, const Vector3 & position ) { if (! sm_bShipSelection ) { if ( syncronized() ) { m_fFade += context.elapsed(); if ( m_fFade > 1.0f ) m_fFade = 1.0f; } else { m_fFade -= context.elapsed(); if ( m_fFade < 0.0f ) m_fFade = 0.0f; } float fContextAlpha = context.alpha(); float fAlpha = m_fFade * visibility(); if ( isLocal() && fAlpha < 0.25f ) fAlpha = 0.25f; if ( fAlpha > 0.0f ) { context.setAlpha( fAlpha * fContextAlpha ); // determine the render bits based on the state of the ship dword bits = ((!inOrbit() && worldVelocity().magnitude2() > 0.1f) ? THRUST : 0) | m_DamageBits; // show thrusters if jump drive is engaged if ( flags() & FLAG_JUMPING ) bits |= THRUST; dword nContextBits = context.bits(); context.setBits( bits ); NounBody::preRender( context, frame, position ); context.setAlpha( fContextAlpha ); context.setBits( nContextBits ); } } else { NounBody::preRender( context, frame, position ); } }