Presentation Parameters/Full Screen

Started by
4 comments, last by MJP 16 years, 6 months ago
I need some insight on an issue I am having with DirectX. I have setup code that will switch between a windowed window and a full screen window. The program works fine on my friends computers and on the computer I have at work. However, on my laptop it will crash whenever I try to go to full screen. No matter what numbers I set for the width and height of the back buffer, it will always be 17 off for width and 20 off for height. Ex: I set an int value for width of 1680, height of 1050. Run the program, insert a break b4 it resets the device but after the presentation parameters have been set up and it will show that the width stored is 1663 and the height will be 1030. This causes the program to crash because my video card does not support that resolution. Laptop: Alienware mALX AMD Athlon 64 Turion nVidia Geforce Go 7900 GTX (SLI, although disabled, same plm)
Advertisement
What language? This sounds to me like you're computing the size of the backbuffer from the size of the window client area. When you pass a size to MoveWindow() or CreateWindow(), it's the size of the window, not of the client area. You need to use AdjustWindowRectEx() to convert from a client area size (E.g. 800x600) to a window size (E.g. 817x620).

If that's not the problem, can you show exactly how you set up the presentation parameters? D3D won't change them, so you must be changing them somewhere in your code.
The language is c++, guess I forgot to mention that, it would have been useful. I did find the problem. Here is the code I had when going to full screen (this was taken from a book I was using):

// Switch to fullscreen mode.
if( enable )
{
// Are we already in fullscreen mode?
if( !d3dPP.Windowed )
return;

int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);

d3dPP.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dPP.BackBufferWidth = width;
d3dPP.BackBufferHeight = height;
d3dPP.Windowed = false;

// Change the window style to a more fullscreen friendly style.
SetWindowLongPtr(mhMainWnd, GWL_style, WS_POPUP);

// If we call SetWindowLongPtr, MSDN states that we need to call
// SetWindowPos for the change to take effect. In addition, we
// need to call this function anyway to update the window dimensions.
SetWindowPos(mhMainWnd, HWND_TOP, 0, 0, width, height, SWP_NOZORDER | SWP_SHOWWINDOW);
}
//else portion has been omitted

// Reset the device with the changes.
onLostDevice();
HR(gd3dDevice->Reset(&d3dPP));
onResetDevice();
}

That is the code that was given in the book. By using debug I found that SetWindowPos was what was changing the values, although I am not sure why. I commented out that code because if I am going full screen I really don't need to set the position fo the window, or at least I think. The comments and code are from the book I was using as a reference. Hope this helps. Thanks for the response, I appreciate it.
If you chaneg the style of a window with SetWindowLong, then you need to call SetWindowPos() with the SWP_FRAMECHANGED flag to update the window style. That only really makes a noticible difference when going from fullscreen to windowed though.

SetWindowPos() will not change the values passed to it - it can't, they're passed by value, not by reference or as pointers. The code you've shown should work fine (Although I wouldn't force the device to be created at the current screen resolution).
Its weird because the code does work fine on everyone's machine but mine :(. If I comment out the SetWindowPos command then it works fine on mine. And you make a good point, I am not going to force the device to be created at the current screen resolution, I will change that to a specified value.

I do appreciate the help. The only reason I traced it to this function is because if I do a debug and step through the values that are stored in backbuffer width and height are fine up until that function. After that function is called, they are different from what they were set to. I have an image of it, I will try and post it somewhere and then link to it. Thanks again.
Quote:Original post by mperry
Its weird because the code does work fine on everyone's machine but mine :(. If I comment out the SetWindowPos command then it works fine on mine. And you make a good point, I am not going to force the device to be created at the current screen resolution, I will change that to a specified value.



When you're setting a backbuffer size for fullscreen mode, you should be checking to make sure the settings match one of the possible configurations you enumerated with EnumAdapterModes()

This topic is closed to new replies.

Advertisement