0
votes

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.

1
How exactly doesn't it work? What you see and what you expected to see?Michael Nastenko
What width & height did you pick? Remember it has to be a supported display mode.Chuck Walbourn
it doesnt work because when I create my directx device, it is a null pointer and my program crashes. when i use fullscreen but when there is no fullscreen, the directx device is created.lvl99knight
I chose 600x480 (rather my book told me to use 600x480).lvl99knight
Show your CreateDevice call. What HRESULT do you have from CreateDevice? And put all additional data to question itself.Michael Nastenko

1 Answers

2
votes

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.