# Making a fullscreen texture

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

## Recommended Posts

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.

##### Share on other sites
The dimensions you pass to CreateWindow determine the size for the entire window, including the frames, tile bar, and window menu. You want your client area to be 1280*800, not the entire window. To do this you can use AdjustWindowRect to come up with the proper window size for you.

Also you generally want Scale * Translation, not the other way around. If you want you can use D3DXMatrixTransformation2D to do everything in one step.

##### Share on other sites
I got this in my initMainWindow() function already:

(width = 1280, height = 800)

RECT R = {0, 0, width, height};	AdjustWindowRect(&R, WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, false);	mhMainWnd = CreateWindow("D3DWndClassName", mMainWndCaption.c_str(), 		WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, R.right, R.bottom, 		0, 0, mhAppInst, 0);

I don't know if im doing it right, take a look at it.

And why does all my sprites get turned up-sidedown when i draw them? :O

Edit: This is how it looks -> http://yfrog.com/1aweirdip

##### Share on other sites
You can confirm the client area with GetClientRect as well.

I think what you want here is not to use a scaling matrix, but instead to set an orthographic projection. Have a look at the D3DXMatrixOrtho functions, set your projection transform (view and world should be identity) then draw.

You won't be able to do this using ID3DXSprite, by the way, so you'll need to get your hands dirty with vertexes. DrawPrimitiveUP should be fine for this requirement too, using a vertex buffer is probably overkill (and overly complicating things) right now.

##### Share on other sites
I don't see any reason you can't use a sprite. I haven't tried this fullscreen but if works fine for a windowed app:
		LPDIRECT3DTEXTURE9 tex = NULL;		HRESULT hr = D3DXCreateTextureFromFile(m_pDevice,"f:/projects/textures/seccamera.bmp",&tex);		if( FAILED(hr) )		{			OutputDebugString("Failed to create texture\n");			return E_FAIL;		}		RECT r;		GetClientRect(hwndClient,&r);		D3DSURFACE_DESC desc;		tex->GetLevelDesc(0,&desc);		UINT twidth = desc.Width;		UINT theight = desc.Height;		float scaleX = float(r.right-r.left)/(float)twidth;		float scaleY = float(r.bottom-r.top)/(float)theight;		D3DXMATRIX scale;		D3DXMatrixScaling(&scale,scaleX,scaleY,1.0f);		LPD3DXSPRITE sprite;		D3DXCreateSprite(m_pDevice,&sprite);		sprite->Begin(0);		sprite->SetTransform(&scale);		D3DXVECTOR3 pos = D3DXVECTOR3(0,0,0);		sprite->Draw(tex,NULL,0,&pos,0xffffffff);		sprite->End();		RELEASE(sprite);		RELEASE(tex);	}

NOTE: I position the sprite with position, not center.

WRT upside-down image: it's possible your texture is really a DIB created to be "rightside up," contrary to most bmp's. I would think CreateTexFromFile would handle, though.

Just for fun, you could use scaleY = -scaleY and pos = D3DXVECTOR3(0,-float(r.bottom-r.top),0). If you change the sign of the scale you have to position it correctly.

1. 1
2. 2
3. 3
frob
12
4. 4
5. 5

• 13
• 14
• 65
• 14
• 15
• ### Forum Statistics

• Total Topics
632130
• Total Posts
3004286

×