Search code examples
c++directx2d-games

DirectX Present Parameters Windowed=false not working


I am trying to make a game. I am using directx 9 to do so and I have some issues trying to go into full screen mode. I made a function that initalized all of the Present Parameters . Everything is fine except when I make windowed = false (ie i set fullscreen to true).

here is my present parameters variable: D3DPRESENT_PARAMETERS d3dpp;

Here is the code for the d3dpp variable. Most if not all of this code comes from a book called Programming 2d Games by charles kelley.

void Graphics::initD3Dpp()
{
try {
    ZeroMemory(&d3dpp, sizeof(d3dpp));              

    d3dpp.BackBufferWidth = width;
    d3dpp.BackBufferHeight = height;
    if (fullscreen)                                  
        d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;  
    else
        d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;   
    d3dpp.BackBufferCount = 1;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.hDeviceWindow = mainhwnd;
    d3dpp.Windowed = (!fullscreen); //THIS LINE RIGHT HERE IS THE ISSUE
    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
}
catch (...)
{
    throw(GameError(gameErrorNS::FATAL_ERROR,
        "Error initializing D3D presentation parameters"));

}

} 

I do not see why .windowed does not work for me. Please ask me if you need more context.


Solution

  • From the comments, you suggest that you are using 600x480. It's highly doubtful that this is a supported resolution on your system, more likely, you meant to be using 640x480. As far as I know, this resolution is supported by essentially every D3D9 driver.

    However, hardcoding the resolution is not a robust solution, it's far more practical to follow the advice stated in the documentation for D3DPRESENT_PARAMETERS, and use the EnumAdapterModes function, to get a list of valid resolutions and display formats for your device.