void PointStarVlist::EndDrawState(bool stretch, int whichTexture) {
    if (stretch)
        vlist->EndDrawState();
    else
        nonstretchvlist->EndDrawState();
    GFXColorMaterial(0);
}
bool PointStarVlist::BeginDrawState (const QVector &center, const Vector & velocity, const Vector & torque, bool roll, bool yawpitch, int whichTexture) {
    UpdateGraphics();
    static bool StarStreaks=XMLSupport::parse_bool(vs_config->getVariable("graphics","star_streaks","false"));
    GFXColorMaterial(AMBIENT|DIFFUSE);
    bool ret=false;
    if (StarStreaks) {
        Matrix rollMatrix;
        static float velstreakscale= XMLSupport::parse_float (vs_config->getVariable ("graphics","velocity_star_streak_scale","5"));
        static float minstreak= XMLSupport::parse_float (vs_config->getVariable ("graphics","velocity_star_streak_min","1"));
        static float fov_smoothing=XMLSupport::parse_float(vs_config->getVariable("graphics","warp.fovlink.smoothing",".4"));
        float fov_smoot = pow(double(fov_smoothing),GetElapsedTime());
        Vector vel (-velocity*velstreakscale);
        float speed = vel.Magnitude();

        if ((smoothstreak>=minstreak||vel.MagnitudeSquared()>=minstreak*minstreak)&&(speed>1.0e-7)) {
            ret=true;
            vel*=1./speed;
            speed = fov_smoot*speed + (1-fov_smoot)*smoothstreak;

            if (speed<minstreak) speed=minstreak;
            static float streakcap  = XMLSupport::parse_float (vs_config->getVariable ("graphics","velocity_star_streak_max","100"));
            if (speed>streakcap) {
                speed=streakcap;
            }
            vel=vel*speed;
            smoothstreak=speed;
            GFXColorVertex * v = vlist->BeginMutate(0)->colors;
            int numvertices = vlist->GetNumVertices();

            static float torquestreakscale= XMLSupport::parse_float (vs_config->getVariable ("graphics","torque_star_streak_scale","1"));
            for (int j=0; j<numvertices-1; j+=2) {
                int i=j;
//				if (SlowStarStreaks)
//					i=((rand()%numvertices)/2)*2;
                Vector vpoint (v[i+1].x,v[i+1].y,v[i+1].z);
                Vector recenter =(vpoint-center.Cast());
                if (roll) {
                    RotateAxisAngle(rollMatrix,torque,torque.Magnitude()*torquestreakscale*.003);
                    vpoint = Transform(rollMatrix,recenter)+center.Cast();
                }
                v[i].x=vpoint.i-vel.i;
                v[i].y=vpoint.j-vel.j;
                v[i].z=vpoint.k-vel.k;
//				static float NumSlowStarStreaks=XMLSupport::parse_float(vs_config->getVariable("graphics","num_star_streaks",".05"));
//				if (SlowStarStreaks&&j<NumSlowStarStreaks*numvertices)
//					break;
            }
            vlist->EndMutate();
        }
    }
    if (ret) {
        vlist->LoadDrawState();
        vlist->BeginDrawState();
    } else {
        nonstretchvlist->LoadDrawState();
        nonstretchvlist->BeginDrawState();
    }
    return ret;
}
/**
 * Draws the heightfield represented by this tree
 * Returns teh number of triangles rendered (not including multipass
 */
int quadsquare::Render( const quadcornerdata &cd, const Vector &camvec )
{
    quadsquare::camerapos = camvec;
    vertices->LoadDrawState();
    vertices->BeginDrawState( GFXFALSE );
    int totsize = 0;
    RenderAux( cd, GFX_PARTIALLY_VISIBLE );
    vecTextureIndex::iterator i = indices.begin();
    vecTextureStar::iterator  k;
    for (k = textures->begin(); k != textures->end(); i++, k++) {
        TerrainMakeActive( *k );
        unsigned int isize = (*i).q.size();
        totsize += isize;
        vertices->Draw( GFXTRI, isize, (*i).q.begin() );
        TerrainMakeDeactive( *k );
    }
    vertices->EndDrawState();
    i = indices.begin();
    int j = 0;
    for (k = textures->begin(); k != textures->end(); i++, j++, k++) {
        if ( (*i).c.size() > 2 ) {
            TerrainMakeClearActive( *k );
            GFXPolygonOffset( 0, -j );
            GFXColorMaterial( AMBIENT|DIFFUSE );
            GFXColorVertex **cv  = (&blendVertices->BeginMutate( 0 )->colors);
            GFXColorVertex  *tmp = *cv;
            *cv = (*i).c.begin();
            blendVertices->EndMutate( (*i).c.size() );
            blendVertices->LoadDrawState();
            blendVertices->BeginDrawState( GFXFALSE );
            blendVertices->Draw( GFXTRI, (*i).c.size() );
            blendVertices->EndDrawState( GFXFALSE );
            cv  = (&blendVertices->BeginMutate( 0 )->colors);
            *cv = tmp;
            blendVertices->EndMutate( 3 );
            GFXColorMaterial( 0 );
            GFXPolygonOffset( 0, 0 );
            TerrainMakeDeactive( *k );
        }
        (*i).Clear();
    }
    return totsize;
}
bool SpriteStarVlist::BeginDrawState(const QVector &center, const Vector &velocity, const Vector & torque, bool roll, bool yawpitch, int whichTex) {

    UpdateGraphics();
    GFXEnable(TEXTURE0);
    decal[whichTex]->MakeActive();
    GFXDisable(CULLFACE);
    GFXColorMaterial(AMBIENT|DIFFUSE);
    vlist[whichTex]->LoadDrawState();
    vlist[whichTex]->BeginDrawState();
    return false;
}
void SpriteStarVlist::EndDrawState(bool stretch, int whichTex) {
    vlist[whichTex]->EndDrawState();
    GFXDisable(TEXTURE0);
    GFXEnable(CULLFACE);
    GFXColorMaterial(0);
}