15. OpenGL Fog Types
In this openg tutorial I will show you the different types of opengl fog
that you can use within your opengl program, they are GL_EXP, GL_EXP2 and GL_LINEAR. You would use a different fog type depending on how you would like the current part of your opengl application to look. It is more a trial and error thing, to choose which opengl fog type you want. But when you get to know them well, you should be able to visualise the way it will look inside your opengl application.
In this tutorial I will be expanding upon the previous fog tutorial.
Now in the last one, you will have seen that I used the fog type
GL_EXP2
Now this is not the only one. I only chose it because I think
that it looks best.
The others include:
GL_EXP
and
GL_LINEAR
So there are 3 in total.
In this project I have given you the option of viewing them all
by pressing a, s and d.
Now with our fogHint. We have 3 options once again.
They are:
GL_NICEST
GL_FASTEST
and
GL_DONT_CARE
Nicest makes it look better.
Fastest makes it look worse, but run better.
And
Don’t care sets it to either (I believe it depends on the hardware).
Now we are going to take a look at the start and ending positions for the fog.
We set the fog starting position with:
glFogf (GL_FOG_START, 1);
This sets how far into the screen the fog will start.
Then the fog ending position is set with
glFogf (GL_FOG_END, 10);
This will set how far into the screen the fog will end.
And that is all there is to it.
If you have any questions please email me at swiftless@gmail.com
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. |
#include <GL/gl.h> #include <GL/glut.h> GLfloat angle = 0.0; GLfloat density = 0.3; void cube (void) { void init (void) { void display (void) { void reshape (int w, int h) { void keyboard (unsigned char key, int x, int y) { int main (int argc, char **argv) {
|
GL_DONT_CARE is the initial value for each target. Practically, it means no preferences.
Hi, great job with all the tutorials Swiftless. I’ve been reading through all the tutorials before this and wanted to suggest that you include pictures to show the differences
between different light settings and/or fog settings. I actually havent been using C/C++ to program with OpenGL, I’m using JOGL (Java bindings to OpenGL), and everything in your tutorials are helping me! 🙂 Just that I have to set up a window and other similar things without using GLUT. Perhaps you can add further tutorials on some of the things in JOGL that differ from OpenGL. Two things off the top of head would include double-buffering and fullscreen antialiasing. But anyways, keep up the great work, and I’ll be looking through the rest of the tutorials!
This post explains what options OpenGL gives, but not what these options are, what fog model they represent.
Here is some more on how fog affects final color and what calculus is behind GL_EXP, GL_EXP2 and GL_LINEAR: http://www.opengl.org/resources/code/samples/advanced/advanced97/notes/node122.html
hi,
tutorial is very simple and easy, however I put the fog start and end lines with a limit between 2 and -2 , i was expecting some part of cube in the fog but it didnt change anything, i put these lines in the init() functoin just after glEnable(GL_FOG);