| 1 | package SDL::Tutorial::3DWorld::Fog; | ||
| 2 | |||
| 3 | # A small convenience encapsulation for basic OpenGL fog | ||
| 4 | |||
| 5 | use 5.008; | ||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | use SDL::Tutorial::3DWorld::OpenGL (); | ||
| 9 | |||
| 10 | our $VERSION = '0.33'; | ||
| 11 | |||
| 12 | |||
| 13 | |||
| 14 | |||
| 15 | |||
| 16 | ###################################################################### | ||
| 17 | # Constructor and Accessors | ||
| 18 | |||
| 19 | sub new { | ||
| 20 | my $class = shift; | ||
| 21 | my $self = bless { | ||
| 22 | |||
| 23 | # Defaults to match the OpenGL spec | ||
| 24 | mode => OpenGL::GL_LINEAR, | ||
| 25 | density => 1, | ||
| 26 | start => 0, | ||
| 27 | end => 1, | ||
| 28 | color => [ 0.0, 0.0, 0.0, 0.0 ], | ||
| 29 | coord_src => OpenGL::GL_FRAGMENT_DEPTH, | ||
| 30 | |||
| 31 | @_, | ||
| 32 | }, $class; | ||
| 33 | return $self; | ||
| 34 | } | ||
| 35 | |||
| 36 | |||
| 37 | |||
| 38 | |||
| 39 | |||
| 40 | ###################################################################### | ||
| 41 | # Engine Methods | ||
| 42 | |||
| 43 | sub init { | ||
| 44 | return 1; | ||
| 45 | } | ||
| 46 | |||
| 47 | sub enable { | ||
| 48 | my $self = shift; | ||
| 49 | |||
| 50 | # Apply all fog settings | ||
| 51 | OpenGL::glFogi( OpenGL::GL_FOG_MODE, $self->{mode} ); | ||
| 52 | OpenGL::glFogi( OpenGL::GL_FOG_COORD_SRC, $self->{coord_src} ); | ||
| 53 | OpenGL::glFogf( OpenGL::GL_FOG_DENSITY, $self->{density} ); | ||
| 54 | OpenGL::glFogf( OpenGL::GL_FOG_START, $self->{start} ); | ||
| 55 | OpenGL::glFogf( OpenGL::GL_FOG_END, $self->{end} ); | ||
| 56 | OpenGL::glFogfv_p( OpenGL::GL_FOG_COLOR, @{$self->{color}} ); | ||
| 57 | |||
| 58 | OpenGL::glEnable( OpenGL::GL_FOG ); | ||
| 59 | } | ||
| 60 | |||
| 61 | sub disable { | ||
| 62 | OpenGL::glDisable( OpenGL::GL_FOG ); | ||
| 63 | } | ||
| 64 | |||
| 65 | 1; |