void ZoomAnimation::OnRender() { std::auto_ptr<Surface> pSurface( getSurface()->ZoomSurface( m_curZoom ) ); if(pSurface.get() == 0) { return; } Dim destDim = pSurface->GetDim(); Dim srcDim = getSurface()->GetDim(); Coord srcCoord = getCoord(); // 그림이 확대, 축소되면 이미지 위치로 확대 축소된 값에 따라 변한다. int x = srcCoord.getX() + (srcDim.getW() - destDim.getW() ) / 2; int y = srcCoord.getY() + (srcDim.getH() - destDim.getH() ) / 2; pSurface->SetColorKey(); pSurface->Blit( x, y ); pSurface->Free(); }
Texture2D Texture2D::createFromImageByPath(const std::string &path) { // SDL_Surface *pSurface(IMG_Load(path.c_str())); // Texture2D ret(createFromSDLSurface(*pSurface)); // SDL_FreeSurface(pSurface); // return ret; unsigned imageId = ilGenImage(); ilBindImage(imageId); int success = ilLoadImage(path.c_str()); if (success) { success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); } if (!success) { ilDeleteImage(imageId); { SDL_Surface *pSurface(IMG_Load(path.c_str())); if (!pSurface) throw std::runtime_error("Cannot load texture " + path); unsigned id = createFromSDLSurface(*pSurface); SDL_FreeSurface(pSurface); if (id == 0) throw std::runtime_error("Cannot load texture: SDL_image not " "expected this format" + path); { Texture2D ret; ret.m_id = id; return ret; } } } Texture2D ret(createFromDevILBinded()); ilDeleteImage(imageId); return ret; }
CqTeapot::CqTeapot( bool addCrowBase ) : m_CrowBase( addCrowBase ) { int i; TqInt lUses; boost::shared_ptr<CqSurfacePatchMeshBicubic> pSurface( new CqSurfacePatchMeshBicubic( 13, 10, RI_TRUE, RI_TRUE ) ); lUses = pSurface->Uses(); // Fill in default values for all primitive variables not explicitly specified. // Fill in primitive variables specified. pSurface->AddPrimitiveVariable( new CqParameterTypedVertex<CqVector4D, type_hpoint, CqVector3D>( "P", 1 ) ); pSurface->P() ->SetSize( 13 * 10 ); for ( i = 0; i < 13*10; i++ ) pSurface->P()->pValue( i )[0] = vectorCast<CqVector4D>(Patch01[ i ]); pSurface->SetDefaultPrimitiveVariables(); pSurface->SetSurfaceParameters( *this ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Cs" ) ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Os" ) ); pSurface->Cs() ->SetSize( 130 ); pSurface->Os() ->SetSize( 130 ); for ( i = 0; i < 13*10; i++ ) { pSurface->Cs()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Color" ) [ 0 ]; pSurface->Os()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Opacity" ) [ 0 ]; } this->pPatchMeshBicubic[ 0 ] = pSurface; pSurface = boost::shared_ptr<CqSurfacePatchMeshBicubic>( new CqSurfacePatchMeshBicubic( 13, 7, RI_TRUE, RI_TRUE ) ); lUses = pSurface->Uses(); // Fill in default values for all primitive variables not explicitly specified. // Fill in primitive variables specified. pSurface->AddPrimitiveVariable( new CqParameterTypedVertex<CqVector4D, type_hpoint, CqVector3D>( "P", 1 ) ); pSurface->P() ->SetSize( 13 * 7 ); for ( i = 0; i < 13*7; i++ ) pSurface->P()->pValue( i )[0] = vectorCast<CqVector4D>(Patch02[ i ]); pSurface->SetDefaultPrimitiveVariables(); pSurface->SetSurfaceParameters( *this ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Cs" ) ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Os" ) ); pSurface->Cs() ->SetSize( 13 * 7 ); pSurface->Os() ->SetSize( 13 * 7 ); for ( i = 0; i < 13*7; i++ ) { pSurface->Cs()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Color" ) [ 0 ]; pSurface->Os()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Opacity" ) [ 0 ]; } this->pPatchMeshBicubic[ 1 ] = pSurface; pSurface = boost::shared_ptr<CqSurfacePatchMeshBicubic>( new CqSurfacePatchMeshBicubic( 4, 7, RI_TRUE, RI_TRUE ) ); lUses = pSurface->Uses(); // Fill in default values for all primitive variables not explicitly specified. // Fill in primitive variables specified. pSurface->AddPrimitiveVariable( new CqParameterTypedVertex<CqVector4D, type_hpoint, CqVector3D>( "P", 1 ) ); pSurface->P() ->SetSize( 4 * 7 ); for ( i = 0; i < 4*7; i++ ) pSurface->P()->pValue( i )[0] = vectorCast<CqVector4D>(Patch03[ i ]); pSurface->SetDefaultPrimitiveVariables(); pSurface->SetSurfaceParameters( *this ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Cs" ) ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Os" ) ); pSurface->Cs() ->SetSize( 4 * 7 ); pSurface->Os() ->SetSize( 4 * 7 ); for ( i = 0; i < 4*7; i++ ) { pSurface->Cs()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Color" ) [ 0 ]; pSurface->Os()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Opacity" ) [ 0 ]; } this->pPatchMeshBicubic[ 2 ] = pSurface; pSurface = boost::shared_ptr<CqSurfacePatchMeshBicubic>( new CqSurfacePatchMeshBicubic( 4, 7, RI_TRUE, RI_TRUE ) ); lUses = pSurface->Uses(); // Fill in default values for all primitive variables not explicitly specified. // Fill in primitive variables specified. pSurface->AddPrimitiveVariable( new CqParameterTypedVertex<CqVector4D, type_hpoint, CqVector3D>( "P", 1 ) ); pSurface->P() ->SetSize( 4 * 7 ); for ( i = 0; i < 4*7; i++ ) pSurface->P()->pValue( i )[0] = vectorCast<CqVector4D>(Patch04[ i ]); pSurface->SetDefaultPrimitiveVariables(); pSurface->SetSurfaceParameters( *this ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Cs" ) ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Os" ) ); pSurface->Cs() ->SetSize( 4 * 7 ); pSurface->Os() ->SetSize( 4 * 7 ); for ( i = 0; i < 4*7; i++ ) { pSurface->Cs()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Color" ) [ 0 ]; pSurface->Os()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Opacity" ) [ 0 ]; } this->pPatchMeshBicubic[ 3 ] = pSurface; pSurface = boost::shared_ptr<CqSurfacePatchMeshBicubic>( new CqSurfacePatchMeshBicubic( 4, 7, RI_TRUE, RI_TRUE ) ); lUses = pSurface->Uses(); // Fill in default values for all primitive variables not explicitly specified. // Fill in primitive variables specified. pSurface->AddPrimitiveVariable( new CqParameterTypedVertex<CqVector4D, type_hpoint, CqVector3D>( "P", 1 ) ); pSurface->P() ->SetSize( 4 * 7 ); for ( i = 0; i < 4*7; i++ ) pSurface->P()->pValue( i )[0] = vectorCast<CqVector4D>(Patch05[ i ]); pSurface->SetDefaultPrimitiveVariables(); pSurface->SetSurfaceParameters( *this ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Cs" ) ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Os" ) ); pSurface->Cs() ->SetSize( 4 * 7 ); pSurface->Os() ->SetSize( 4 * 7 ); for ( i = 0; i < 4*7; i++ ) { pSurface->Cs()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Color" ) [ 0 ]; pSurface->Os()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Opacity" ) [ 0 ]; } this->pPatchMeshBicubic[ 4 ] = pSurface; pSurface = boost::shared_ptr<CqSurfacePatchMeshBicubic>( new CqSurfacePatchMeshBicubic( 4, 7, RI_TRUE, RI_TRUE ) ); lUses = pSurface->Uses(); // Fill in default values for all primitive variables not explicitly specified. // Fill in primitive variables specified. pSurface->AddPrimitiveVariable( new CqParameterTypedVertex<CqVector4D, type_hpoint, CqVector3D>( "P", 1 ) ); pSurface->P() ->SetSize( 4 * 7 ); for ( i = 0; i < 4*7; i++ ) pSurface->P()->pValue( i )[0] = vectorCast<CqVector4D>(Patch06[ i ]); pSurface->SetDefaultPrimitiveVariables(); pSurface->SetSurfaceParameters( *this ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Cs" ) ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Os" ) ); pSurface->Cs() ->SetSize( 4 * 7 ); pSurface->Os() ->SetSize( 4 * 7 ); for ( i = 0; i < 4*7; i++ ) { pSurface->Cs()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Color" ) [ 0 ]; pSurface->Os()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Opacity" ) [ 0 ]; } this->pPatchMeshBicubic[ 5 ] = pSurface; this->cNbrPatchMeshBicubic = 6; // bottom if ( m_CrowBase ) { pSurface = boost::shared_ptr<CqSurfacePatchMeshBicubic>( new CqSurfacePatchMeshBicubic( 13, 4, RI_TRUE, RI_TRUE ) ); lUses = pSurface->Uses(); // Fill in default values for all primitive variables not explicitly specified. // Fill in primitive variables specified. pSurface->AddPrimitiveVariable( new CqParameterTypedVertex<CqVector4D, type_hpoint, CqVector3D>( "P", 1 ) ); pSurface->P() ->SetSize( 13 * 4 ); for ( i = 0; i < 13*4; i++ ) { if ( i < 13 ) pSurface->P()->pValue( i )[0] = CqVector4D(0.0f); else if ( i < 39 ) pSurface->P()->pValue( i )[0] = vectorCast<CqVector4D>(Patch01[ i - 13 ]); else pSurface->P()->pValue( i )[0] = vectorCast<CqVector4D>(Patch01[ i - 13 ] * 0.85); } pSurface->SetDefaultPrimitiveVariables(); pSurface->SetSurfaceParameters( *this ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Cs" ) ); pSurface->AddPrimitiveVariable( new CqParameterTypedVarying<CqColor, type_color, CqColor>( "Os" ) ); pSurface->Cs() ->SetSize( 13 * 4 ); pSurface->Os() ->SetSize( 13 * 4 ); for ( i = 0; i < 13*4; i++ ) { pSurface->Cs()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Color" ) [ 0 ]; pSurface->Os()->pValue( i )[0] = m_pAttributes->GetColorAttribute( "System", "Opacity" ) [ 0 ]; } this->pPatchMeshBicubic[ 6 ] = pSurface; this->cNbrPatchMeshBicubic = 7; } }
SDLSurface::SDLSurfaceSharedPtr SDLSurface::createRGBSurfaceSharedPtr( const RGBVideoFormat& videoFormat) { if (!videoFormat) { SDLSurfaceSharedPtr pSurface; return pSurface; } Uint32 flags = SDL_SWSURFACE; IntegerSize sizePixels(videoFormat.sizePixels()); SizeType width = sizePixels.width(); if (!width) { SDLSurfaceSharedPtr pSurface; return pSurface; } SizeType height = sizePixels.height(); if (!height) { SDLSurfaceSharedPtr pSurface; return pSurface; } SizeType depth = videoFormat.bitsPerPixel(); RGBFormat rgbFormat = videoFormat.rgbFormat(); Uint32 rMask = 0; Uint32 gMask = 0; Uint32 bMask = 0; Uint32 aMask = 0; #if SDL_BYTEORDER == SDL_BIG_ENDIAN switch (rgbFormat) { case RGB888: rMask = 0xff000000; gMask = 0x00ff0000; bMask = 0x0000ff00; break; case BGR888: rMask = 0x0000ff00; gMask = 0x00ff0000; bMask = 0xff000000; break; case RGBA8888: rMask = 0xff000000; gMask = 0x00ff0000; bMask = 0x0000ff00; aMask = 0x000000ff; break; case ABGR8888: rMask = 0x000000ff; gMask = 0x0000ff00; bMask = 0x00ff0000; aMask = 0xff000000; break; } #else switch (rgbFormat) { case RGB888: rMask = 0x000000ff; gMask = 0x0000ff00; bMask = 0x00ff0000; break; case BGR888: rMask = 0x00ff0000; gMask = 0x0000ff00; bMask = 0x000000ff; break; case RGBA8888: rMask = 0x000000ff; gMask = 0x0000ff00; bMask = 0x00ff0000; aMask = 0xff000000; break; case ABGR8888: rMask = 0xff000000; gMask = 0x00ff0000; bMask = 0x0000ff00; aMask = 0x000000ff; break; } #endif if (!rMask && !gMask && !bMask) { SDLSurfaceSharedPtr pSurface; return pSurface; } SDLSurfaceSharedPtr pSurface( new SDLSurface(SDL_CreateRGBSurface( flags, width, height, depth, rMask, gMask, bMask, aMask))); return pSurface; }