Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Painful Rendering Problem ._.

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    3

    Unhappy Painful Rendering Problem ._.

    I've been having this odd rendering issue here:
    Click image for larger version. 

Name:	ofuq.jpg 
Views:	31 
Size:	7.5 KB 
ID:	2579
    I am not sure what the problem is, because all those missing tris you can see are easily visible depending on the viewing conditions:
    Click image for larger version. 

Name:	wot.jpg 
Views:	35 
Size:	8.3 KB 
ID:	2580
    Since I'm relatively new to opengl, I cannot diagnose whether this is the result of me missing a simple function call or some larger issue.

    Thank you for reading. Any help or input would be appreciated.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,828
    My first guess would be that it's related to depth testing. Check that the near plane (in gluPerspective, glFrustum, etc) isn't too close, as that dictates the accuracy of the depth buffer.

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,394
    As a test, try glDisable( GL_CULL_FACE ). As part of that test, disable lighting and just render triangles with a constant color (easiest).

    It looks like like you might have GL_CULL_FACE on "and" you are rendering triangles with an inconsistent winding order (assuming your meshes are not just wholesale "missing" triangles). This means that some of them which should be front-facing are correctly "front-facing", but the rest which "should" be front-facing are actually "back facing". Disabling GL_CULL_FACE basically says to the GPU: I don't care; just render them all regardless. This isn't the best fix (results in more fill), but it'll at least let you see if this is your problem. The better fix to this is to leave GL_CULL_FACE enabled and just fix the winding order of the triangle vertices in your mesh. Here's a wiki page on this: Face Culling (OpenGL Wiki).

    Failing that, is it possible that your depth buffer has some left-over trash in it from some previous render? That's unlikely to be it though. Make sure you are calling glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) at the beginning of your frame.

    Also verify that you have both depth test and depth writes enabled for both shapes. And that you do have a depth buffer allocated to your render target (it appears that you do).

    You might also try drawing just one of these shapes without the other. Could give you some clues.

    Though my best guess is that the winding order of the tris in the ring is just really messed up. For the ring triangles whose winding order is wrong, those get backface culled away, and you incorrectly "see through" to the cylinder, but elsewhere you don't.
    Last edited by Dark Photon; 12-24-2017 at 12:45 PM.

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    3
    Quote Originally Posted by Dark Photon View Post
    As a test, try glDisable( GL_CULL_FACE ). As part of that test, disable lighting and just render triangles with a constant color (easiest).
    Well the problem with rendering only as a solid color is that the only detail you can now make out is the silhouette which doesn't provide much additional insight:
    Click image for larger version. 

Name:	solid.jpg 
Views:	17 
Size:	4.9 KB 
ID:	2581
    Quote Originally Posted by Dark Photon View Post
    It looks like like you might have GL_CULL_FACE on "and" you are rendering triangles with an inconsistent winding order (assuming your meshes are not just wholesale "missing" triangles). This means that some of them which should be front-facing are correctly "front-facing", but the rest which "should" be front-facing are actually "back facing".
    Yeah that's exactly what I thought when I first got this problem, at this point it seems the mesh itself is fine and everything is front facing. I tried both with and without GL_CULL_FACE

    Look, this is GL_CULL_FACE disabled:
    Click image for larger version. 

Name:	nocull.jpg 
Views:	24 
Size:	11.6 KB 
ID:	2582
    And this is enabled:
    Click image for larger version. 

Name:	cull.jpg 
Views:	26 
Size:	7.3 KB 
ID:	2583

    After studying this behavior, looking around the model in all directions, I am pretty sure that triangles on the other side of the cylinder were being rendered AFTER some of the triangles.
    and that culling those overdrawing back triangles result in the image above. It might be a little easier to see in this lower poly example:
    Click image for larger version. 

Name:	lp.jpg 
Views:	22 
Size:	13.0 KB 
ID:	2584

    But the problem is... this is all ONE MESH and the cylinder is overdrawing onto the ring and all of this is done in one render only.
    So is this some kind of depth buffer issue at this point? All I've done with that is to try and enable depth test and depth mask also I'm clearing the depth buffer, but it gives no better results than the last image above.

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,828
    Quote Originally Posted by Kittyous View Post
    So is this some kind of depth buffer issue at this point? All I've done with that is to try and enable depth test and depth mask also I'm clearing the depth buffer, but it gives no better results than the last image above.
    Do you actually have a depth buffer? If you're using GLUT, you need to pass the GLUT_DEPTH flag to glutInitDisplayMode().

    If glEnable(GL_DEPTH_TEST) doesn't have any effect, then you probably don't have a depth buffer (not having a depth buffer automatically disables depth tests; most of the basic mistakes regarding depth testing will at least produce a different result to not having depth tests).

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    3
    Thank all of you guys so much.
    I was using SFML and I just didn't initialize the context's depth buffer properly.
    It probably would've taken me a lot longer to catch that without your help.
    <3

    Unfortunately it was a bit elusive trying to figure out how to set up a context correctly, so let me
    post it here so anyone else with this problem using SFML could maybe find this out easier:

    This is how you correctly open your window and context:
    width = 800;
    height = 800;
    sf::ContextSettings settings;
    settings.depthBits = 24;
    settings.stencilBits = 8;
    settings.antialiasingLevel = 4;
    settings.majorVersion = 3;
    settings.minorVersion = 0;
    window = new sf::Window(sf::VideoMode(width, height, 32), "SFML Window", sf::Style::Default, settings);
    Click image for larger version. 

Name:	cull.jpg 
Views:	27 
Size:	7.4 KB 
ID:	2585
    after you do that and also call glEnable(GL_DEPTH_TEST); before rendering, it should correctly use the context's depth buffer!
    Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •