Sign in to follow this  
jonathon99

OpenGL Problem between OpenGL and DirectX renderings

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
[url="http://www.moonlightminions.com/problem/nofog.jpg"][img]http://www.moonlightminions.com/problem/nofog_sm.jpg[/img][/url] [url="http://www.moonlightminions.com/problem/fog.jpg"][img]http://www.moonlightminions.com/problem/fog_sm.jpg[/img][/url]

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]
[size=2]Device->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);[/size]
[size=2]Device->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);[/size]
[size=2]Device->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);[/size]

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

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

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

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

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

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

[size=2][size=2][size=2][size=2][size=2][size=2][size=2]//OpenGL Z Function[/size][/size][/size][/size][/size][/size][/size]
[size=2][size=2][size=2][size=2][size=2][size=2][size=2][size=2]glDepthFunc(GL_LEQUAL); [/size][/size][/size][/size][/size][/size][/size][/size] Edited by jonathon99

Share this post


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

[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.[/size]

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 );
[/quote]
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
[quote name='Arkhyl' timestamp='1341134366' post='4954468']
[quote name='jonathon99' timestamp='1341098916' post='4954398']
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );
[/quote]
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

[quote name='mhagain' timestamp='1341141498' post='4954494']
Also this is going to reduce the effectiveness of your mipmapping:[code]glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);[/code]
[/quote]

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
[quote name='jonathon99' timestamp='1341174720' post='4954644']
The textures look extremely blurry when I take out that line of code.
[/quote]
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
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.

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Partner Spotlight

  • Forum Statistics

    • Total Topics
      627636
    • Total Posts
      2978331
  • Similar Content

    • By xhcao
      Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness. 
    • By cebugdev
      hi guys, 
      are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
      Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic 
      let me know if you guys have recommendations.
      Thank you in advance!
    • By dud3
      How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below? 
      Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
      Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.
       
      References:
      Code: https://pastebin.com/Hcshj3FQ
      The video shows the difference between blender and my rotation:
       
    • By Defend
      I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
      My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
      * make lots of VAO/VBO pairs and flip through them to render different objects, or
      * make one big VBO and jump around its memory to render different objects. 
      I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
      If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?
       
    • By test opty
      Hello all,
       
      On my Windows 7 x64 machine I wrote the code below on VS 2017 and ran it.
      #include <glad/glad.h>  #include <GLFW/glfw3.h> #include <std_lib_facilities_4.h> using namespace std; void framebuffer_size_callback(GLFWwindow* window , int width, int height) {     glViewport(0, 0, width, height); } //****************************** void processInput(GLFWwindow* window) {     if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)         glfwSetWindowShouldClose(window, true); } //********************************* int main() {     glfwInit();     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);     //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);     GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);     if (window == nullptr)     {         cout << "Failed to create GLFW window" << endl;         glfwTerminate();         return -1;     }     glfwMakeContextCurrent(window);     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))     {         cout << "Failed to initialize GLAD" << endl;         return -1;     }     glViewport(0, 0, 600, 480);     glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);     glClearColor(0.2f, 0.3f, 0.3f, 1.0f);     glClear(GL_COLOR_BUFFER_BIT);     while (!glfwWindowShouldClose(window))     {         processInput(window);         glfwSwapBuffers(window);         glfwPollEvents();     }     glfwTerminate();     return 0; }  
      The result should be a fixed dark green-blueish color as the end of here. But the color of my window turns from black to green-blueish repeatedly in high speed! I thought it might be a problem with my Graphics card driver but I've updated it and it's: NVIDIA GeForce GTX 750 Ti.
      What is the problem and how to solve it please?
  • Popular Now