/
skybox.cc
81 lines (58 loc) · 1.87 KB
/
skybox.cc
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
74
75
76
77
78
79
80
81
#include "skybox.h"
#include "simulation.h"
#include "glIncludes.h"
#include "camera.h"
#include "render.h"
slSkybox::slSkybox() {
_loaded = false;
}
slSkybox::~slSkybox() {
}
int slSkybox::loadImage( std::string &inPath, int inN ) {
int result = _textures[ inN ].loadImage( inPath, false );
// check and update the _loaded state
_loaded = true;
for( int n = 0; n < 6; n++ ) {
if( !_textures[ n ].isLoaded() )
_loaded = false;
}
return result;
}
void slSkybox::draw( slRenderGL& inRenderer, slCamera *inCamera ) {
if( ! _loaded )
return;
slVector position;
slVectorAdd( &inCamera -> _location, &inCamera -> _target, &position );
glDepthMask( GL_FALSE );
inRenderer.PushMatrix( slMatrixGeometry );
inRenderer.Translate( slMatrixGeometry, position.x, position.y, position.z );
inRenderer.Scale( slMatrixGeometry, 0.3f * inCamera -> _zClip, 0.3f * inCamera -> _zClip, 0.3f * inCamera -> _zClip );
// we go a little past the edge of the cube to ensure no gaps...
float r = 1.005f;
float f[] = { 1, 1, 1, 1 };
inRenderer.SetBlendColor( f );
slVector c, x, y;
slVectorSet( &c, 0, 0, -1 );
slVectorSet( &x, -r, 0, 0 );
slVectorSet( &y, 0, r, 0 );
inRenderer.DrawQuad( _textures[ 0 ], c, x, y );
slVectorSet( &c, 0, 0, 1 );
slVectorSet( &x, r, 0, 0 );
inRenderer.DrawQuad( _textures[ 1 ], c, x, y );
slVectorSet( &c, 1, 0, 0 );
slVectorSet( &x, 0, 0, -r );
slVectorSet( &y, 0, r, 0 );
inRenderer.DrawQuad( _textures[ 2 ], c, x, y );
slVectorSet( &c, -1, 0, 0 );
slVectorSet( &x, 0, 0, r );
inRenderer.DrawQuad( _textures[ 3 ], c, x, y );
slVectorSet( &c, 0, 1, 0 );
slVectorSet( &x, 0, 0, -r );
slVectorSet( &y, -r, 0, 0 );
inRenderer.DrawQuad( _textures[ 4 ], c, x, y );
slVectorSet( &c, 0, -1, 0 );
slVectorSet( &x, 0, 0, r );
inRenderer.DrawQuad( _textures[ 5 ], c, x, y );
inRenderer.PopMatrix( slMatrixGeometry );
glDepthMask( GL_TRUE );
}