Changing Resolution in directx

Started by
8 comments, last by nilbast 15 years, 11 months ago
Im pretty new to this whole mess of directx programing in c++ so please correct me if my approach to sprite rendering is wrong. Im trying to code a sprite system that changes according to my change in resolution. I found a way that worked great on my workstation computer (that has a widescreen running at 1440x900). I set up my whole interface at this resolution and now i want to change it or at least allow a fullscreen monitor to display my sprites properly. I am rendering sprites in this manner: 1. Initializing the D3DXSprite Interface using LPD3DXSPRITE d3dspt; 2. Loading a Texture using LPDIRECT3DTEXTURE9 and D3DXCreateTextureFromFileEx(p_dx_Device, // the device pointer "title1.png", // the new file name SCREEN_WIDTH, // default width SCREEN_HEIGHT, // default height D3DX_DEFAULT, // no mip mapping NULL, // regular usage D3DFMT_A8R8G8B8, // 32-bit pixels with alpha D3DPOOL_MANAGED, // typical memory handling D3DX_DEFAULT, // no filtering D3DX_DEFAULT, // no mip filtering D3DCOLOR_XRGB(255, 0, 255), // the hot-pink color key mask NULL, // no image info struct NULL, // not using 256 colors &sprite); // load to sprite 3. And then drawing the texture in this manner: RECT part; SetRect(∂, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); D3DXVECTOR3 position(0.0f, 0.0f, 0.0f); d3dspt->Draw(sprite, ∂, &center, &position, D3DCOLOR_ARGB(255, 255, 255, 255)); I am assuming that this is the proper way to do this. My problem is that when I run this on a fullscreen monitor at say 800x600 it displays wrong. (on my widescreen it renders everything fine even if the resolution is set at 800x600) I was assuming that direct x would stretch all the images to the height and width settings in D3DXCreateTextureFromFileEx. This code works completely on my widescreen. I run this equation on all my images and where it draws them: (Natural_Image_Width*Current_Screen_Resolution_Width/1440) and (Natural_Image_Height*Current_Screen_Resolution_Height/900) because i set the interface up on 1440x900. Is this how resolution is handled in normal directx programs? Any help would be appreciated... Thanx, Nil
Advertisement
I would enumerate the available adaptor modes by using IDirect3D9::EnumAdapterModes function. This will give a list of what available screen resolutions and refresh rates the GPU supports at full screen. It will give widescreen formats automatically if you have a widescreen monitor.

hope that helps
Don't stretch the image when you load it up, that's just a waste of memory. You can instead scale the sprite when you render it.

D3DSURFACE_DESC surfaceDesc;sprite->GetLevelDesc(0, &surfaceDesc);D3DXMATRIXA16 matScale;D3DXMatrixScaling(&matScale, static_cast<FLOAT>(SCREEN_WIDTH)/surfaceDesc.Width, static_cast<FLOAT>(SCREEN_HEIGHT)/surfaceDesc.Height, 0);d3dspt->SetTransform(&matScale);
Thanx guys... Both of you provided me with some very useful info. But I'm still a little confused why if I run the program 800X600 on my widescreen the equation I used works but when I render 800x600 on a fullscreen monitor the sprites don't fit properly.
What happens if you take out the RECT in the sprite draw call? Just use NULL instead?
the rect is the designated area for the animations (showing only part of the image)
it displays more of the image than i want if i use NULL
Perhaps one of your computers doesn't support non-power-of-2 textures? That would have caused the texture to be loaded at 1024 x 1024.
OMG i think you may be right.... that makes sense really but one card is a geforce fx5900 and other is an ati radeon 9700... both are less than 5 years old. my widscreen is far newer than the other two... is support of non-power-of-2 textures something new? is there a function that checks that like in d9caps?
D3DPTEXTURECAPS_NONPOW2CONDITIONAL is what ive found

thanx MJP ill play with this a while (I probably should do power of 2 on all images just for compatability's sake. I just assumed...too much)
There's actually 2 caps for power-of-2 textures...the combination of them tells you what you can do with them. If D3DPTEXTURECAPS_POW2 is set, it means you can only user power-of-2 textures no matter what. If D3DPTEXTURECAPS_POW2 is not set and D3DPTEXTURECAPS_NONPOW2CONDITIONAL is set, it means you can use non-power-of-2 textures but with restrictions (clamp-addressing only, no mip-maps, no DXT formats). If neither are set, you can use non-power-of-2 textures with no restrictions.

As far as those GPU's...in my experience I've found very few DX9-class GPU's that don't support non-power-of-2 textures. Many of them have the "D3DPTEXTURECAPS_NONPOW2CONDITIONAL" flag set, though. However that fx5900 worries me...that entire line had very inconsistent support for optional DX9 features and it wouldn't surprise me if it didn't support this one. A lot of PC games don't support that line for this reason.

EDIT: You're sending "D3DX_DEFAULT" as the parameters number of mipmap-levels, and this causes the function to generate the entire not mipmap chain. You have to specify "1" if you don't want mipmaps. I'm not sure if this is related to your problem or not, but its possible that the D3DPTEXTURECAPS_NONPOW2CONDITIONAL is set and it's causing D3DX to bump the texture up to a power-of-2 size since you're asking for mipmaps.
yep you nailed it... it was the mip map thing... it now works on all 3 comps (there is a variation on the ati card so i'm gonna try the transform thing now) thanx again MJP

This topic is closed to new replies.

Advertisement