Ejemplo n.º 1
0
void TXFFont::initFromStream(std::istream &source)
{
    bool    swapit, valid = true;
    UChar8  u_magic, *imageBuffer = NULL;
    Char8   c_magic[3];
    UInt32  ibuff, bitWidth = 0, stride;
    UInt16  sbuff;
    Int32   i, j;

    valid &= !source.fail();
    // checking sourcetype
    source >> u_magic;
    valid &= !source.fail();

    if(!(u_magic == 0xff))
        valid = false;

    source.read(c_magic, 3);
    valid &= !source.fail();

    if(strncmp(c_magic, "txf", 3))
        valid = false;

    source.read(reinterpret_cast < Char8 * > (&ibuff), 4);
    valid &= !source.fail();
    swapit = (ibuff == 0x12345678 ? false : true);

    if(swapit && (ibuff - 0x78563412))
        valid = false;

    valid &= sRead(source, &_txfIsBitmap, 4, swapit);
    valid &= sRead(source, &_txfFontWidth, 4, swapit);
    valid &= sRead(source, &_txfFontHeight, 4, swapit);
    valid &= sRead(source, &_txfFontMaxAscent, 4, swapit);
    valid &= sRead(source, &_txfFontMaxDescent, 4, swapit);
    valid &= sRead(source, &_txfNumGlyphs, 4, swapit);

    valid &= !(_txfIsBitmap > 1);

    _txfFontMaxDescent =
        _txfFontMaxDescent > 0 ? _txfFontMaxDescent * -1 : _txfFontMaxDescent;

    if(!valid)
    {
        _valid = valid;
        return;
    }

    // read content: glyph info
    _txfGlyphs = new txfChar[256];

    for(i = 0; i < _txfNumGlyphs; i++)
    {
        valid &= sRead(source, &sbuff, 2, swapit);
        source.read(reinterpret_cast<Char8 *>(
                        _txfGlyphs[UChar8(sbuff)].dimensions), 6);
        valid &= sRead(source, &_txfGlyphs[UChar8(sbuff)].x, 2, swapit);
        valid &= sRead(source, &_txfGlyphs[UChar8(sbuff)].y, 2, swapit);
        _txfGlyphs[UChar8(sbuff)].remapped = 0;

        if(!valid)
        {
            delete [] _txfGlyphs;

            _txfGlyphs = NULL;
            _valid = valid;

            return;
        }
    }

    if(_txfIsBitmap)
    {
        bitWidth = (_txfFontWidth + 7) / 8;
        imageBuffer = new UChar8[bitWidth * _txfFontHeight];
        source.read(reinterpret_cast < Char8 * > (imageBuffer),
                    bitWidth * _txfFontHeight);
    }
    else
    {
        imageBuffer = new UChar8[_txfFontWidth * _txfFontHeight];
        source.read(reinterpret_cast < Char8 * > (imageBuffer),
                    _txfFontWidth * _txfFontHeight);
    }

    valid &= !source.fail();

    if(!valid)
    {
        delete [] _txfGlyphs;
        delete [] imageBuffer;

        _txfGlyphs   = NULL;
        imageBuffer = NULL;
        _valid = valid;

        return;
    }

    _txfImageMap = new UChar8[_txfFontWidth * _txfFontHeight * 2];

    stride = 0;

    if(_txfIsBitmap)
    {
        for(i = 0; i < _txfFontHeight; i++)
        {
            for(j = 0; j < _txfFontWidth; j++, stride += 2)
            {
                _txfImageMap[stride] = _txfImageMap[stride + 1] =
                                           imageBuffer[i * bitWidth + (j >> 3)] &
                                           (1 << (j & 7)) ? 255 : 0;
            }
        }
    }
    else
    {
        for(i = 0; i < _txfFontHeight; i++)
void ColorDisplayFilter::changed(ConstFieldMaskArg whichField, 
                                 UInt32            origin,
                                 BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    if(0x0000 != (whichField & (ColorTableWidthFieldMask  |
                                ColorTableHeightFieldMask |
                                ColorTableDepthFieldMask  |
                                ColorTableFieldMask       )))
    {
        UInt32 c;
        std::vector<UChar8> vImageData;

        UInt32 uiWidth  = getColorTableWidth ();
        UInt32 uiHeight = getColorTableHeight();
        UInt32 uiDepth  = getColorTableDepth ();

        UInt32 uiSize = (uiWidth * uiHeight * uiDepth);

        if(uiSize != getMFColorTable()->size() || uiDepth < 2)
        {
            // create default linear table
            //FWARNING(("Wrong shading table size\n"));

            uiWidth = uiHeight = 1;

            uiDepth = 2;

            vImageData.push_back(0);
            vImageData.push_back(0);
            vImageData.push_back(0);

            vImageData.push_back(255);
            vImageData.push_back(255);
            vImageData.push_back(255);
        } 
        else
        {
            const MFColor3f &vColors = *(this->getMFColorTable());

            vImageData.resize(uiSize * 3);

            for(c = 0; c < uiSize ; ++c)
            {
                vImageData[c * 3 + 0] = UChar8(vColors[c][0] * 255);
                vImageData[c * 3 + 1] = UChar8(vColors[c][1] * 255);
                vImageData[c * 3 + 2] = UChar8(vColors[c][2] * 255);
            }
        }

        Image *pImg = this->getTableImage();

        if(pImg == NULL)
        {
            // Make Cluster Local
            ImageUnrecPtr pImage = Image::createLocal(FCLocal::Cluster);

            pImg = pImage;

            this->setTableImage(pImage);
        }

        pImg->set( Image::OSG_RGB_PF,
                   uiWidth, uiHeight, uiDepth,
                   1, 1, 0,
                  &vImageData[0]);

        
        SimpleSHLChunk *pShader = this->getFilterShader();

        if(pShader != NULL)
        {
            pShader->addUniformVariable("shadingWidth",  Int32(uiWidth));
            pShader->addUniformVariable("shadingHeight", Int32(uiHeight));
            pShader->addUniformVariable("shadingDepth",  Int32(uiDepth));
        }
    }
  
    if(0x0000 != (whichField & (MatrixFieldMask)))
    {
        SimpleSHLChunk *pShader = this->getFilterShader();

        if(pShader != NULL)
        {
            pShader->addUniformVariable("colorMatrix", getMatrix());
        }
    }

    if(0x0000 != (whichField & (GammaFieldMask)))
    {
        SimpleSHLChunk *pShader = this->getFilterShader();

        if(pShader != NULL)
        {
            pShader->addUniformVariable("gamma", getGamma());
        }
    }
}
Ejemplo n.º 3
0
//-------------------------------------------------------------------------------
// @ Player::ReadData()
//-------------------------------------------------------------------------------
// Read in geometry data
//-------------------------------------------------------------------------------
bool
Player::ReadData()
{
    // read in geometric data
    IvFileReader in("Tank.txt");
    if (!in)
        return false;

    unsigned int numVerts;
    
    // get number of vertices
    in >> numVerts;
    if ( !in.good() )
        return false;

    mVertices = IvRenderer::mRenderer->GetResourceManager()->CreateVertexBuffer(kCNPFormat, numVerts,
                                                                                nullptr, kDefaultUsage);
    IvCNPVertex* dataPtr = (IvCNPVertex*) mVertices->BeginLoadData();

    // read positions
    for ( UInt32 i = 0; i < numVerts; ++i )
    {
        float x, y, z;
        in >> x >> y >> z;
        dataPtr[i].position.Set(x,y,z);
        if (!in.good() )
        {
            CleanData();
            return false;
        }
    }

    // read normals
    for ( UInt32 i = 0; i < numVerts; ++i )
    {
        float x, y, z;
        in >> x >> y >> z;
        dataPtr[i].normal.Set(x,y,z);
        if (!in.good() )
        {
            CleanData();
            return false;
        }
    }

    // read colors
    for ( UInt32 i = 0; i < numVerts; ++i )
    {
        float r, g, b;
        in >> r >> g >> b;
        dataPtr[i].color.mRed = UChar8(r*255);
        dataPtr[i].color.mGreen = UChar8(g*255);
        dataPtr[i].color.mBlue = UChar8(b*255);
        dataPtr[i].color.mAlpha = 255;

        if (!in.good() )
        {
            CleanData();
            return false;
        }
    }

    if (!mVertices->EndLoadData())
    {
        CleanData();
        return false;
    }

    // get number of indices
    UInt32 numTankBodyIndices;
    in >> numTankBodyIndices;
    if ( !in.good() )
        return false;

    // read indices
    mIndices = IvRenderer::mRenderer->GetResourceManager()->CreateIndexBuffer(numTankBodyIndices,
                                                                              nullptr, kDefaultUsage);
    UInt32* indexPtr = static_cast<UInt32*>(mIndices->BeginLoadData());
    for ( UInt32 i = 0; i < numTankBodyIndices; ++i )
    {
        in >> indexPtr[i];
        if (!in.good() )
        {
            CleanData();
            return false;
        }
    }
    if (!mIndices->EndLoadData())
    {
        CleanData();
        return false;
    }

    // read in turret
    if ( !mTurret || !mTurret->ReadData() )
    {
        CleanData();
        return false;
    }

    return true;

}   // End of Player::ReadData()