-2

My issue is that apparently the normal's of the objects in my OpenGL scene, have inexplicably flipped. Here are some pictures to aid in my explanation.

First screenshot:
enter image description here

Second screenshot:
enter image description here

Is the problem with my code( Which it should not be because I did not change anything there), or is it just something like a graphics card glitch? And if it is my graphics card that was the issue, what can be done to fix it?

Side note, it was working fine before I upgraded my graphics card driver

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • It's probably not the graphics card driver. Note that your z-buffer with depth-test is also not working. This must be in your code. Or you forgot to specify the winding. – Martijn Courteaux Jan 08 '15 at 23:11
  • Question: Are those two screenshots both supposed to be broke, or is the first one the desired output? – BWG Jan 08 '15 at 23:14

1 Answers1

0

Your problem is that you are drawing both sides (inside and outside) of the cube without using a depth test. There are two ways to fix this. Typically, you will enable both because they solve different problems, but either technique will solve your problem in this particular case.

  1. Enable the depth test: glEnable(GL_DEPTH_TEST). This will make it so that the parts of the cube that are in front get drawn over the parts in back, but not vice versa.

  2. Enable backface culling: glEnable(GL_CULL_FACE). This will make it so that the outside of the cube is drawn but not the inside. Note that you will have to make sure that all of your triangles are facing the correct direction in order for this to work correctly. Also note that this is only a complete solution because your model is convex.

Dietrich Epp
  • 205,541
  • 37
  • 345
  • 415
  • Well, enabling `GL_CULL_FACE` is pretty much exclusively used as an optimization. If your mesh is set up correctly (which OP's appears NOT to be), then you won't usually see any difference with it enabled or disabled. – BWG Jan 08 '15 at 23:16
  • @BWG: How would setting up the mesh differently change anything, assuming face culling is disabled? (Yes, face culling is usually an optimization. However, for convex models, it can be used instead of the depth test.) – Dietrich Epp Jan 08 '15 at 23:17
  • Lighting due to the normals. I think your answer is a little misleading, beacuse culling face doesn't solve the occlusion problem unless the geometry is SUPER simple. – BWG Jan 08 '15 at 23:19
  • @BWG: I'm not sure there is a problem with the normals. It looks to me like the only problem is that the inside of the cube is being drawn over the outside. I mentioned both solutions for completeness, but I've added the caveat. – Dietrich Epp Jan 08 '15 at 23:21
  • @DietrichEpp That did not fix it. I tested my game engine on another computer and it seemed to work fine. The computer I am building my game engine on is a newer computer, is there something I need to add to my game engine to work properly on newer graphics cards? – Electric Fountain Co Jan 09 '15 at 18:56
  • It's probably a bug in your engine. You might have to post some source code, if you've already enabled the depth test and culling, and your triangles are facing the right way. – Dietrich Epp Jan 09 '15 at 19:01