int OpticSprite::draw(LPD3DXSPRITE sprite, double time, D3DXCOLOR colour, double offsetX, double offsetY) { if(!this->animate) { sprite->Draw(texture, NULL, NULL, NULL, colour); return 1; } if(animation.lifetime() > time) { animation.updateState(aniState, time); colour = D3DXCOLOR(aniState.red, aniState.green, aniState.blue, colour.a < aniState.alpha? colour.a : aniState.alpha); float rotation = 6.28318531f * aniState.rotation; D3DXMATRIX mat, current; D3DXVECTOR2 scaling(aniState.scale_x, aniState.scale_y); D3DXVECTOR2 position(floor(((pResolution->width * aniState.position_x) - translateCentre.x) + offsetX), floor(((pResolution->height * aniState.position_y) - translateCentre.y) + offsetY)); D3DXMatrixTransformation2D(&mat, &transformCentre, 0.0f, &scaling, &transformCentre, rotation, &position); sprite->GetTransform(¤t); mat *= current; sprite->SetTransform(&mat); HRESULT res; //Spritesheet rect calculations are slightly iffy thanks to the texture scaling (rounding errors) if(this->spritesheet) { int x = (width * currFrame) % surfaceDesc.Width; //Hacky workaround int diff = x - surfaceDesc.Width; if(abs(diff) <= 10) { x = 0; } //End of hacky workaround int y = height * currRow; RECT source; source.top = y; source.left = x; source.right = x + width; source.bottom = y + height; res = sprite->Draw(texture, &source, NULL, NULL, colour); sprite->SetTransform(¤t); if(!advanceFrame(time, x, y)) { return 0; } } else { res = sprite->Draw(texture, NULL, NULL, NULL, colour); sprite->SetTransform(¤t); } if(res != S_OK) { throw OpticSpriteException("Rendering sprite failed!"); } return 1; } return 0; }
void CTextureDx9::RenderWithoutTransform(LPD3DXSPRITE _lpDSpriteHandle, D3DXVECTOR2 position, D3DXVECTOR2 Center, D3DXVECTOR2 scale, float angle, D3DCOLOR color, RECT *srcRect, float deep) { D3DXVECTOR2 CamTransDistance; CamTransDistance.x = -Camera::getInstance()->GetMatrixTranslate()._41; CamTransDistance.y = Camera::getInstance()->GetMatrixTranslate()._42; position.y += Camera::getInstance()->getBound().bottom; Center.y += Camera::getInstance()->getBound().bottom; D3DXVECTOR3 currentPosition(position.x + CamTransDistance.x, position.y, deep); //toa do trong the gioi thuc D3DXMATRIX oldMatrix; //ma tran luu lai phep transform cua SpriteBatch _lpDSpriteHandle->GetTransform(&oldMatrix); D3DXVECTOR2 centerScale = D3DXVECTOR2(position.x, position.y);//lay vi tri cua vat the lam tam xoay(vi vi tri cua vat la vi tri chinh giua cua vat) D3DXMATRIX matrixScalingRotate; //ma tran rotate, scale D3DXMatrixTransformation2D(&matrixScalingRotate, ¢erScale, 0.0f, &scale, &Center, D3DXToRadian(angle), 0); D3DXMATRIX finalMatrix = matrixScalingRotate * oldMatrix; _lpDSpriteHandle->SetTransform(&finalMatrix); //ma tran chuyen toa do vi tri cua vat the tu the gioi thuc sang toa do trong directX de ve _lpDSpriteHandle->Draw( this->m_lpTexture, srcRect, &D3DXVECTOR3((float)(srcRect->right - srcRect->left)/2, (float)(srcRect->bottom - srcRect->top)/2, 0), ¤tPosition, color); _lpDSpriteHandle->SetTransform(&oldMatrix); }
// // -------------------------------------------------------- // Renders the edit box and the internal text. // -------------------------------------------------------- void DirectX::GUI::EditBox::render( LPD3DXSPRITE d3dsprite, const POINT* pos ) { // Compute absolute offset int xpos = m_posX + pos->x; int ypos = m_posY + pos->y; // Render edit box background sprite Matrix fieldTransform; float fieldScaleX = (float)m_sizeX / (float)(m_style->selectionBox.right - m_style->selectionBox.left); float fieldScaleY = (float)m_sizeY / (float)(m_style->selectionBox.bottom - m_style->selectionBox.top); D3DXMatrixTransformation2D( &fieldTransform, NULL, 0.0, &Vector2( fieldScaleX, fieldScaleY ), NULL, NULL, &Vector2( (float)xpos, (float)ypos ) ); // Render the properly positioned sprite d3dsprite->SetTransform( &fieldTransform ); d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->selectionBox, NULL, NULL, 0xFFFFFFFF ); // Draw button text if( m_state&FOCUSED ) m_cursorPosition = m_text.insert( m_cursorPosition, '|' ); Matrix iden; RECT textRect = { xpos, ypos, xpos+m_sizeX, ypos+m_sizeY }; D3DXMatrixIdentity( &iden ); d3dsprite->SetTransform( &iden ); m_style->font.getFont( )->DrawTextW( d3dsprite, m_text.c_str( ), -1, &textRect, m_alignment, m_style->color ); if( m_state&FOCUSED ) { std::wstring::iterator next = m_cursorPosition; next++; m_cursorPosition = m_text.erase( m_cursorPosition, next ); } }
void CGameEnd::Render(LPDIRECT3DDEVICE9& dxdevice, LPD3DXSPRITE& dxsprite) { dxsprite->Begin(D3DXSPRITE_ALPHABLEND); dxsprite->Draw(GMAIN->m_pGameTex[6].m_pTex, &(GMAIN->rc), NULL, &(GMAIN->vcPos), D3DXCOLOR(1, 1, 1, 1.f)); //////////////////////////////////////////////////////////////////////////////// dxsprite->End(); GMAIN->m_text.Begin(); char scoreBuf[80]; TCHAR fpsBuf[128]; if (GMAIN->m_nGameBeforePhase == ST_MULTI) { sprintf(scoreBuf, "%d", GGAMEMULTI->score);//멀티 게임 점수 } else { sprintf(scoreBuf, "%d", GGAME->score);//싱글 게임 점수. } GMAIN->m_text.Draw("Game Over", 355, 250, D3DXCOLOR(0, 0, 0, 1)); GMAIN->m_text.Draw("Total Score", 355, 300, D3DXCOLOR(0, 0, 0, 1)); GMAIN->m_text.Draw(scoreBuf, 355, 320, D3DXCOLOR(0, 0, 0, 1)); GMAIN->m_text.Draw("Press Enter for going back to Menu", 250, 400, D3DXCOLOR(0, 0, 0, 1)); //////////////////////////////////////////////////////////////////////////////// //FPS 화면에 출력 sprintf(fpsBuf, "FPS: %4.1f", GMAIN->m_fFps); GMAIN->m_text.Draw(fpsBuf, 700, 300); GMAIN->m_text.End(); }
HRESULT Li_lstBtnSprite::fn_drawButton(LPD3DXSPRITE dxSpriteInterface) { // Build our matrix to rotate, scale and position our sprite D3DXMATRIX mat; RECT srcRect; srcRect.left = 0; srcRect.right = m_Width; switch (m_direction) { case 0: // Down { // draw the selected button in the list srcRect.top = m_Height / m_lstSize * m_curSelect; srcRect.bottom = m_Height / m_lstSize * (m_curSelect + 1); } break; default: break; } D3DXVECTOR3 translation; translation.x = m_pos.x; translation.y = m_pos.y; translation.z = 0; // out, scaling centre, scaling rotation, scaling, rotation centre, rotation, translation D3DXMatrixTransformation(&mat, NULL, NULL, NULL, NULL, NULL, &translation); dxSpriteInterface->SetTransform(&mat); return dxSpriteInterface->Draw(m_dxTexture,&srcRect,NULL,NULL,0xFFFFFFFF); }
void CImage::DrawSprite(LPD3DXSPRITE SpriteInterface, LPDIRECT3DTEXTURE9 TextureInterface, int PosX, int PosY, int Rotation, int Align) { if(SpriteInterface == NULL || TextureInterface == NULL) return; D3DXVECTOR3 Vec; Vec.x = (FLOAT)PosX; Vec.y = (FLOAT)PosY; Vec.z = (FLOAT)0.0f; D3DXMATRIX mat; D3DXVECTOR2 scaling(1.0f, 1.0f); D3DSURFACE_DESC desc; TextureInterface->GetLevelDesc(0, &desc); D3DXVECTOR2 spriteCentre; if(Align == 1) spriteCentre = D3DXVECTOR2((FLOAT)desc.Width / 2, (FLOAT)desc.Height / 2); else spriteCentre = D3DXVECTOR2(0, 0); D3DXVECTOR2 trans = D3DXVECTOR2(0, 0); D3DXMatrixTransformation2D(&mat, NULL, 0.0, &scaling, &spriteCentre, (FLOAT)Rotation, &trans); SpriteInterface->SetTransform(&mat); SpriteInterface->Begin(D3DXSPRITE_ALPHABLEND); SpriteInterface->Draw(TextureInterface, NULL, NULL, &Vec, 0xFFFFFFFF); SpriteInterface->End(); }
void Sprite_Transform_Draw(LPDIRECT3DTEXTURE9 image, int x, int y, int width, int height, int frame, int columns, float rotation, float scaling, D3DCOLOR color) { //create a scale vector D3DXVECTOR2 scale( scaling, scaling ); //create a translate vector D3DXVECTOR2 trans( (float)x, (float)y ); //set center by dividing width and height by two D3DXVECTOR2 center( (float)( width * scaling )/2, (float)( height * scaling )/2); //create 2D transformation matrix D3DXMATRIX mat; D3DXMatrixTransformation2D( &mat, NULL, 0, &scale, ¢er, rotation, &trans ); //tell sprite object to use the transform spriteobj->SetTransform( &mat ); //calculate frame location in source image int fx = (frame % columns) * width; int fy = (frame / columns) * height; RECT srcRect = {fx, fy, fx + width, fy + height}; //draw the sprite frame spriteobj->Draw( image, &srcRect, NULL, NULL, color ); }
/** * CBitmapFont::drawStringMarkup * @date Modified Mar 29, 2006 */ void CBitmapFont::drawStringMarkup(CString str, float fX, float fY, D3DCOLOR dwColor, bool bHandleSprite) { CRenderDevice& oDev = CRenderSystem::getInstance().getRenderDevice(); LPD3DXSPRITE pSprite = oDev.getD3DXSprite(); RECT rChar; char cChar; D3DXVECTOR3 vPos, vZero; vPos.x = fX; vPos.y = fY; vPos.z = 0.0f; vZero.x = vZero.y = vZero.z = 0.0f; if(bHandleSprite) beginSprite(); // Split strings bool bFirst = false; std::vector<CString> vStrings; str.ToList(vStrings, TEXT("{}")); if(str.GetChar(0) == '{') bFirst = true; // Iterate split strings, and change color if needed. for(size_t v = 0; v < vStrings.size(); ++v) { // Get string, and read color if((bFirst && v % 2 == 0) || (!bFirst && v % 2 == 1)) { dwColor = vStrings[v].ToUlongFromHex(); continue; } // Iterate string and draw characters. size_t nSize = vStrings[v].GetLength(); for(size_t i = 0; i < nSize; ++i) { cChar = vStrings[v].GetChar(i); switch(cChar) { case '\n': vPos.y += m_cLineHeight; vPos.x = fX; break; case '\t': vPos.x += m_mCharMap['X'] * 4; break; default: getCharRect(cChar, &rChar); pSprite->Draw(m_poTexture->getD3DTexture(), &rChar, NULL, &vPos, dwColor); vPos.x += (rChar.right - rChar.left); break; } } } if(bHandleSprite) endSprite(); }
void Texture::render(LPD3DXSPRITE spriteHandle, const RECT* rect, const GVector3* center, const GVector3* position) { spriteHandle->Draw( this->_texture, rect, center, position, _color); }
void Sprite::Draw(float X,float Y,int Index,LPD3DXSPRITE _Handler) { D3DXMATRIX m; D3DXMatrixIdentity(&m); _Handler->SetTransform(&m); _Handler->Draw(m_Image,&this->getRect(Index), NULL,&D3DXVECTOR3(X,Y,0),D3DCOLOR_ARGB(255,255,255,255)); }
void Sprite::Draw(D3DMATRIX _World,InfoSprite _info,LPD3DXSPRITE _Handler) { D3DXMATRIX ma; ma = _info.getMatrixTransform()*_World; _Handler->SetTransform(&ma); _Handler->Draw(m_Image,&this->getRect(_info.getCurFrame()),NULL, &D3DXVECTOR3(0,0,_info.getDepth()),_info.getColor()); }
void Button::display(LPD3DXSPRITE spt){ if (visible){ D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); D3DXVECTOR3 position((float)size.left, (float)size.top, 1.0f); spt->Draw(*sprite, NULL, ¢er, &position, D3DCOLOR_XRGB(255, 255, 255)); (*font)->DrawTextA(spt, text.c_str(), text.length(), &size, DT_CENTER | DT_VCENTER | DT_SINGLELINE, color); } }
void Sprite_Draw_Frame(LPDIRECT3DTEXTURE9 texture, int destx, int desty, int framenum, int framew, int frameh, int columns) { D3DXVECTOR3 position( (float)destx, (float)desty, 0 ); D3DCOLOR white = D3DCOLOR_XRGB(255,255,255); RECT rect; rect.left = (framenum % columns) * framew; rect.top = (framenum / columns) * frameh; rect.right = rect.left + framew; rect.bottom = rect.top + frameh; spriteobj->Draw( texture, &rect, NULL, &position, white); }
static void myAdditions(LPDIRECT3DDEVICE9 Device_Interface) { D3DXVECTOR3 imagepos; BOOL currentState = (BOOL)(GetAsyncKeyState(VK_INSERT) & 0x8000); //Switch ON and OFF if(!currentState && oldState) //Si la touche passe de enfoncée à relevée DRAW_CROSSHAIR ^= TRUE; oldState = currentState; if(DRAW_CROSSHAIR) { //Checks / Init ============================================================================================================= if(imagetex == NULL) { if(!SUCCEEDED(D3DXCreateTextureFromFileEx(Device_Interface, "crosshair.png", D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, &imageInfo, NULL, &imagetex))) { DRAW_CROSSHAIR = FALSE; return; } } if(sprite == NULL) { if(!SUCCEEDED(D3DXCreateSprite(Device_Interface, &sprite))) { DRAW_CROSSHAIR = FALSE; return; } } //============================================================================================================= if(SUCCEEDED(Device_Interface->BeginScene())) { //RESOLUTION ? D3DVIEWPORT9 vp; Device_Interface->GetViewport(&vp); imagepos.x = (vp.Width - imageInfo.Width)/2.0f; //coord x of our sprite imagepos.y = (vp.Height - imageInfo.Height)/2.0f; //coord y of out sprite imagepos.z = 0.0f; if(SUCCEEDED(sprite->Begin(D3DXSPRITE_ALPHABLEND))) { sprite->Draw(imagetex, NULL, NULL, &imagepos, 0xFFFFFFFF); sprite->End(); } Device_Interface->EndScene(); } } }
void DrawSprite(LPD3DXSPRITE pSpriteBat,LPDIRECT3DTEXTURE9 pSpriteTex, const RECT& to,D3DCOLOR col) { int w,h; GetSpriteSize(pSpriteTex,w,h); float sx=float(to.right-to.left)/w; float sy=float(to.bottom-to.top)/h; D3DXMATRIX scale; D3DXMatrixScaling(&scale,sx,sy,1); pSpriteBat->SetTransform(&scale); pSpriteBat->Draw(pSpriteTex,NULL,NULL, &D3DXVECTOR3(to.left/sx,to.top/sy,0),col); pSpriteBat->SetTransform(&IDENTITY_MAT); // reset the matrix }
void Sprite::Draw(LPD3DXSPRITE _Handler,D3DMATRIX _mtWorld, float _X,float _Y, int _Index,float _Depth,D3DXCOLOR _color) { D3DXMATRIX MaTrix,mtFinal; // D3DXMatrixIdentity(&mtFinal); D3DXVECTOR2 MTTran (_X,_Y); D3DXMatrixTransformation2D(&MaTrix,NULL,0,NULL,NULL,NULL,&MTTran); mtFinal = MaTrix*_mtWorld; _Handler->SetTransform(&mtFinal); _Handler->Draw(m_Image,&this->getRect(_Index),NULL, &D3DXVECTOR3(0,0,_Depth),_color); }
void DrawSprite(LPDIRECT3DTEXTURE9 s, int x, int y) { HRESULT hr = ddraw->Draw(s, NULL, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3((float)x, (float)y, 0.0f), D3DCOLOR_XRGB(255, 255, 255)); //s->sprite is the sprite to draw //NULL tells it to draw the whole stinkin' thing (would normally be a pRECT //D3DXVECTOR3 is the center point (just setting it to (0, 0) //the second D3DVECTOR3 is the point to start drawing it on the screen //the color is to draw at full intensity /*HRESULT Draw(LPDIRECT3DTEXTURE9 pTexture, CONST RECT* pSrcRect, CONST D3DXVECTOR3* pCenter, CONST D3DXVECTOR3* pPosition, D3DCOLOR Color);*/ }
//----------------------------------------------------------------------------- // Name: Render() // Desc: Draws the scene //----------------------------------------------------------------------------- VOID Render() { renderDevice->Clear(0,NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0); renderDevice->BeginScene(); if(bg->getTexture()) { sprite->Begin(D3DXSPRITE_ALPHABLEND); sprite->Draw(bg->getTexture(), bg->getSource(), bg->getCenter(), bg->getPosition(), 0xFFFFFFFF); sprite->End(); // End the scene } renderDevice->EndScene(); renderDevice->Present( NULL, NULL, NULL, NULL ); }
void HookD3D9::DrawSprite(unsigned int texId, long left, long top, long right, long bottom, float posX, float posY, int r, int g, int b, int a) { RECT destRect = {left, top, right, bottom}; LPD3DXSPRITE sprite = sprites[texId]; LPDIRECT3DTEXTURE9 texture = textures[texId]; D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); D3DXVECTOR3 pos(posX, posY, 0.0f); sprite->Begin(D3DXSPRITE_ALPHABLEND); sprite->Draw(texture, NULL, NULL, &pos, D3DCOLOR_RGBA(r, g, b, a)); sprite->End(); }
/** Draw a transformed sprite; does all the matrix shit for you */ void Sprite::spriteTransformDraw(LPDIRECT3DTEXTURE9 texture, LPD3DXSPRITE SpriteObj) { //Create 2D vectors for scale and translate values (indicate scale x-wise and y-wise) D3DXVECTOR2 scale(this->scalingX, this->scalingY); D3DXVECTOR2 translate(x, y); //Set center by dividing width and height by 2, take scaling into account D3DXVECTOR2 center((double)(this->width * this->scalingX)/2, (double)(this->height * this->scalingY)/2); //The 2D transformation matrix and the function that actually sets the matrix values D3DXMATRIX mat; D3DXMatrixTransformation2D( &mat, //The matrix; note pass by reference NULL, //scaling center point (not used) 0, //scaling rotation value (not used) &scale, //scaling vector ¢er, //rotation / pivot center rotation, //rotation angle in RADIANS &translate //translation vector ); //Tell sprite object to use the matrix SpriteObj->SetTransform(&mat); //calculate frame location in source image (only useful if it's a spritesheet) int fx = (this->frame % columns) * this->width; int fy = (this->frame / columns) * this->height; RECT sourceRect = {fx, fy, fx + this->width, fy + this->height}; //Draw the sprite frame; note we are not filling in pivot center or position because those are already set //by the matrix SpriteObj->Draw(texture, &sourceRect, NULL, NULL, this->color); /** More on spriteObj->Draw pSrcTexture - a pointer to the texture to be used, see textures pSrcRect - pointer to a rectangle defining the area of the texture to use or NULL for the whole texture pCenter- pointer to a 3D vector specifying the position in the sprite around which it can be rotated or NULL for top left pPosition - pointer to a 3D vector defining the screen position of the sprite. Note: in Direct3D 0,0 is the top left of the screen. Color - colour value that can be used to modulate the texture colours. A value of 0xFFFFFFFF maintains the colour from the texture. Note: you can use the D3DCOLOR_COLORVALUE macro to create a D3DCOLOR from RGB values. */ }//end spriteTransformDraw
void Sprite::Render() { if( m_isUse == false ) return; D3DXMATRIX Tmat, rotation, scale, translation[2]; float width = AVTexture2D::m_Rect.right - AVTexture2D::m_Rect.left; float height = AVTexture2D::m_Rect.bottom - AVTexture2D::m_Rect.top; //float width = m_Info.Width; //float height = m_Info.Height; static LPD3DXSPRITE sprite = AVDirector::GetDiector()->GetApplication()->GetD3DSprite(); D3DXMatrixIdentity(&rotation); D3DXMatrixIdentity(&scale); for(int i=0; i<2; i++)D3DXMatrixIdentity(&translation[i]); sprite->SetTransform( &scale ); // 한개만 해줘도 상관없음. D3DXMatrixTranslation(&translation[0], -(width * m_anchorPoint.x), -(height* m_anchorPoint.y), 0); D3DXMatrixScaling(&scale, m_scale.x, m_scale.y, 1.f); D3DXMatrixRotationZ(&rotation, m_angle); D3DXVECTOR2 vector = AVTexture2D::m_vPosition; D3DXMatrixTranslation(&translation[1], AVTexture2D::m_vPosition.x, AVTexture2D::m_vPosition.y, 0); Tmat = translation[0] * scale * rotation * translation[1]; sprite->SetTransform( &Tmat ); D3DCOLOR color = D3DCOLOR_ARGB((int)m_Color.a, (int)m_Color.r, (int)m_Color.g, (int)m_Color.b); sprite->Draw(m_Texture, &m_Rect, NULL, NULL, color); D3DXMatrixIdentity(&scale); sprite->SetTransform( &scale ); }
BOOL dx9vid_render() { // clear the window to a deep blue d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0); d3ddev->BeginScene(); // begins the 3D scene g_screenSprite->Begin( 0 ); d3ddev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); d3ddev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); d3ddev->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); g_screenSprite->Draw( g_screenTex, &srcRect, &vCenter, &vPosition, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) ); g_screenSprite->End(); d3ddev->EndScene(); // ends the 3D scene d3ddev->Present(NULL, NULL, NULL, NULL); // displays the created frame on the screen return TRUE; }
void DrawTexture(Texture *texture, int x, int y) { if(texture->imageLoaded == false) { return; } D3DXVECTOR3 pos(x, y, 0); //draw sprite with or without alpha-channel transparency if(transparent) { spriteHandler->Begin(D3DXSPRITE_ALPHABLEND); } else { spriteHandler->Begin(NULL); } TransformTexture(); spriteHandler->Draw(textureList[texture->textureIndex], NULL, NULL, &pos, texture->color); spriteHandler->End(); }
HRESULT Li_lstBtnSprite::fn_drawButtonList(LPD3DXSPRITE dxSpriteInterface) { // Build our matrix to rotate, scale and position our sprite D3DXMATRIX mat; RECT srcRect; D3DXVECTOR3 translation; D3DCOLOR col; switch (m_direction) { case 0: // Down { // draw the list button separately for (int i = 0; i < m_lstSize; i++) { // draw the list at the different position srcRect.left = 0; srcRect.right = m_Width; srcRect.top = m_Height / m_lstSize * i; srcRect.bottom = m_Height / m_lstSize * (i + 1); translation.x = m_pos.x; translation.y = m_pos.y + m_Height / m_lstSize * (i + 1); translation.z = 0; if (i == m_curSelect) col = 0xFFFFFFFF; else col = 0x78787878; // out, scaling centre, scaling rotation, scaling, rotation centre, rotation, translation D3DXMatrixTransformation(&mat, NULL, NULL, NULL, NULL, NULL, &translation); dxSpriteInterface->SetTransform(&mat); dxSpriteInterface->Draw(m_dxTexture,&srcRect,NULL,NULL,col); } } break; default: break; } return S_OK; }
/** * CBitmapFont::drawString * @date Modified Mar 29, 2006 */ void CBitmapFont::drawString(CString str, float fX, float fY, D3DCOLOR dwColor, bool bHandleSprite) { CRenderDevice& oDev = CRenderSystem::getInstance().getRenderDevice(); LPD3DXSPRITE pSprite = oDev.getD3DXSprite(); RECT rChar; char cChar; D3DXVECTOR3 vPos, vZero; vPos.x = fX; vPos.y = fY; vPos.z = 0.0f; vZero.x = vZero.y = vZero.z = 0.0f; if(bHandleSprite) beginSprite(); // Iterate string and draw characters. size_t nSize = str.GetLength(); for(size_t i = 0; i < nSize; ++i) { cChar = str.GetChar(i); switch(cChar) { case '\n': vPos.y += m_cLineHeight; vPos.x = fX; break; case '\t': vPos.x += m_mCharMap['X'] * 4; break; default: getCharRect(str.GetChar(i), &rChar); pSprite->Draw(m_poTexture->getD3DTexture(), &rChar, NULL, &vPos, dwColor); vPos.x += (rChar.right - rChar.left); break; } } if(bHandleSprite) endSprite(); }
/////////////////// // Button Sprite // /////////////////// HRESULT Li_btnSprite::fn_drawButton(LPD3DXSPRITE dxSpriteInterface) { // Build our matrix to rotate, scale and position our sprite D3DXMATRIX mat; RECT srcRect; srcRect.left = 0; srcRect.right = m_Width; switch (m_btnState) { case IDLE: { srcRect.top = 0; srcRect.bottom = m_Height / 3; } break; case PUSH: { srcRect.top = m_Height / 3; srcRect.bottom = m_Height / 3 * 2; } break; case PASS: { srcRect.top = m_Height / 3 * 2; srcRect.bottom = m_Height; } break; } D3DXVECTOR3 translation; translation.x = m_pos.x; translation.y = m_pos.y; translation.z = 0; // out, scaling centre, scaling rotation, scaling, rotation centre, rotation, translation D3DXMatrixTransformation(&mat, NULL, NULL, NULL, NULL, NULL, &translation); dxSpriteInterface->SetTransform(&mat); return dxSpriteInterface->Draw(m_dxTexture,&srcRect,NULL,NULL,0xFFFFFFFF); }
void renderD3d(void) { static float movementA = 0.1f, rotateB = 0.0f; rotateB += 0.1f; rotateAZ = rotateB; D3DXMATRIX matrixMoveA, matrixMoveB, matrixMoveC, matrixRotateAX, matrixRotateAX2, matrixRotateAY; D3DXMATRIX matrixRotateAY2, matrixRotateAZ, matrixRotateBX, matrixRotateBY, matrixRotateBWide; D3DXMATRIX matrixRotateMesh3, matrixScaleA, matrixScaleB, matrixView, matrixProjection; // pipeline projection matrixes D3DXMATRIX matrixCamRotateY, matrixCamMove; RECT part; // rectangular area for sprite drawing D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); // center at the upper-left corner (I dont get it) for sprite D3DXVECTOR3 position((float)SCREEN_WIDTH/2-128, 20.0f, 0.0f); // position sprite at center if (launch) if (movementA < 50.0f) movementA *= 1.1f; else movementA += 5.0f; if (movementA > 100.0f) { movementA = 0.1f; launch = false; } // clear the window to specified colors d3d9dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(backgroundColorRed, backgroundColorGreen, backgroundColorBlue), 1.0f, 0); // pipeline transformations // build a matrix to rotate the model based on the increasing float value // do 3D rendering on the back buffer here d3d9dev->BeginScene(); // begins the 3D scene D3DXMatrixLookAtLH(&matrixView, &D3DXVECTOR3 (0.0f, 0.0f, 10.0f), // the camera position &D3DXVECTOR3 (0.0f, 0.0f, 0.0f), // the look-at position &D3DXVECTOR3 (0.0f, 1.0f, 0.0f)); // the up direction d3d9dev->SetTransform(D3DTS_VIEW, &matrixView); // set the view transform to matView D3DXMatrixPerspectiveFovLH(&matrixProjection, D3DXToRadian(45), // the horizontal field of view (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio 1.0f, // the near view-plane 100.0f); // the far view-plane d3d9dev->SetTransform(D3DTS_PROJECTION, &matrixProjection); // set the projection D3DXMatrixTranslation(&matrixCamMove, moveCamX, moveCamY, moveCamZ); D3DXMatrixRotationY(&matrixCamRotateY, rotateCamY); d3d9dev->SetTransform(D3DTS_VIEW, &(matrixCamMove*matrixCamRotateY)); // move camera d3d9dev->SetFVF(CUSTOMFVF); // select which vertex format we are using d3d9dev->SetStreamSource(0, d3d9VertexBuffer1, 0, sizeof(CUSTOMVERTEX)); // select the triangle vertex buffer to display d3d9dev->SetMaterial(material); d3d9dev->SetTexture(0, texture3); D3DXMatrixTranslation(&matrixMoveA, -2.0f, 2.0f, 3.0f); D3DXMatrixRotationX(&matrixRotateAX, rotateAX); D3DXMatrixRotationX(&matrixRotateAX2, rotateAX-2.0f*rotateAX); D3DXMatrixRotationY(&matrixRotateAY, rotateAY); D3DXMatrixRotationY(&matrixRotateAY2, rotateAY+3.14159f); D3DXMatrixRotationZ(&matrixRotateAZ, rotateAZ); // a matrix to scale the triangle D3DXMatrixScaling(&matrixScaleA, scaleA, scaleA, scaleA); // tell Direct3D about our matrixes, set them in action d3d9dev->SetTransform(D3DTS_WORLD, &(matrixRotateAX*matrixRotateAY*matrixRotateAZ*matrixMoveA)); d3d9dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); d3d9dev->SetTransform(D3DTS_WORLD, &(matrixRotateAX2*matrixRotateAY2*matrixRotateAZ*matrixMoveA)); d3d9dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); // draw mesh, using almost same transformations as the triangle D3DXMatrixRotationY(&matrixRotateMesh3, 1.0f); D3DXMatrixTranslation(&matrixMoveA, 0.0f, 0.0f, (0.0f-movementA)); d3d9dev->SetTransform(D3DTS_WORLD, &(matrixScaleA*matrixMoveA*matrixRotateAX*matrixRotateAY)); for (DWORD i = 0; i < numMaterials; i++) { d3d9dev->SetMaterial(&materialX[i]); d3d9dev->SetTexture(0, planeTexture[i]); mesh3->DrawSubset(i); } d3d9dev->SetFVF(CUSTOMFVF); d3d9dev->SetMaterial(material); // cube D3DXMatrixTranslation(&matrixMoveB, 0.0f, 0.0f, 3.0f); D3DXMatrixRotationX(&matrixRotateBX, rotateB); D3DXMatrixRotationY(&matrixRotateBY, rotateB); D3DXMatrixRotationY(&matrixRotateBWide, rotateB); D3DXMatrixScaling(&matrixScaleB, 0.2f, 0.2f, 0.2f); // set vertex buffer source (contains the vertices coord-array in the video ram) d3d9dev->SetStreamSource(0, d3d9VertexBuffer2, 0, sizeof(CUSTOMVERTEX)); // set the texture to be drawn on everything below d3d9dev->SetTexture(0, texture1); // apply transformations (animation matrixes) d3d9dev->SetTransform(D3DTS_WORLD, &(matrixRotateBX*matrixRotateBY*matrixScaleB*matrixMoveB*matrixRotateBWide)); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); // change texture for last side of cube // set the texture to be drawn on everything below d3d9dev->SetTexture(0, texture2); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 2); d3d9dev->SetTexture(0, texture1); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 8, 2); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 12, 2); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 16, 2); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 20, 2); // cube2 D3DXMatrixTranslation(&matrixMoveB, 2.0f, 2.0f, 3.0f); D3DXMatrixRotationX(&matrixRotateBX, rotateB*1.1f); D3DXMatrixRotationY(&matrixRotateBY, rotateB*0.9f); d3d9dev->SetTransform(D3DTS_WORLD, &(matrixRotateBX*matrixRotateBY*matrixScaleB*matrixMoveB)); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); // change texture for last side of cube // set the texture to be drawn on everything below d3d9dev->SetTexture(0, texture2); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 2); d3d9dev->SetTexture(0, texture1); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 8, 2); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 12, 2); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 16, 2); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 20, 2); // cube3 D3DXMatrixTranslation(&matrixMoveB, -2.0f, -2.0f, 3.0f); D3DXMatrixRotationX(&matrixRotateBX, rotateB*0.44f); D3DXMatrixRotationY(&matrixRotateBY, rotateB); d3d9dev->SetTransform(D3DTS_WORLD, &(matrixRotateBX*matrixRotateBY*matrixScaleB*matrixMoveB)); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); // change texture for last side of cube // set the texture to be drawn on everything below d3d9dev->SetTexture(0, texture2); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 2); d3d9dev->SetTexture(0, texture1); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 8, 2); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 12, 2); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 16, 2); d3d9dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 20, 2); d3d9dev->SetTexture(0, NULL); D3DXMatrixTranslation(&matrixMoveB, 5.0f, -5.0f, -20.0f); d3d9dev->SetTransform(D3DTS_WORLD, &(matrixRotateAY*matrixRotateAX*matrixMoveB)); mesh1->DrawSubset(0); // spheres D3DXMatrixRotationX(&matrixRotateBX, rotateB); D3DXMatrixRotationY(&matrixRotateBY, rotateB*0.9f); D3DXMatrixRotationZ(&matrixRotateAZ, rotateB*1.1f); D3DXMatrixTranslation(&matrixMoveA, -1.4f, 0.0f, 0.0f); D3DXMatrixTranslation(&matrixMoveB, -2.0f, -2.0f, 3.0f); d3d9dev->SetTransform(D3DTS_WORLD, &(matrixMoveA*matrixRotateBY*matrixRotateBX*matrixRotateAZ*matrixMoveB)); mesh2->DrawSubset(0); D3DXMatrixTranslation(&matrixMoveA, 1.4f, 0.0f, 0.0f); D3DXMatrixTranslation(&matrixMoveB, -2.0f, -2.0f, 3.0f); d3d9dev->SetTransform(D3DTS_WORLD, &(matrixMoveA*matrixRotateBY*matrixRotateBX*matrixMoveB)); mesh2->DrawSubset(0); // sprite legend legendSprite->Begin(D3DXSPRITE_ALPHABLEND); SetRect(&part, 0, 0, 256, 256); position = D3DXVECTOR3(0.0f, 0.0f, 0.0f); // position at center legendSprite->Draw(legendTexture, &part, ¢er, &position, D3DCOLOR_ARGB(127, 255, 255, 255)); legendSprite->End(); // end sprite drawing // sprite menu effect sprite->Begin(D3DXSPRITE_ALPHABLEND); /* sprite sample by directxtutorial.com // count from 0 to 22 to determine the current frame if(frame < 22) frame++; // if we aren't on the last frame, go to the next frame if(frame < 11) xpos = frame * 182 + 1; if(frame > 12 && frame < 22) xpos = (frame - 12) * 182 + 1; if(frame < 11) ypos = 1; if(frame > 12 && frame < 22) ypos = 123; // draw the selected frame using the coordinates SetRect(&part, xpos, ypos, xpos + 181, ypos + 121); position = D3DXVECTOR3((float)SCREEN_WIDTH/2-91, (float)SCREEN_HEIGHT/2-61, 0.0f); // position at center */ // my sprite // sprite.png frames: // 1st row 1 | 2 | 3 | 4 // ------------- // 2nd row 5 | 6 | 7 | 8 if (frame < 8) { frame++; // if we aren't on the last frame, go to the next frame } if (frame == 1) { xpos = 1; // if we're on the first frame on the first row, xpos is at the first horizontal pixel } else if (frame < 5) { xpos = (frame - 1) * 513; // if we're on the first row of the sprite } else if (frame > 4) { xpos = (frame - 5) * 513; // if we're at the second row of the sprite } if (frame < 5) { ypos = 1; // if were on the first row, ypos is at the first vertical pixel } else { ypos = 257; // if we're on the second row, ypos starts from hte 257th pixel (1-256 are in the first row) } SetRect(&part, xpos, ypos, xpos + 511, ypos + 255); // construct the selected frame using the coordinates position = D3DXVECTOR3((float)SCREEN_WIDTH/2-256, (float)SCREEN_HEIGHT/2-128, 0.0f); // position at center if (frameGo) { // this adds transparent dissapearing of the sprite after ~5s sprite->Draw(spriteTexture, &part, ¢er, &position, D3DCOLOR_ARGB(((frameGoCount>180)?180:frameGoCount), 255, 255, 255)); frameGoCount -= 3; if (frameGoCount < 5) { frameGo = FALSE; } } sprite->End(); // end sprite drawing d3d9dev->EndScene(); // ends the 3D scene d3d9dev->Present(NULL, NULL, NULL, NULL); // displays the created frame on the screen return; }
// // -------------------------------------------------------- // Renders the ListBox control. // -------------------------------------------------------- void DirectX::GUI::ListBox::render( LPD3DXSPRITE d3dsprite, const POINT* pos ) { // Compute absolute offset int xpos = m_posX + pos->x; int ypos = m_posY + pos->y; // Get default sprite sizes for scaling operations float fieldSizeX = (float)(m_style->selectionBox.right - m_style->selectionBox.left); float fieldSizeY = (float)(m_style->selectionBox.bottom - m_style->selectionBox.top); int scrollbarWidth = m_style->downArrow.right - m_style->downArrow.left; // Compute backdrop sprite transform Matrix transformField; float fieldScaleX = (float)(m_sizeX-scrollbarWidth) / fieldSizeX; float fieldScaleY = (float)m_sizeY / fieldSizeX; Vector2 scaling( fieldScaleX, fieldScaleY ), position( (float)xpos, (float)ypos ); D3DXMatrixTransformation2D( &transformField, NULL, 0.0, &scaling, NULL, NULL, &position ); // Draw the selection box background d3dsprite->SetTransform( &transformField ); d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->selectionBox, NULL, NULL, 0xFFFFFFFF ); // Determine number of items in list box int nItemsToDraw = m_sizeY / m_spacing; int limit = ( m_items.size( ) < m_topItemIndex+nItemsToDraw ) ? m_items.size( ) : m_topItemIndex+nItemsToDraw; // Draw the highlights on selected items for( int i = m_topItemIndex; i < limit; i++ ) if( m_items[i].selected ) { // Compute highlight sprite transform Matrix transformBackdrop; float highlightSizeX = (float)(m_style->backdrop.right - m_style->backdrop.left); float highlightSizeY = (float)(m_style->backdrop.bottom - m_style->backdrop.top); float highlightScaleX = (float)(m_sizeX-scrollbarWidth) / highlightSizeX; float highlightScaleY = (float)m_spacing / highlightSizeY; Vector2 scaling( highlightScaleX, highlightScaleY ); Vector2 position( (float)xpos, (float)(ypos+(i-m_topItemIndex)*m_spacing) ); Matrix transform; D3DXMatrixTransformation2D( &transformBackdrop, NULL, 0.0, &scaling, NULL, NULL, &position ); // Draw the highlight sprite d3dsprite->SetTransform( &transformBackdrop ); d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->backdrop, NULL, NULL, 0xFFFFFFFF ); } // Draw text for visible list box entries Matrix matrix; D3DXMatrixIdentity( &matrix ); d3dsprite->SetTransform( &matrix ); RECT textRect; SetRect( &textRect, xpos, ypos, xpos+m_sizeX-scrollbarWidth, ypos+m_spacing ); for( int i = m_topItemIndex; i < limit; i++ ) { // Render list item string m_style->font.getFont( )->DrawTextW( d3dsprite, m_items[i].text.c_str( ), -1, &textRect, Center | VCenter, m_style->color ); // Adjust text rectangle for next element textRect.top = textRect.bottom; textRect.bottom += m_spacing; } // Compute arrow transforms Matrix transformUp, transformDw; float arrowSizeX = (float)(m_style->downArrow.right - m_style->downArrow.left); float arrowSizeY = (float)(m_style->downArrow.bottom - m_style->downArrow.top); Vector2 arrowScale( (float)scrollbarWidth / fieldSizeX, (float)scrollbarWidth / fieldSizeY ); Vector2 positionUp( (float)xpos+(float)m_sizeX-(float)scrollbarWidth, (float)ypos ); Vector2 positionDw( (float)xpos+(float)m_sizeX-(float)scrollbarWidth, (float)ypos+(float)m_sizeY-(float)scrollbarWidth ); D3DXMatrixTransformation2D( &transformUp, NULL, 0.0, &arrowScale, NULL, NULL, &positionUp ); D3DXMatrixTransformation2D( &transformDw, NULL, 0.0, &arrowScale, NULL, NULL, &positionDw ); // Render up arrow with correct sprite d3dsprite->SetTransform( &transformUp ); if( (m_state&PRESS_UP) && (m_state&HOVER_UP) ) d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->upArrowPressed, NULL, NULL, 0xFFFFFFFF ); else if( (m_state&HOVER_UP) || (m_state&PRESS_UP) ) d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->upArrowHover, NULL, NULL, 0xFFFFFFFF ); else d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->upArrow, NULL, NULL, 0xFFFFFFFF ); // Render down arrow with correct sprite d3dsprite->SetTransform( &transformDw ); if( (m_state&PRESS_DOWN) && (m_state&HOVER_DOWN) ) d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->downArrowPressed, NULL, NULL, 0xFFFFFFFF ); else if( (m_state&HOVER_DOWN) || (m_state&PRESS_DOWN) ) d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->downArrowHover, NULL, NULL, 0xFFFFFFFF ); else d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->downArrow, NULL, NULL, 0xFFFFFFFF ); // Compute scroller transform Matrix transformScroller; float scrollerSizeY = (float)(m_style->scroller.bottom - m_style->scroller.top); Vector2 scalingScroller( 1.0f, (float)(m_sizeY-2*scrollbarWidth) / (float)(scrollerSizeY) ); Vector2 positionScroller( (float)(xpos+m_sizeX-scrollbarWidth), (float)(ypos+scrollbarWidth) ); D3DXMatrixTransformation2D( &transformScroller, NULL, 0.0, &scalingScroller, NULL, NULL, &positionScroller ); // Render scroll bar backdrop d3dsprite->SetTransform( &transformScroller ); d3dsprite->Draw( m_style->spriteSheet.getImage( ), &m_style->scroller, NULL, NULL, 0xFFFFFFFF ); }
void CTextureDx9::RenderTexture(LPD3DXSPRITE _lpDSpriteHandle,const RECT* sourceRect, const D3DXVECTOR3* Center, const D3DXVECTOR3* Position, D3DCOLOR Color) { _lpDSpriteHandle->Draw(m_lpTexture, sourceRect, Center, Position, Color); }
void CGameStart::Render(LPDIRECT3DDEVICE9& dxdevice, LPD3DXSPRITE& dxsprite) { dxsprite->Begin(D3DXSPRITE_ALPHABLEND); dxsprite->Draw(GMAIN->m_pGameTex[5].m_pTex, &(GMAIN->rc), NULL, &(GMAIN->vcPos), D3DXCOLOR(1, 1, 1, 1.f)); dxsprite->End(); }