Jump to content
  • Advertisement
Sign in to follow this  
odyodyodys

transformation matrix went wrong.. (I NEED some HELP!!)

This topic is 3630 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I am trying to use ID3DXSprite to draw images on the screen. I want to do something like the life and power bar in games, 2d graphics. I've managed to do it, but i'm failing at the transformation matrix that will scale the image as desired. I've loaded a texture and the code below is inside the BeginScene-EndScene What I do is the following:
//Load the texture (this is in the initialization method)
D3DXCreateTextureFromFile(device, imageFilename.c_str(), &imageTexture);

//------------------------- inside the BeginScene/EndScene method

sprite->Begin(D3DXSPRITE_ALPHABLEND);

D3DXVECTOR3 position(0, 0, 0); // Set the image to start from top left

// My image is 1440*1050 and my monitor resolution is 1440*900
// I've set those values by testing it, and like this it is stretched for this resolution only
imageStretchMatrix = D3DXMATRIX( 0.703f,  0.0f,  0.0f,  0.0f,
                                 0.0f,  0.439f,  0.0f,  0.0f,
                                 0.0f,  0.0f,  1.0f,  0.0f,
                                 0.0f,  0.0f,  0.0f,  1.0f);

// Transform using the imageStrechMatrix
sprite->SetTransform(&imageStretchMatrix);

sprite->Draw(imageTexture, NULL, NULL, &position, D3DCOLOR_ARGB(255, 255, 255, 255));

sprite->End();


What should I do so the image is stretched in the monitor? (to cover the whole screen) and how should I compute the x and y transformation factors? Thanks in advance, every bit of info is treasure for me!

Share this post


Link to post
Share on other sites
Advertisement
The X scaling factor you need in this case is simply screenWidth / imageWidth. The Y scaling factor is screenHeight / imageHeight. Once you have these values, you can simply give them to D3DXMatrixScaling


// Get the texture dimensions
D3DSURFACE_DESC imageDesc;
imageTexture->GetLevelDesc(0, &imageDesc);

// Get the backbuffer dimensions (you should probably have this stored anyway)
LPDIRECT3DSURFACE9 backBuffer;
device->GetRenderTarget(0, &backBuffer);
D3DSURFACE_DESC backbufferDesc;
backBuffer->GetDesc(&backbufferDesc);

// If you're not going to hold onto a pointer to the backbuffer, make sure you
// Release it!
backBuffer->Release();

// Figure out the scaling values
float scaleX = backbufferDesc.Width / (float)imageDesc.Width;
float scaleY = backbufferDesc.Height / (float)imageDesc.Height ;

// Make the scaling matrix
D3DXMATRIX scaleMatrix;
D3DXMatrixScaling(&scaleMatrix, scaleX, scaleY, 1.0f);


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!