Jump to content
  • Advertisement
Sign in to follow this  
jonathon99

OpenGL Problem between OpenGL and DirectX renderings

This topic is 2229 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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); Edited by jonathon99

Share this post


Link to post
Share on other sites
Advertisement
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 Edited by L. Spiro

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
Specify higher-quality mipmaps.
::glHint( GL_GENERATE_MIPMAP_HINT, GL_NICEST );

Also, post shaders.


L. Spiro Edited by L. Spiro

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Also this is going to reduce the effectiveness of your mipmapping:glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);

Share this post


Link to post
Share on other sites

[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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!