Skip to main content
gamedev.net
🔒 Locked

make background image

Started by 31337noob 5 replies 1.7k views
Original Post
31337noob
31337noob
hi, i have an image that i want to take up the full window. how can i do that easily? BTW, the directx window is not set to a certain width and height. my game engine finds the best size for them. so the background image has to resize to the whole window. is there a way just using sprites to do that, or what? i know that the Clear function in the device changes the background color, is there a parameter to make it an image? i am trying to make a menu and intro scenes that fills up the whole window. please help.
fpsgamer
fpsgamer
I am not up to date on the Direct X API, but what you're looking for is a "Screen Aligned Quad". That is a quadrilateral polygon that is perfectly aligned with the screen. On that quad you map your background texture.

[Edited by - fpsgamer on July 29, 2007 10:03:41 PM]
31337noob
31337noob
i want to see an example on how you use "Screen Aligned Quad" in directx c++.

i am trying to find a good example, but no luck so far.
ilflyer12
ilflyer12
To make a background image (of anysize) you will want to use either a textured quad or the sprite interface. My personal preference is the sprite interface. To do this, load the texture you want as the background. Then create a sprite. Now to stretch the whole screen width, you will set a transformation for the sprite to the size of the window you are drawing to. Here is a bit of pseudocode for you.

D3DXCreateSprite (pd3dDevice, &pSprite);D3DXCreateTextureFromFile (pd3dDevice, "background.jpg", &BGTexture);...// Render Portion of CodepSprite->Begin();D3DXMATRIX ScaleMatrix;D3DXMatrixScaling(&ScaleMatrix, screenWidth / textureWidth, screenHeight / textureHeight, 1);pSprite->SetTransform(&ScaleMatrix);pSprite->Draw(BGTexture, NULL, NULL, NULL, D3DCOLOR_RGBA(255,255,255,255));pSprite->End();


The code above is just pseudocode and is missing getting the texture sizing, etc. and i have not tested it but it is just pseudocode so it should put you in the right direction. Hope this helps.
31337noob
31337noob
Quote:
Original post by ilflyer12
To make a background image (of anysize) you will want to use either a textured quad or the sprite interface. My personal preference is the sprite interface. To do this, load the texture you want as the background. Then create a sprite. Now to stretch the whole screen width, you will set a transformation for the sprite to the size of the window you are drawing to. Here is a bit of pseudocode for you.

D3DXCreateSprite (pd3dDevice, &pSprite);D3DXCreateTextureFromFile (pd3dDevice, "background.jpg", &BGTexture);...// Render Portion of CodepSprite->Begin();D3DXMATRIX ScaleMatrix;D3DXMatrixScaling(&ScaleMatrix, screenWidth / textureWidth, screenHeight / textureHeight, 1);pSprite->SetTransform(&ScaleMatrix);pSprite->Draw(BGTexture, NULL, NULL, NULL, D3DCOLOR_RGBA(255,255,255,255));pSprite->End();


The code above is just pseudocode and is missing getting the texture sizing, etc. and i have not tested it but it is just pseudocode so it should put you in the right direction. Hope this helps.


what should the file width and height be..

it still cuts off the bottom of my texture

1024x768 is my file width and height

just to let you know, my screen width and height is 1280x1024.. i want the sprite to fit perfectly

[Edited by - 31337noob on July 30, 2007 9:52:29 PM]
ilflyer12
ilflyer12
Well if you are using a windowed application, you need to take into account the amount of the screen that has the menus on it (aka file, edit, etc.). There is a windows call that will give you the area of your screen that you actually are drawing to but i do not remember it off the top of my head. Just google window size and you should get it. Also, the other reason you the image could be cut off is that your image does not have dimensions that are powers of 2. The width is correct at 1024 (2^10) but 768 is not a power of 2. This will cause issues on most video cards because they do not like textures that are not powers or 2. Therefore, resize the image to either 1024x512 or 1024x1024 and you should not get this problem.
31337noob
31337noob
Quote:
Original post by ilflyer12
Well if you are using a windowed application, you need to take into account the amount of the screen that has the menus on it (aka file, edit, etc.). There is a windows call that will give you the area of your screen that you actually are drawing to but i do not remember it off the top of my head. Just google window size and you should get it. Also, the other reason you the image could be cut off is that your image does not have dimensions that are powers of 2. The width is correct at 1024 (2^10) but 768 is not a power of 2. This will cause issues on most video cards because they do not like textures that are not powers or 2. Therefore, resize the image to either 1024x512 or 1024x1024 and you should not get this problem.


thanks man...

you reminded me about the 2^n..now it works great..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.