🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Issue with adding Antialiasing in Direct3D9

Started by
6 comments, last by ESries19 2 years ago

Hello everyone, I have a game source that I recently upgraded from DX8 to DX9, without further ado, I'm now trying to add built in support for antialiasing, here's my code

// Check MultiSampling Support
    HRESULT hr = ms_lpd3d->CheckDeviceMultiSampleType(ms_iD3DAdapterInfo, D3DDEVTYPE_HAL,
    D3DFMT_R8G8B8, FALSE, D3DMULTISAMPLE_2_SAMPLES, NULL);

    if (FAILED(hr))
    {
        ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_NONE;
        return false;
    }
    else
    {
        D3DPRESENT_PARAMETERS    ms_d3dPresentParameter;
        ZeroMemory(&ms_d3dPresentParameter, sizeof(ms_d3dPresentParameter));

        ms_d3dPresentParameter.Windowed = TRUE;
        ms_d3dPresentParameter.SwapEffect = D3DSWAPEFFECT_DISCARD;
        ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;

        hr = ms_lpd3d->CreateDevice(ms_iD3DAdapterInfo, D3DDEVTYPE_HAL,
            hWnd,
            D3DCREATE_HARDWARE_VERTEXPROCESSING, &ms_d3dPresentParameter, &ms_lpd3dDevice);
    }

    ms_lpd3dDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);

it's returning this error CreateDevice: Unknown Error

Anyone knows whats going on?

Advertisement

What is the value returned by CreateDevice?

In the CheckDeviceMultisampleType you specified a R8G8B8 format (which is not a valid backbuffer format) but you didn't specify a format in the D3DPRESENT_PARAMETERS. And you are checking for Fullscreen multisampling and then you Create a windowed application.

I recommend checking the parameters you are passing to the D3D functions, and the return values (set breakpoints or log the values).

Why “return false” when multisampling is not supported? Is multisampling support mandatory?

@Aerodactyl55 Hi thank you so much for your analysis! Oh I did not know R8G8B8 was not a valid backbuffer format, I've done it according to Microsoft instructions, which had done it that way… Sorry I'm still learning.. well I've updated the code, I would appreciate if you could be so kind to take a second look.

if (SUCCEEDED(ms_lpd3d->CheckDeviceMultiSampleType(ms_iD3DAdapterInfo,
		D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, FALSE,
		D3DMULTISAMPLE_2_SAMPLES, NULL)))

	D3DPRESENT_PARAMETERS	ms_d3dPresentParameter{};
	ZeroMemory(&ms_d3dPresentParameter, sizeof(ms_d3dPresentParameter));
	ms_d3dPresentParameter.BackBufferFormat = D3DFMT_A8R8G8B8;
	ms_d3dPresentParameter.Windowed = FALSE;
	ms_d3dPresentParameter.SwapEffect = D3DSWAPEFFECT_DISCARD;
	ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;


	ret = ms_lpd3d->CreateDevice(ms_iD3DAdapterInfo, D3DDEVTYPE_HAL, hWnd,
	D3DCREATE_HARDWARE_VERTEXPROCESSING, &ms_d3dPresentParameter, &ms_lpd3dDevice);

	if (FAILED(ret))
	{
		return CREATE_GET_DEVICE_CAPS2;
		return false;
	}

	// Enable MSAA
	ms_lpd3dDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);

As for return false, It's just for me to test if it works. I plan to change it to just set sampling to NONE in production environment if it fails.

I recommend checking the parameters you are passing to the D3D functions, and the return values (set breakpoints or log the values).

Yeah im trying to do that. mind giving me example on how to do that please?

Also i'm not really sure if i need BackBufferFormat in my code? what purpose it serves? I'm just trying to enable AA to reduce the look of pixelated edges.

Does the error persist after you changed the code? Try creating a windowed application, and passing D3DADAPTER_DEFAULT to the adapter index.

Set a breakpoint at the “if (FAILED(ret))” test. And check what value the “ret” variable has.

Aerodactyl55 said:

Does the error persist after you changed the code? Try creating a windowed application, and passing D3DADAPTER_DEFAULT to the adapter index.

Set a breakpoint at the “if (FAILED(ret))” test. And check what value the “ret” variable has.

yeah still same error. Also just tried passing D3DADAPTER_DEFAULT instead of ms_iD3DAdapterInfo, still the same.

I don't really know how to set a breakpoint.

edit: im trying now windowed

edit: tried with windowed. still the same.

If you are using Visual Studio, just right click on the side of line you want to set the breakpoint. A red circle will appear to indicate that the breakpoint is set. When you run the code and execution reaches the line you set the breakpoint, the application will “freeze” there, and you can hover the mouse on variables to check values.

But this does not work well with fullscreen applications, I recommend you switch to windowed until you solve this problem.

@Aerodactyl55 Okay im trying now but it's worth noting im not running the app through visual studio directly, first i have to compile it and then run it. I'm recompiling now with windowed to see..

edit: nothing.. still same error :(

This topic is closed to new replies.

Advertisement