• Advertisement
Sign in to follow this  

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

This topic is 3360 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


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->Draw(imageTexture, NULL, NULL, &position, D3DCOLOR_ARGB(255, 255, 255, 255));


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
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
imageTexture->GetLevelDesc(0, &imageDesc);

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

// If you're not going to hold onto a pointer to the backbuffer, make sure you
// Release it!

// 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