Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem between OpenGL and DirectX renderings

Started by jonathon99 Jun 30, 2012 at 11:28 PM 11 replies 4.3k views
Original Post
jonathon99
jonathon99
I have a couple issues with inconsistencies between OpenGL and DirectX. I wrote my editor and other tools in DirectX and the game itself is in OpenGL (for easy porting). I've noticed differences between the texture filtering/quality, thickness of the fog, coloring and other issues. All the settings (color, fog intensity/amount, etc are identical between the two). I've made sure I'm running most of the same settings or as close as I could get them, however, my OpenGL experience is limited. If anyone can spot something that I may be overlooking please feel free to comment. It will be greatly appreciated!

// Comparison screenshots with and without fog, the top image in the screenshots are in DirectX the other is OpenGL
nofog_sm.jpg fog_sm.jpg

You can see that in the top image (DirectX) are much better and the desired look. Does anyone have any idea why this is happening? Here is my code for most of the generic rendering states.

[size=2]//DirectX Texture Filtering
[size=2]Device->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
[size=2]Device->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
[size=2]Device->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);

[size=2]//OpenGL Texture Filtering
[size=2][size=2]glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
[size=2][size=2]glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );
[size=2][size=2]glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);

[size=2][size=2]//DirectX Alpha Settings
[size=2][size=2][size=2]Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
[size=2][size=2][size=2]Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

[size=2][size=2][size=2]//OpenGL Alpha Settings
[size=2][size=2][size=2][size=2]glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

[size=2][size=2][size=2][size=2]//DirectX Alpha Test Settings
[size=2][size=2][size=2][size=2][size=2][size=2]Device->SetRenderState( D3DRS_ALPHAREF , (DWORD)0xAA );
[size=2][size=2][size=2][size=2][size=2][size=2]Device->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
[size=2][size=2][size=2][size=2][size=2][size=2]Device->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );

[size=2][size=2][size=2][size=2][size=2][size=2]//OpenGL Alpha Test Settings
[size=2][size=2][size=2][size=2][size=2][size=2][size=2]glAlphaFunc(GL_GREATER,0.1f);

[size=2][size=2][size=2][size=2][size=2][size=2]//DirectX Z Function
[size=2][size=2][size=2][size=2][size=2][size=2][size=2]Device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);

[size=2][size=2][size=2][size=2][size=2][size=2][size=2]//OpenGL Z Function
[size=2][size=2][size=2][size=2][size=2][size=2][size=2][size=2]glDepthFunc(GL_LEQUAL);
NumberXaero
NumberXaero
hard to say, is alpha test enabled under opengl?
L. Spiro
L. Spiro
For starters, your alpha-testing states are not the same.
D3DCMP_GREATEREQUAL != GL_GREATER and 0xAA (0.667) != 0.1.

Considering the brightness of your fog and flames, I would consider that not enough pixels are being rejected in OpenGL, which would be due to the low alpha-test value.


L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
jonathon99
jonathon99
[size="2"]glAlphaFunc(GL_GEQUAL,0.667f);

[size="2"]Getting the same result. I think maybe it has something to do with my billboard system for the fog perhaps but even if that was the case, the texture quality seems a bit lower for some reason.
L. Spiro
L. Spiro
Specify higher-quality mipmaps.
::glHint( GL_GENERATE_MIPMAP_HINT, GL_NICEST );

Also, post shaders.


L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
jonathon99
jonathon99
Still having an issue with the fog.. I'm not using shaders. This was entirely written in OpenGL 1.1
Arkhyl
Arkhyl

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );

You can only set mag filter to GL_LINEAR or GL_NEAREST. Also, for your alpha func, the equivalent OpenGL to D3DCMP_GREATEQUAL is GL_GEQUAL.
21st Century Moose
21st Century Moose
Also this is going to reduce the effectiveness of your mipmapping:glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
jonathon99
jonathon99

[quote name='jonathon99' timestamp='1341098916' post='4954398']
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );

You can only set mag filter to GL_LINEAR or GL_NEAREST. Also, for your alpha func, the equivalent OpenGL to D3DCMP_GREATEQUAL is GL_GEQUAL.
[/quote]

I ended up changing it to GL_GEQUAL and GL_LINEAR for the MAG


Also this is going to reduce the effectiveness of your mipmapping:glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);


The textures look extremely blurry when I take out that line of code.

I appreciate all the help so far but it seems even with mipmapping disabled entirely, I'm still getting thicker fog in OpenGL as well as lower quality fog texturing. I realize this could be many different reasons so I'm going to pull an all nighter trying to investigate. I appreciate everyone's help so far!
21st Century Moose
21st Century Moose

The textures look extremely blurry when I take out that line of code.

That indicates you've got something else wrong, perhaps with your texture loading setup or some state you haven't shown us, as otherwise GL_LINEAR/GL_LINEAR_MIPMAP_LINEAR is exactly equivalent to D3DTEXF_LINEAR/D3DTEXF_LINEAR/D3DTEXF_LINEAR (an example might be a bad value for GL_MAX_TEXTURE_SIZE compared to your D3DCAPS9::MaxTextureWidth and D3DCAPS9::MaxTextureHeight causing you to resample textures down too much in your GL renderer) - at the most fundamental level all that the API does is tell the hardware what to do, and what the hardware does is API-agnostic, so your OpenGL and D3D renderings should look identical if everything else is equal.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
jonathon99
jonathon99
I still haven't really been able to pinpoint what exactly is causing the inconsistencies but it doesn't seem to have much to do with everything we've discussed here. It's quite puzzling.
lawnjelly
lawnjelly
Are there any differences in the vertex colours being applied? If you are not meaning to use vertex colours but it's still switched on by accident this can cause a tinge. It almost looks like there is an extra constant being added to the fog additive values.

There seems to be a blue tinge in the opengl no fog screenshot which is not present on the dx no fog screenshot. Are you drawing the background the same in both?

I would simplify the problem as much as possible and only try and draw certain parts of the scene and compare for differences. i.e. background on it's own, geometry on it's own, geometry and background, fog on it's own etc.

There may also be default settings for the driver which are different in dx and opengl. In my nvidia setup you can adjust the defaults for each application, including things like mip map quality etc. Although I am not sure this is causing the difference you are seeing here.

Other than that it does kind of look like the opengl is using a 'better quality' version of the fog, either the dx is using a lower mipmap, or the dx version of the fog texture looks almost like a dxt compressed version versus an uncompressed version in the opengl (some premultiplied alpha thing I dunno?). Or something in the blending mode as the others are suggesting.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.