Making a fullscreen texture (DX9)

Need help to make a background texture fullscreen in DirectX

Page 1 of 1

4 Replies - 2440 Views - Last Post: 19 February 2013 - 02:47 PM Rate Topic: -----

#1 simpler  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 02-March 10

Making a fullscreen texture (DX9)

Posted 15 July 2010 - 01:11 PM

Hi, I have during my past 3 hours tried to make a background texture in DirectX to fit the whole window. The texture is suppose to be a background for a game . I've tried everything i possible could think of and I'd be pleased if you could give me some help about it.

In the constructor i create the texture like this (the image file is 512*512)

HR(D3DXCreateTextureFromFile(gd3dDevice, "sky_bkg1.bmp", &mBkgdTex));
mBkgdCenter = D3DXVECTOR3(256.0f, 256.0f, 0.0f);


The window is 1280*800 and I want the texture to be in the same size so that it can be rendered over the whole screen.
Therefore in my drawScene() function I scale it up to the right resultion. (In the CreateWindow() function i send 1280 as the width and 800 as height, they are defined in another file as WIDTH and HEIGHT)

/*float scalingX, scalingY;
	D3DSURFACE_DESC bkgdTexInfo;
	mBkgdTex->GetLevelDesc(0, &bkgdTexInfo);

	scalingX = (float)WIDTH / bkgdTexInfo.Width;
	scalingY = (float)HEIGHT / bkgdTexInfo.Height;

	D3DXMATRIX T,S;
	D3DXMatrixTranslation(&T, 0, 0, 0);
	D3DXMatrixScaling(&S, scalingX, scalingY, 0.0f);
	HR(mSprite->SetTransform(&(T*S)));
	HR(mSprite->Draw(mBkgdTex, 0, &mBkgdCenter, 0, D3DCOLOR_XRGB(255, 255, 255)));
	HR(mSprite->Flush());	


With this method I want to find out how much i have to scale the texture in order for it to get 1280*800. I then make a scaling matrix to change it's scale as required. However it doesn't work. The image gets bigger but there is a small line around the whole image between it and the windows borders. The image doesnt take up the whole screen like it should do..

If you didn't get the idea of my example i simply want to make a texture to be full screen, it doesnt matter if the quality gets bad or so as long as there are no parts of the texture that ain't visible on the screen.

Btw, the image is also inverted. Up is down and down is up.. I dont understand that either.

Thanks.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Making a fullscreen texture (DX9)

#2 ModMaker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 18
  • Joined: 12-July 10

Re: Making a fullscreen texture (DX9)

Posted 15 July 2010 - 03:12 PM

If you do not use the texture for anything else, you can instead load the image into a surface (IDirect3DSurface9*) so you can call IDirect3DDevice9::StretchRect. This function will take your surface and stretch it to fit a designated size onto the back buffer. Image is a IDirect3DSurface9* Here is some code to load the file:

 gd3dDevice->CreateOffscreenPlainSurface( width, height, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &image, NULL);
	
//load surface from file into newly created surface
D3DXLoadSurfaceFromFile( image, NULL, NULL, filepath, NULL, D3DX_DEFAULT, 0, NULL );


And when you want to display the image to the screen, use this code. You will need to create two RECT structs (r1 and r2 ) that will hold the bounding box of the image in the file, most likely { 0, 0, width, height }, and the other will hold where you want to place it on the screen, most likely { 0, 0, screenwidth, screenheight }.

IDirect3DSurface9* BackBuf;
gd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &BackBuf);
gd3dDevice->StretchRect( BackBuf, &r1, image, &r2, D3DTEXF_POINT );

Was This Post Helpful? 1
  • +
  • -

#3 simpler  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 02-March 10

Re: Making a fullscreen texture (DX9)

Posted 15 July 2010 - 04:01 PM

Thanks alot for the answer ModMaker!
I'm pretty new to this scene so could you please tell me how i draw the surface? And btw, there must be a way to do it with sprite and textures, I've been looking around and people say thet the surface solution ain't the best. If you know another way to do it please tell me :)
Was This Post Helpful? 0
  • +
  • -

#4 ModMaker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 18
  • Joined: 12-July 10

Re: Making a fullscreen texture (DX9)

Posted 15 July 2010 - 04:35 PM

I haven't use transformations with LPD3DXSPRITE, so I don't know how that works. I also noticed a possible error in your code:

Quote

HR(mSprite->SetTransform(&(T*S)));


It is safer to apply the multiplication to another variable and use the address of that in the function.

D3DXMATRIX O;
D3DXMatrixMultiply( &O, &T, &S );
HR(mSprite->SetTransform(&O));



But to draw the surface onto the screen, place the below code after IDirect3DDevice9::BeginScene().

RECT r1, r2;
r1.top = 0;
r1.left = 0;
r1.bottom = heightOfSurface
r1.right = widthOfSurface

r2.top = 0;
r2.left = 0;
r2.right = widthOfScreen;
r2.bottom = heightOfScreen;

IDirect3DSurface9* BackBuf;
gd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &BackBuf);

pd3dDevice->StretchRect( BackBuf, &r1, surface, &r2, D3DTEXF_POINT );


Was This Post Helpful? 0
  • +
  • -

#5 sprezzatura  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-February 13

Re: Making a fullscreen texture (DX9)

Posted 19 February 2013 - 02:47 PM

The code works, except for one error: the source/destination parameters are reversed in the example. It should be:
gd3dDevice->StretchRect(image , &r1, BackBuf, &r2, D3DTEXF_POINT );

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1