Image* HeightmapEditorSystem::CreateToolImage(int32 sideSize, const FilePath& filePath) { Sprite *dstSprite = Sprite::CreateAsRenderTarget((float32)sideSize, (float32)sideSize, FORMAT_RGBA8888); Texture *srcTex = Texture::CreateFromFile(filePath); Sprite *srcSprite = Sprite::CreateFromTexture(srcTex, 0, 0, (float32)srcTex->GetWidth(), (float32)srcTex->GetHeight()); RenderManager::Instance()->SetRenderTarget(dstSprite); RenderManager::Instance()->ClearWithColor(0.f, 0.f, 0.f, 0.f); RenderManager::Instance()->SetBlendMode(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA); RenderManager::Instance()->SetColor(Color::White()); srcSprite->SetScaleSize((float32)sideSize, (float32)sideSize); srcSprite->SetPosition(Vector2((dstSprite->GetTexture()->GetWidth() - sideSize)/2.0f, (dstSprite->GetTexture()->GetHeight() - sideSize)/2.0f)); srcSprite->Draw(); RenderManager::Instance()->RestoreRenderTarget(); Image *retImage = dstSprite->GetTexture()->CreateImageFromMemory(); SafeRelease(srcSprite); SafeRelease(srcTex); SafeRelease(dstSprite); return retImage; }
Image *LandscapeEditorHeightmap::CreateToolImage(int32 sideSize) { RenderManager::Instance()->LockNonMain(); Image *image = currentTool->image; Sprite *dstSprite = Sprite::CreateAsRenderTarget((float32)sideSize, (float32)sideSize, FORMAT_RGBA8888); Texture *srcTex = Texture::CreateFromData(image->GetPixelFormat(), image->GetData(), image->GetWidth(), image->GetHeight(), false); Sprite *srcSprite = Sprite::CreateFromTexture(srcTex, 0, 0, (float32)image->GetWidth(), (float32)image->GetHeight()); RenderManager::Instance()->SetRenderTarget(dstSprite); RenderManager::Instance()->SetColor(Color::Black()); RenderHelper::Instance()->FillRect(Rect(0, 0, (float32)dstSprite->GetTexture()->GetWidth(), (float32)dstSprite->GetTexture()->GetHeight())); RenderManager::Instance()->SetBlendMode(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA); RenderManager::Instance()->SetColor(Color::White()); srcSprite->SetScaleSize((float32)sideSize, (float32)sideSize); srcSprite->SetPosition(Vector2((dstSprite->GetTexture()->GetWidth() - sideSize)/2.0f, (dstSprite->GetTexture()->GetHeight() - sideSize)/2.0f)); srcSprite->Draw(); RenderManager::Instance()->RestoreRenderTarget(); Image *retImage = dstSprite->GetTexture()->CreateImageFromMemory(); SafeRelease(srcSprite); SafeRelease(srcTex); SafeRelease(dstSprite); RenderManager::Instance()->UnlockNonMain(); return retImage; }
void Game::SpawnExplosion(int x, int y) { Sprite* aS = m_pBackBuffer->CreateSprite("assets\\explosion.png"); // create an explosion object Explosion* explosion = new Explosion(); // initialize the texture if (!explosion->Initialise(*aS->GetTexture())) { LogManager::GetInstance().Log("Explosion Init Fail!"); return; } // set the width and speed of the animation int fw = aS->GetWidth() / 5; explosion->SetFrameWidth(fw); // 5 frames in the animation explosion->SetFrameSpeed(0.1f); for (int i = 0; i < 5; i++) { explosion->AddFrame(i * fw); } // set the center points for visual alignment explosion->SetCenter(fw / 2, aS->GetHeight() / 2); // set the x and y explosion->SetX(x - explosion->GetCenterX() / 2); explosion->SetY(y - explosion->GetCenterY() / 2); // add to the explosion container m_explosion.push_back(explosion); }
void CustomColorsSystem::UpdateBrushTool(float32 timeElapsed) { Sprite* colorSprite = drawSystem->GetCustomColorsProxy()->GetSprite(); RenderManager::Instance()->SetRenderTarget(colorSprite); RenderManager::Instance()->SetColor(drawColor); Vector2 spriteSize = Vector2(cursorSize, cursorSize); Vector2 spritePos = cursorPosition - spriteSize / 2.f; Sprite::DrawState drawState; drawState.SetScaleSize(spriteSize.x / Core::GetVirtualToPhysicalFactor(), spriteSize.y / Core::GetVirtualToPhysicalFactor(), toolImageSprite->GetWidth(), toolImageSprite->GetHeight()); drawState.SetPosition(spritePos / Core::GetVirtualToPhysicalFactor()); toolImageSprite->Draw(&drawState); RenderManager::Instance()->RestoreRenderTarget(); RenderManager::Instance()->SetColor(Color::White); drawSystem->GetLandscapeProxy()->SetCustomColorsTexture(colorSprite->GetTexture()); Rect updatedRect; updatedRect.SetCenter(spritePos); updatedRect.SetSize(spriteSize); AddRectToAccumulator(updatedRect); }
void UIStaticText::PrepareSpriteInternal(DAVA::BaseObject *caller, void *param, void *callerData) { if (textBlock->IsSpriteReady()) { Sprite *sprite = textBlock->GetSprite(); shadowBg->SetSprite(sprite, 0); textBg->SetSprite(sprite, 0); Texture *tex = sprite->GetTexture(); if(tex && tex->GetFormat() == FORMAT_A8) { textBg->SetShader(RenderManager::TEXTURE_MUL_FLAT_COLOR_IMAGE_A8); shadowBg->SetShader(RenderManager::TEXTURE_MUL_FLAT_COLOR_IMAGE_A8); } else { textBg->SetShader(RenderManager::TEXTURE_MUL_FLAT_COLOR); shadowBg->SetShader(RenderManager::TEXTURE_MUL_FLAT_COLOR); } } else { shadowBg->SetSprite(NULL, 0); textBg->SetSprite(NULL, 0); } }
void ModifyTilemaskCommand::Redo() { ApplyImageToSprite(redoImageMask, landscapeProxy->GetTilemaskSprite(LandscapeProxy::TILEMASK_SPRITE_SOURCE)); Texture* maskTexture = landscapeProxy->GetLandscapeTexture(Landscape::TEXTURE_TILE_MASK); Sprite* sprite; sprite = ApplyImageToTexture(redoImageMask, maskTexture); sprite->GetTexture()->GenerateMipmaps(); landscapeProxy->SetTilemaskTexture(sprite->GetTexture()); SafeRelease(sprite); landscapeProxy->UpdateFullTiledTexture(); landscapeProxy->IncreaseTilemaskChanges(); Rect r = Rect(Vector2(0, 0), Vector2(redoImageMask->GetWidth(), redoImageMask->GetHeight())); Image* mask = landscapeProxy->GetTilemaskImageCopy(); mask->InsertImage(redoImageMask, updatedRect.GetPosition(), r); }
void BackBuffer::DrawSprite(Sprite& sprite) { SDL_Rect dest; dest.x = sprite.GetX(); dest.y = sprite.GetY(); dest.w = sprite.GetWidth(); dest.h = sprite.GetHeight(); SDL_RenderCopy(m_pRenderer, sprite.GetTexture()->GetTexture(), 0, &dest); }
void CustomColorsSystem::SaveTexture(const DAVA::FilePath &filePath) { if(filePath.IsEmpty()) return; Sprite* customColorsSprite = drawSystem->GetCustomColorsProxy()->GetSprite(); Texture* customColorsTexture = customColorsSprite->GetTexture(); Image* image = customColorsTexture->CreateImageFromMemory(RenderState::RENDERSTATE_2D_BLEND); ImageSystem::Instance()->Save(filePath, image); SafeRelease(image); StoreSaveFileName(filePath); drawSystem->GetCustomColorsProxy()->ResetChanges(); }
void renderFrame(void) { //glViewport(0, 0, 600, 800); // Get parameters from Effect Effect* effect = sprite.GetEffect(); GLint u_MVPMatrix_handle = glGetUniformLocation(effect->GetProgramHandle(),"u_MVPMatrix"); GLint a_Position_handle = glGetAttribLocation(effect->GetProgramHandle(), "a_Position"); GLint a_TexCoordinate = glGetAttribLocation(effect->GetProgramHandle(), "a_TexCoordinate"); GLint mTextureUniformHandle = glGetUniformLocation(effect->GetProgramHandle(), "u_Texture"); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); glUseProgram(sprite.GetEffect()->GetProgramHandle()); glActiveTexture(GL_TEXTURE0); // Bind the texture to this unit. Texture* texture = (Texture*)sprite.GetTexture(); const GLuint thandle = texture->GetTextureHandle(); glBindTexture(GL_TEXTURE_2D, thandle); //sprite.GetTexture()->GetTextureHandle()); // Tell the texture uniform sampler to use this texture in the shader by binding to texture unit 0. glUniform1i(mTextureUniformHandle, 0); // Set position attribute and MVP matrix uniform glVertexAttribPointer(a_Position_handle, 3, GL_FLOAT, false, 0, Sprite::GetVertexPosStatic()); glEnableVertexAttribArray(a_Position_handle); glVertexAttribPointer(a_TexCoordinate, 2, GL_FLOAT, false, 0, Sprite::GetVertexTexStatic()); glEnableVertexAttribArray(a_TexCoordinate); const Matrix *proj; proj = camera.GetProjection(); std::string s; Matrix projworld; Matrix world; world = Matrix::Translation(0,0,zoom); Matrix::Multiply(*proj,world, projworld); glUniformMatrix4fv(u_MVPMatrix_handle, 1, false, projworld.Data()); std::cout << std::flush; glDrawArrays(GL_TRIANGLES, 0, 6); //glFlush(); }
void LandscapeEditorCustomColors::PerformLandscapeDraw() { Sprite* sprLandscape = Sprite::CreateFromTexture(texSurf, 0, 0, texSurf->GetWidth(), texSurf->GetHeight()); Sprite* sprTargetSurf = Sprite::CreateAsRenderTarget(texSurf->width, texSurf->height, FORMAT_RGBA8888); //render original and color layer to final container RenderManager::Instance()->SetRenderTarget(sprTargetSurf); sprLandscape->Draw(); RenderManager::Instance()->SetColor(1.f, 1.f, 1.f, .5f); colorSprite->Draw(); RenderManager::Instance()->SetColor(Color::White()); texSurf->GenerateMipmaps(); RenderManager::Instance()->RestoreRenderTarget(); workingLandscape->SetTexture(Landscape::TEXTURE_TILE_FULL, sprTargetSurf->GetTexture()); SafeRelease(sprTargetSurf); SafeRelease(sprLandscape); }
void NoteDisplay::DrawHoldBottomCap( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ) { // // Draw the bottom cap (always wavy) // StripBuffer queue; Sprite* pBottomCap = GetHoldBottomCapSprite( NoteRowToBeat(iRow), tn.subType == TapNote::hold_head_roll, bIsBeingHeld ); pBottomCap->SetZoom( ArrowEffects::GetZoom( m_pPlayerState ) ); // draw manually in small segments RageTexture* pTexture = pBottomCap->GetTexture(); const RectF *pRect = pBottomCap->GetCurrentTextureCoordRect(); DISPLAY->ClearAllTextures(); DISPLAY->SetTexture( 0, pTexture ); DISPLAY->SetBlendMode( BLEND_NORMAL ); DISPLAY->SetCullMode( CULL_NONE ); DISPLAY->SetTextureWrapping(false); const float fFrameWidth = pBottomCap->GetZoomedWidth(); const float fFrameHeight = pBottomCap->GetZoomedHeight(); const float fYCapTop = fYTail+cache->m_iStopDrawingHoldBodyOffsetFromTail; const float fYCapBottom = fYTail+cache->m_iStopDrawingHoldBodyOffsetFromTail+fFrameHeight; bool bReverse = m_pPlayerState->m_CurrentPlayerOptions.GetReversePercentForColumn(iCol) > 0.5f; if( bGlow ) fColorScale = 1; float fDrawYCapTop; float fDrawYCapBottom; { float fYStartPos = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYStartOffset, m_fYReverseOffsetPixels ); float fYEndPos = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYEndOffset, m_fYReverseOffsetPixels ); fDrawYCapTop = max( fYCapTop, bReverse ? fYEndPos : fYStartPos ); fDrawYCapBottom = min( fYCapBottom, bReverse ? fYStartPos : fYEndPos ); } bool bAllAreTransparent = true; bool bLast = false; // don't draw any part of the tail that is before the middle of the head float fY=max( fDrawYCapTop, fYHead ); for( ; !bLast; fY += fYStep ) { if( fY >= fDrawYCapBottom ) { fY = fDrawYCapBottom; bLast = true; } const float fYOffset = ArrowEffects::GetYOffsetFromYPos( m_pPlayerState, iCol, fY, m_fYReverseOffsetPixels ); const float fX = ArrowEffects::GetXPos( m_pPlayerState, iCol, fYOffset ); const float fZ = ArrowEffects::GetZPos( m_pPlayerState, iCol, fYOffset ); // XXX: Actor rotations use degrees, RageFastCos/Sin use radians. Convert here. const float fRotationY = ArrowEffects::GetRotationY( m_pPlayerState, fYOffset ) * PI/180; // if we're rotating, we need to modify the X and Z coords for the outer edges. const float fRotOffsetX = fFrameWidth/2 * RageFastCos(fRotationY); const float fRotOffsetZ = fFrameWidth/2 * RageFastSin(fRotationY); const float fXLeft = fX - fRotOffsetX; const float fXRight = fX + fRotOffsetX; const float fZLeft = fZ - fRotOffsetZ; const float fZRight = fZ + fRotOffsetZ; const float fTopDistFromTail = fY - fYCapTop; const float fTexCoordTop = SCALE( fTopDistFromTail, 0, fFrameHeight, pRect->top, pRect->bottom ); const float fTexCoordLeft = pRect->left; const float fTexCoordRight = pRect->right; const float fAlpha = ArrowGetAlphaOrGlow( bGlow, m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels ); const RageColor color = RageColor(fColorScale,fColorScale,fColorScale,fAlpha); if( fAlpha > 0 ) bAllAreTransparent = false; queue.v[0].p = RageVector3(fXLeft, fY, fZLeft); queue.v[0].c = color; queue.v[0].t = RageVector2(fTexCoordLeft, fTexCoordTop); queue.v[1].p = RageVector3(fXRight, fY, fZRight); queue.v[1].c = color; queue.v[1].t = RageVector2(fTexCoordRight, fTexCoordTop); queue.v+=2; if( queue.Free() < 2 ) { /* The queue is full. Render it, clear the buffer, and move back a step to * start off the quad strip again. */ if( !bAllAreTransparent ) queue.Draw(); queue.Init(); bAllAreTransparent = true; fY -= fYStep; } } if( !bAllAreTransparent ) queue.Draw(); }
void NoteDisplay::DrawHoldBody( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYHead, float fYTail, int fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow, float fYStartOffset, float fYEndOffset ) { // // Draw the body (always wavy) // StripBuffer queue; Sprite* pSprBody = GetHoldBodySprite( NoteRowToBeat(iRow), tn.subType == TapNote::hold_head_roll, bIsBeingHeld ); pSprBody->SetZoom( ArrowEffects::GetZoom( m_pPlayerState ) ); // draw manually in small segments RageTexture* pTexture = pSprBody->GetTexture(); const RectF *pRect = pSprBody->GetCurrentTextureCoordRect(); DISPLAY->ClearAllTextures(); DISPLAY->SetTexture( 0, pTexture ); DISPLAY->SetBlendMode( BLEND_NORMAL ); DISPLAY->SetCullMode( CULL_NONE ); DISPLAY->SetTextureWrapping( true ); const float fFrameWidth = pSprBody->GetZoomedWidth(); const float fFrameHeight = pSprBody->GetZoomedHeight(); const float fYBodyTop = fYHead + cache->m_iStartDrawingHoldBodyOffsetFromHead; const float fYBodyBottom = fYTail + cache->m_iStopDrawingHoldBodyOffsetFromTail; const bool bReverse = m_pPlayerState->m_CurrentPlayerOptions.GetReversePercentForColumn(iCol) > 0.5f; bool bAnchorToBottom = bReverse && cache->m_bFlipHeadAndTailWhenReverse; if( bGlow ) fColorScale = 1; /* Only draw the section that's within the range specified. If a hold note is * very long, don't process or draw the part outside of the range. Don't change * fYBodyTop or fYBodyBottom; they need to be left alone to calculate texture * coordinates. */ float fDrawYBodyTop; float fDrawYBodyBottom; { float fYStartPos = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYStartOffset, m_fYReverseOffsetPixels ); float fYEndPos = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYEndOffset, m_fYReverseOffsetPixels ); fDrawYBodyTop = max( fYBodyTop, bReverse ? fYEndPos : fYStartPos ); fDrawYBodyBottom = min( fYBodyBottom, bReverse ? fYStartPos : fYEndPos ); } // top to bottom bool bAllAreTransparent = true; bool bLast = false; float fVertTexCoordOffset = 0; for( float fY = fDrawYBodyTop; !bLast; fY += fYStep ) { if( fY >= fDrawYBodyBottom ) { fY = fDrawYBodyBottom; bLast = true; } const float fYOffset = ArrowEffects::GetYOffsetFromYPos( m_pPlayerState, iCol, fY, m_fYReverseOffsetPixels ); const float fX = ArrowEffects::GetXPos( m_pPlayerState, iCol, fYOffset ); const float fZ = ArrowEffects::GetZPos( m_pPlayerState, iCol, fYOffset ); // XXX: Actor rotations use degrees, RageFastCos/Sin use radians. Convert here. const float fRotationY = ArrowEffects::GetRotationY( m_pPlayerState, fYOffset ) * PI/180; // if we're rotating, we need to modify the X and Z coords for the outer edges. const float fRotOffsetX = fFrameWidth/2 * RageFastCos(fRotationY); const float fRotOffsetZ = fFrameWidth/2 * RageFastSin(fRotationY); const float fXLeft = fX - fRotOffsetX; const float fXRight = fX + fRotOffsetX; const float fZLeft = fZ - fRotOffsetZ; const float fZRight = fZ + fRotOffsetZ; const float fDistFromBodyBottom = fYBodyBottom - fY; const float fDistFromBodyTop = fY - fYBodyTop; float fTexCoordTop = SCALE( bAnchorToBottom ? fDistFromBodyTop : fDistFromBodyBottom, 0, fFrameHeight, pRect->bottom, pRect->top ); /* For very large hold notes, shift the texture coordinates to be near 0, so we * don't send very large values to the renderer. */ if( fY == fDrawYBodyTop ) // first fVertTexCoordOffset = floorf( fTexCoordTop ); fTexCoordTop -= fVertTexCoordOffset; const float fTexCoordLeft = pRect->left; const float fTexCoordRight = pRect->right; const float fAlpha = ArrowGetAlphaOrGlow( bGlow, m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels ); const RageColor color = RageColor(fColorScale,fColorScale,fColorScale,fAlpha); if( fAlpha > 0 ) bAllAreTransparent = false; queue.v[0].p = RageVector3(fXLeft, fY, fZLeft); queue.v[0].c = color; queue.v[0].t = RageVector2(fTexCoordLeft, fTexCoordTop); queue.v[1].p = RageVector3(fXRight, fY, fZRight); queue.v[1].c = color; queue.v[1].t = RageVector2(fTexCoordRight, fTexCoordTop); queue.v+=2; if( queue.Free() < 2 ) { /* The queue is full. Render it, clear the buffer, and move back a step to * start off the quad strip again. */ if( !bAllAreTransparent ) queue.Draw(); queue.Init(); bAllAreTransparent = true; fY -= fYStep; } } if( !bAllAreTransparent ) queue.Draw(); }