void GD_EXTENSION_API CreateSFMLTexture( RuntimeScene & scene, const gd::String & imageName, unsigned int width, unsigned int height, const gd::String & colorStr ) { //Get or create the texture in memory std::shared_ptr<SFMLTextureWrapper> newTexture; if ( !scene.GetImageManager()->HasLoadedSFMLTexture(imageName) ) newTexture = std::shared_ptr<SFMLTextureWrapper>(new SFMLTextureWrapper); else newTexture = scene.GetImageManager()->GetSFMLTexture(imageName); //Get the color sf::Color color; bool colorIsOk = false; std::vector < gd::String > colors = colorStr.Split(U';'); if ( colors.size() == 3 ) { colorIsOk = true; color = sf::Color(colors[0].To<int>(), colors[1].To<int>(), colors[2].To<int>()); } //Create the SFML image and the SFML texture if ( width != 0 && height != 0 && colorIsOk ) newTexture->image.create(width, height, color); newTexture->texture.loadFromImage(newTexture->image); //Do not forget to update the associated texture scene.GetImageManager()->SetSFMLTextureAsPermanentlyLoaded(imageName, newTexture); //Otherwise }
void GD_EXTENSION_API CaptureScreen( RuntimeScene & scene, const gd::String & destFileName, const gd::String & destImageName ) { if ( !scene.renderWindow ) return; sf::Image capture = scene.renderWindow->capture(); if ( !destFileName.empty() ) capture.saveToFile(destFileName.ToLocale()); if ( !destImageName.empty() && scene.GetImageManager()->HasLoadedSFMLTexture(destImageName) ) { std::shared_ptr<SFMLTextureWrapper> sfmlTexture = scene.GetImageManager()->GetSFMLTexture(destImageName); sfmlTexture->image = capture; sfmlTexture->texture.loadFromImage(sfmlTexture->image); //Do not forget to update the associated texture } }
void GD_EXTENSION_API CopyImageOnAnother( const gd::String & destName, const gd::String & srcName, float destX, float destY, bool useTransparency,RuntimeScene & scene ) { if ( !scene.GetImageManager()->HasLoadedSFMLTexture(destName) ) return; if ( !scene.GetImageManager()->HasLoadedSFMLTexture(srcName) ) return; std::shared_ptr<SFMLTextureWrapper> dest = scene.GetImageManager()->GetSFMLTexture(destName); //Make sure the coordinates are correct. if ( destX < 0 || static_cast<unsigned>(destX) >= dest->texture.getSize().x) return; if ( destY < 0 || static_cast<unsigned>(destY) >= dest->texture.getSize().y) return; dest->image.copy(scene.GetImageManager()->GetSFMLTexture(srcName)->image, destX, destY, sf::IntRect(0, 0, 0, 0), useTransparency); dest->texture.loadFromImage(dest->image); }
void GD_EXTENSION_API OpenSFMLTextureFromFile( RuntimeScene & scene, const gd::String & fileName, const gd::String & imageName ) { //Get or create the texture in memory std::shared_ptr<SFMLTextureWrapper> newTexture; if ( !scene.GetImageManager()->HasLoadedSFMLTexture(imageName) ) newTexture = std::shared_ptr<SFMLTextureWrapper>(new SFMLTextureWrapper); else newTexture = scene.GetImageManager()->GetSFMLTexture(imageName); //Open the SFML image and the SFML texture newTexture->image.loadFromFile(fileName.ToLocale()); newTexture->texture.loadFromImage(newTexture->image); //Do not forget to update the associated texture scene.GetImageManager()->SetSFMLTextureAsPermanentlyLoaded(imageName, newTexture); }
void GD_API SetWindowIcon(RuntimeScene & scene, const std::string & imageName) { //Retrieve the image boost::shared_ptr<SFMLTextureWrapper> image = scene.GetImageManager()->GetSFMLTexture(imageName); if ( image == boost::shared_ptr<SFMLTextureWrapper>() ) return; scene.renderWindow->setIcon(image->image.getSize().x, image->image.getSize().y, image->image.getPixelsPtr()); }
RuntimeBox3DObject::RuntimeBox3DObject(RuntimeScene & scene, const gd::Object & object) : RuntimeObject(scene, object), zPosition(0), yaw(0), pitch(0), roll(0) { const Box3DObject & box3DObject = static_cast<const Box3DObject&>(object); SetWidth(box3DObject.GetWidth()); SetHeight(box3DObject.GetHeight()); SetDepth(box3DObject.GetDepth()); //Load resources frontTextureName = box3DObject.frontTextureName; topTextureName = box3DObject.topTextureName; bottomTextureName = box3DObject.bottomTextureName; leftTextureName = box3DObject.leftTextureName; rightTextureName = box3DObject.rightTextureName; backTextureName = box3DObject.backTextureName; frontTexture = scene.GetImageManager()->GetSFMLTexture(frontTextureName); topTexture = scene.GetImageManager()->GetSFMLTexture(topTextureName); bottomTexture = scene.GetImageManager()->GetSFMLTexture(bottomTextureName) ; leftTexture = scene.GetImageManager()->GetSFMLTexture(leftTextureName); rightTexture = scene.GetImageManager()->GetSFMLTexture(rightTextureName); backTexture = scene.GetImageManager()->GetSFMLTexture(backTextureName); }
void RuntimeSpriteObject::CopyImageOnImageOfCurrentSprite(RuntimeScene & scene, const gd::String & imageName, float xPosition, float yPosition, bool useTransparency) { if ( needUpdateCurrentSprite ) UpdateCurrentSprite(); ptrToCurrentSprite->MakeSpriteOwnsItsImage(); //We want to modify only the image of the object, not all objects which have the same image. std::shared_ptr<SFMLTextureWrapper> dest = ptrToCurrentSprite->GetSFMLTexture(); //Make sure the coordinates are correct. if ( xPosition < 0 || static_cast<unsigned>(xPosition) >= dest->texture.getSize().x) return; if ( yPosition < 0 || static_cast<unsigned>(yPosition) >= dest->texture.getSize().y) return; //Update texture and pixel perfect collision mask dest->image.copy(scene.GetImageManager()->GetSFMLTexture(imageName)->image, xPosition, yPosition, sf::IntRect(0, 0, 0, 0), useTransparency); dest->texture.loadFromImage(dest->image); }
RuntimeSpriteObject::RuntimeSpriteObject(RuntimeScene & scene, const gd::Object & object) : RuntimeObject(scene, object), currentAnimation( 0 ), currentDirection( 0 ), currentAngle( 0 ), currentSprite( 0 ), animationStopped(false), timeElapsedOnCurrentSprite(0.f), animationSpeedScale(1.f), ptrToCurrentSprite( NULL ), needUpdateCurrentSprite(true), opacity( 255 ), blendMode(0), isFlippedX(false), isFlippedY(false), scaleX( 1 ), scaleY( 1 ), colorR( 255 ), colorV( 255 ), colorB( 255 ) { if (!badSpriteDatas) badSpriteDatas = new gd::Sprite(); //Initialize the runtime object using the object const gd::SpriteObject & spriteObject = static_cast<const gd::SpriteObject&>(object); animations.clear(); for (std::size_t i = 0; i < spriteObject.GetAllAnimations().size(); ++i) animations.push_back(AnimationProxy(spriteObject.GetAllAnimations()[i])); //Load resources for ( std::size_t j = 0; j < animations.size();j++ ) { gd::Animation & anim = animations[j].GetNonConst(); for ( std::size_t k = 0;k < anim.GetDirectionsCount();k++ ) { for ( std::size_t l = 0;l < anim.GetDirection(k).GetSpritesCount();l++ ) { gd::Sprite & sprite = anim.GetDirection(k).GetSprite(l); sprite.LoadImage(scene.GetImageManager()->GetSFMLTexture(sprite.GetImageName())); } } } }
/** * Change the texture */ void ParticleEmitterBase::SetTexture(RuntimeScene& scene, const gd::String& textureParticleName_) { textureParticleName = textureParticleName_; if (particleSystem && rendererType == Quad) { // Load new texture particleSystem->textureParticle = scene.GetImageManager()->GetSFMLTexture(textureParticleName); // Notify the renderer of the change SPK::GL::GLQuadRenderer* quadRenderer = dynamic_cast<SPK::GL::GLQuadRenderer*>(particleSystem->renderer); if (quadRenderer) { quadRenderer->setTexturingMode(SPK::TEXTURE_2D); quadRenderer->setTexture( particleSystem->textureParticle->texture.getNativeHandle()); } } }
void RuntimeTiledSpriteObject::ChangeAndReloadImage(const gd::String &txtName, const RuntimeScene &scene) { textureName = txtName; texture = scene.GetImageManager()->GetSFMLTexture(textureName); }
void GD_EXTENSION_API SaveSFMLTextureToFile( RuntimeScene & scene, const gd::String & fileName, const gd::String & imageName ) { if ( !scene.GetImageManager()->HasLoadedSFMLTexture(imageName) ) return; scene.GetImageManager()->GetSFMLTexture(imageName)->image.saveToFile(fileName.ToLocale()); }