Depth Sorting
So the tank looked kind of strange didn't it? Never mind, let's sort it out...
OpenGL has the facilities to use Depth Sorting, something that has been unheard of on home PC computers until the arrival of fast processors with plenty of ram on graphic card. Think of it as a large grid that all the objects are placed on, the computer with then look at each horizontal line going through the whole table bit by bit. finally displaying all the objects it found starting from the back to the front. Once again its not hard to do, but can really take its toll on low processor computers.
Back to Depth Sorting. Hopefully it won't slow up things too much. ;)
Go through the INIT function until you find the lines:
glClearDepth(1.0)
glEnable(GL_CULL_FACE)
Insert the following 2 lines of code below the above instructions:
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
All these 2 lines of code do is to enable the depth test and set what sort of algorithm we should use.
Now find the DISPLAY function and change the 'glClear(GL_COLOR_BUFFER_BIT)' instruction to:
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
As you can tell this clears the depth buffer as well as the normal display buffer.
That's it! Try running the demo again - now you should see the tank in all its glory, spinning around its X and Y axis perfectly without any problems with the 3 separate shapes combined.
So the tank looked kind of strange didn't it? Never mind, let's sort it out...
OpenGL has the facilities to use Depth Sorting, something that has been unheard of on home PC computers until the arrival of fast processors with plenty of ram on graphic card. Think of it as a large grid that all the objects are placed on, the computer with then look at each horizontal line going through the whole table bit by bit. finally displaying all the objects it found starting from the back to the front. Once again its not hard to do, but can really take its toll on low processor computers.
Back to Depth Sorting. Hopefully it won't slow up things too much. ;)
Go through the INIT function until you find the lines:
glClearDepth(1.0)
glEnable(GL_CULL_FACE)
Insert the following 2 lines of code below the above instructions:
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
All these 2 lines of code do is to enable the depth test and set what sort of algorithm we should use.
Now find the DISPLAY function and change the 'glClear(GL_COLOR_BUFFER_BIT)' instruction to:
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
As you can tell this clears the depth buffer as well as the normal display buffer.
That's it! Try running the demo again - now you should see the tank in all its glory, spinning around its X and Y axis perfectly without any problems with the 3 separate shapes combined.