Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Background Class Reference

#include <background.h>

Classes

struct  BackgroundClone
 

Public Member Functions

 Background (const char *file, int numstars, float spread, const std::string &starfilename, const GFXColor &color, bool degamma)
 
 ~Background ()
 
void EnableBG (bool)
 
void Draw ()
 
BackgroundClone Cache ()
 

Detailed Description

Definition at line 29 of file background.h.

Constructor & Destructor Documentation

Background::Background ( const char *  file,
int  numstars,
float  spread,
const std::string &  starfilename,
const GFXColor color,
bool  degamma 
)

Definition at line 35 of file background.cpp.

References VegaConfig::getVariable(), GFXTRUE, Texture::LoadSuccess(), VSFileSystem::LookForFile(), MIPMAP, VSFileSystem::Ok, XMLSupport::parse_bool(), XMLSupport::parse_float(), XMLSupport::parse_int(), BaseUtil::Texture(), TEXTURE2D, TEXTURE_2D, VSFileSystem::TextureFile, and vs_config.

36  : Enabled( true )
37  , stars( NULL )
38  , degamma( degamma_ )
39  , color( color_ )
40 {
41  string temp;
42  static string starspritetextures = vs_config->getVariable( "graphics", "far_stars_sprite_texture", "" );
43  static float starspritesize =
44  XMLSupport::parse_float( vs_config->getVariable( "graphics", "far_stars_sprite_size", "2" ) );
45  if (starspritetextures.length() == 0) {
46  stars =
47  new PointStarVlist( numstars, 200 /*spread*/,
49  "use_star_coords",
50  "true" ) ) ? filename : "" );
51  } else {
52  stars =
53  new SpriteStarVlist( numstars, 200 /*spread*/,
55  "use_star_coords",
56  "true" ) ) ? filename : "", starspritetextures,
57  starspritesize );
58  }
59  up = left = down = front = right = back = NULL;
60 
61  SphereBackground = NULL;
62 
63 #ifndef NV_CUBE_MAP
64  static int max_cube_size = XMLSupport::parse_int( vs_config->getVariable( "graphics", "max_cubemap_size", "1024" ) );
65  string suffix = ".image";
66  temp = string( file )+"_up.image";
67  up = new Texture( temp.c_str(), 0, MIPMAP, TEXTURE2D, TEXTURE_2D, GFXTRUE, max_cube_size );
68  if ( !up->LoadSuccess() ) {
69  temp = string( file )+"_up.bmp";
70  delete up;
71  up = new Texture( temp.c_str(), 0, MIPMAP, TEXTURE2D, TEXTURE_2D, GFXTRUE, max_cube_size );
72  if ( up->LoadSuccess() )
73  suffix = ".bmp"; //backwards compatibility
74  }
75  if ( !up->LoadSuccess() ) {
76  temp = string( file )+"_sphere.image";
78  //> Ok means failed to load.
79  temp = string( file )+"_sphere.bmp";
80  suffix = ".bmp"; //backwards compatibility
81  }
82  SphereBackground = new SphereMesh( 20, 8, 8, temp.c_str(), "", NULL, true );
83  //SphereBackground->Pitch(PI*.5);//that's the way prophecy's textures are set up
84  //SphereBackground->SetOrientation(Vector(1,0,0),
85  //Vector(0,0,-1),
86  //Vector(0,1,0));//that's the way prophecy's textures are set up
87  delete up;
88  up = NULL;
89  } else {
90  //up->Clamp();
91  //up->Filter();
92 
93  temp = string( file )+"_left"+suffix;
94  left = new Texture( temp.c_str(), 0, MIPMAP, TEXTURE2D, TEXTURE_2D, GFXTRUE, max_cube_size );
95  //left->Clamp();
96  //left->Filter();
97 
98  temp = string( file )+"_front"+suffix;
99  front = new Texture( temp.c_str(), 0, MIPMAP, TEXTURE2D, TEXTURE_2D, GFXTRUE, max_cube_size );
100  //front->Clamp();
101  //front->Filter();
102 
103  temp = string( file )+"_right"+suffix;
104  right = new Texture( temp.c_str(), 0, MIPMAP, TEXTURE2D, TEXTURE_2D, GFXTRUE, max_cube_size );
105  //right->Clamp();
106  //right->Filter();
107 
108  temp = string( file )+"_back"+suffix;
109  back = new Texture( temp.c_str(), 0, MIPMAP, TEXTURE2D, TEXTURE_2D, GFXTRUE, max_cube_size );
110  //back->Clamp();
111  //back->Filter();
112 
113  temp = string( file )+"_down"+suffix;
114  down = new Texture( temp.c_str(), 0, MIPMAP, TEXTURE2D, TEXTURE_2D, GFXTRUE, max_cube_size );
115  //down->Clamp();
116  //down->Filter();
117  }
118 #endif
119 }
Background::~Background ( )

Definition at line 124 of file background.cpp.

125 {
126 #ifndef NV_CUBE_MAP
127  if (up)
128  delete up;
129  if (left)
130  delete left;
131  if (front)
132  delete front;
133  if (right)
134  delete right;
135  if (back)
136  delete back;
137  if (down)
138  delete down;
139 #endif
140  if (SphereBackground)
141  delete SphereBackground;
142  if (stars)
143  delete stars;
144 }

Member Function Documentation

Background::BackgroundClone Background::Cache ( )

Definition at line 145 of file background.cpp.

References Background::BackgroundClone::backups, Texture::Clone(), i, Mesh::numTextures(), and Mesh::texture().

Referenced by NetClient::Respawn(), and Cockpit::Update().

146 {
147  BackgroundClone ret;
148 #ifndef NV_CUBE_MAP
149  ret.backups[0] = up ? up->Clone() : NULL;
150  ret.backups[1] = down ? down->Clone() : NULL;
151  ret.backups[2] = left ? left->Clone() : NULL;
152  ret.backups[3] = right ? right->Clone() : NULL;
153  ret.backups[4] = front ? front->Clone() : NULL;
154  ret.backups[5] = back ? back->Clone() : NULL;
155  ret.backups[6] = NULL;
156  if (SphereBackground)
157  for (int i = 0; i < 7 && i < SphereBackground->numTextures(); ++i)
158  ret.backups[(i+6)%7] = SphereBackground->texture( i )->Clone();
159 #endif
160  return ret;
161 }
void Background::Draw ( )

Definition at line 174 of file background.cpp.

References _Universe, Universe::AccessCamera(), Universe::activateLightMap(), Texture::boundSizeX, Texture::boundSizeY, CLAMP, CUBEMAP, DEPTHTEST, DEPTHWRITE, StarVlist::DrawAll(), Mesh::DrawNow(), gl_options_t::ext_clamp_to_edge, Camera::GetAngularVelocity(), Universe::getLightMap(), VegaConfig::getVariable(), Camera::GetVelocity(), GFXActiveTexture(), GFXBegin(), GFXBlendMode(), GFXCenterCamera(), GFXClear(), GFXColorf(), GFXDisable(), GFXEnable(), GFXEnd(), GFXFALSE, GFXLoadMatrixModel(), GFXMODULATETEXTURE, GFXQUAD, GFXTextureAddressMode(), GFXTextureCoordGenMode(), GFXTextureEnv(), GFXToggleTexture(), GFXTRUE, gl_options, identity_matrix(), LIGHTING, Texture::MakeActive(), Texture::maxtcoord, Texture::mintcoord, gl_options_t::Multitexture, NO_GEN, Texture::numLayers(), Texture::numPasses(), ONE, XMLSupport::parse_float(), QVector, Texture::SetupPass(), SRCCOLOR, t1(), TEXTURE0, TEXTURE1, VERTEX, vs_config, WRAP, and ZERO.

Referenced by GameStarSystem::Draw().

175 {
176  GFXClear( Enabled ? GFXFALSE : GFXTRUE );
177  if (Enabled) {
178  if (degamma)
180  else
181  GFXBlendMode( ONE, ZERO );
182  GFXDisable( LIGHTING );
185  GFXEnable( TEXTURE0 );
186  GFXDisable( TEXTURE1 );
187  GFXColorf(color);
188  if (SphereBackground) {
189  SphereBackground->DrawNow( FLT_MAX, true );
190  //Mesh::ProcessUndrawnMeshes();//background must be processed...dumb but necessary--otherwise might collide with other mehses
191  } else {
192  GFXCenterCamera( true );
194  //GFXLoadIdentity(MODEL);
195  //GFXTranslate (MODEL,_Universe->AccessCamera()->GetPosition());
196 
197  //GFXTextureWrap(0,GFXCLAMPTEXTURE);
198  //glMatrixMode(GL_MODELVIEW);
199 
200  /***********************?????????
201  * //Matrix oldproject;
202  * //GFXGetMatrix(VIEW, oldproject);
203  * //glPushMatrix();
204  * //gluPerspective (90,1.33,0.01,1500); //set perspective to 78 degree FOV
205  ********************************/
206  //_Universe->AccessCamera()->UpdateGLCenter();
207 
208  static struct skybox_rendering_record
209  {
210  Texture *tex;
211  float vertices[4][3]; //will be *= size
212  char tcoord[4][4]; //S-T-S-T: 0 >= min, 1 => max
213  }
214  skybox_rendering_sequence[6] = {
215 #ifdef NV_CUBE_MAP
216  //For rendering with a single cube map as texture
217 
218  { //up
219  NULL,
220  {
221  {-1, +1, +1}, {-1, +1, -1}, {+1, +1, -1}, {+1, +1, +1}
222  },
223  {
224  {-1, +2, +1, 0}, {-1, +2, -1, 0}, {+1, +2, -1, 0}, {+1, +2, +1, 0}
225  },
226  },
227  { //left
228  NULL,
229  {
230  {-1,+1, -1}, {-1, +1, +1}, {-1, -1, +1}, {-1, -1, -1}
231  },
232  {
233  {-2, +1, -1, 0}, {-2, +1, +1, 0}, {-2, -1, +1, 0}, {-2, -1, -1, 0}
234  },
235  },
236  { //front
237  NULL,
238  {
239  {-1, +1, +1}, {+1, +1, +1}, {+1, -1, +1}, {-1, -1, +1}
240  },
241  {
242  {-1, +1, +2, 0}, {+1, +1, +2, 0}, {+1, -1, +2, 0}, {-1, -1, +2, 0}
243  },
244  },
245  { //right
246  NULL,
247  {
248  {+1, +1, +1}, {+1, +1, -1}, {+1, -1, -1}, {+1, -1, +1}
249  },
250  {
251  {+2, +1, +1, 0}, {+2, +1, -1, 0}, {+2, -1, -1, 0}, {+2, -1, +1, 0}
252  },
253  },
254  { //back
255  NULL,
256  {
257  {+1, +1, -1}, {-1, +1, -1}, {-1, -1, -1}, {+1, -1, -1}
258  },
259  {
260  {+1, +1, -2, 0}, {-1, +1, -2, 0}, {-1, -1, -2, 0}, {+1, -1, -2, 0}
261  },
262  },
263  { //down
264  NULL,
265  {
266  {-1, -1, +1}, {+1, -1, +1}, {+1, -1, -1}, {-1, -1, -1}
267  },
268  {
269  {-1, -2, +1, 0}, {+1, -2, +1, 0}, {+1, -2, -1, 0}, {-1, -2, -1, 0}
270  },
271  }
272 
273 #else
274  //For rendering with multiple 2D texture faces
275 
276  { //up
277  NULL,
278  {
279  {-1, +1, +1}, {-1, +1, -1}, {+1, +1, -1}, {+1, +1, +1}
280  },
281  {
282  {1, 0, 1, 0}, {0, 0, 0, 0}, {0, 1, 0, 1}, {1, 1, 1, 1}
283  }
284  },
285  { //left
286  NULL,
287  {
288  {-1, +1, -1}, {-1, +1, +1}, {-1, -1, +1}, {-1, -1, -1}
289  },
290  {
291  {1, 0, 1, 0}, {0, 0, 0, 0}, {0, 1, 0, 1}, {1, 1, 1, 1}
292  }
293  },
294  { //front
295  NULL,
296  {
297  {-1, +1, +1}, {+1, +1, +1}, {+1, -1, +1}, {-1, -1, +1}
298  },
299  {
300  {1, 0, 1, 0}, {0, 0, 0, 0}, {0, 1, 0, 1}, {1, 1, 1, 1}
301  }
302  },
303  { //right
304  NULL,
305  {
306  {+1, +1, +1}, {+1, +1, -1}, {+1, -1, -1}, {+1, -1, +1}
307  },
308  {
309  {1, 0, 1, 0}, {0, 0, 0, 0}, {0, 1, 0, 1}, {1, 1, 1, 1}
310  }
311  },
312  { //back
313  NULL,
314  {
315  {+1, +1, -1}, {-1, +1, -1}, {-1, -1, -1}, {+1, -1, -1}
316  },
317  {
318  {1, 0, 1, 0}, {0, 0, 0, 0}, {0, 1, 0, 1}, {1, 1, 1, 1}
319  }
320  },
321  { //down
322  NULL,
323  {
324  {-1, -1, +1}, {+1, -1, +1}, {+1, -1, -1}, {-1, -1, -1}
325  },
326  {
327  {1, 0, 1, 0}, {0, 0, 0, 0}, {0, 1, 0, 1}, {1, 1, 1, 1}
328  }
329  }
330 #endif
331  };
332  skybox_rendering_sequence[0].tex = up;
333  skybox_rendering_sequence[1].tex = left;
334  skybox_rendering_sequence[2].tex = front;
335  skybox_rendering_sequence[3].tex = right;
336  skybox_rendering_sequence[4].tex = back;
337  skybox_rendering_sequence[5].tex = down;
338  for (size_t skr = 0; skr < sizeof (skybox_rendering_sequence)/sizeof (skybox_rendering_sequence[0]); skr++) {
339  Texture *tex = skybox_rendering_sequence[skr].tex;
340  int lyr;
341 
342 #ifdef NV_CUBE_MAP
343  if (tex == NULL)
344  tex = _Universe->getLightMap();
345  const int numlayers = 1;
346  const bool multitex = true;
347  const int numpasses = 1;
348  static const float edge_fixup =
349  XMLSupport::parse_float( vs_config->getVariable( "graphics", "background_edge_fixup", "0" ) );
350  const float ms = 0.f, Ms = 1.f-edge_fixup/tex->boundSizeX;
351  const float mt = 0.f, Mt = 1.f-edge_fixup/tex->boundSizeY;
352  const float _stca[] = {-1.f, -Ms, ms, Ms, +1.f}, _ttca[] = {-1.f, -Mt, mt, Mt, +1.f};
353  const float *stca = _stca+2, *ttca = _ttca+2;
354 
355  GFXColorf(color);
356 
358  GFXToggleTexture( true, 0, CUBEMAP );
359 #else
360  int numlayers = tex->numLayers();
361  bool multitex = (numlayers > 1);
362  int numpasses = tex->numPasses();
363  float ms = tex->mintcoord.i, Ms = tex->maxtcoord.i;
364  float mt = tex->mintcoord.j, Mt = tex->maxtcoord.j;
366  ms += 1.0/tex->boundSizeX;
367  Ms -= 1.0/tex->boundSizeX;
368  mt += 1.0/tex->boundSizeY;
369  Mt -= 1.0/tex->boundSizeY;
370  }
371  float stca[] = {ms, Ms}, ttca[] = {mt, Mt};
372 
373  GFXColorf(color);
374  for (lyr = 0; (lyr < gl_options.Multitexture) || (lyr < numlayers); lyr++) {
375  GFXToggleTexture( (lyr < numlayers), lyr );
376  if (lyr < numlayers)
377  GFXTextureCoordGenMode( lyr, NO_GEN, NULL, NULL );
378  }
379 #endif
380  for (int pass = 0; pass < numpasses; pass++)
381  if ( !tex || tex->SetupPass( pass, 0, ONE, ZERO ) ) {
382  if (tex)
383  tex->MakeActive( 0, pass );
384  //GFXActiveTexture(0);
387  GFXTextureCoordGenMode( 0, NO_GEN, NULL, NULL );
388 
389  float s1, t1, s2, t2;
390 
391 #ifdef NV_CUBE_MAP
392  #define VERTEX( i ) \
393  s1 = stca[size_t(skybox_rendering_sequence[skr].tcoord[i][0])]; \
394  t1 = ttca[size_t(skybox_rendering_sequence[skr].tcoord[i][1])]; \
395  s2 = stca[size_t(skybox_rendering_sequence[skr].tcoord[i][2])]; \
396  glTexCoord3f( s1, t1, s2 ); \
397  GFXVertex3f( skybox_rendering_sequence[skr].vertices[i][0]*size, \
398  skybox_rendering_sequence[skr].vertices[i][1]*size, \
399  skybox_rendering_sequence[skr].vertices[i][2]*size );
400 #else
401  #define VERTEX( i ) \
402  s1 = stca[size_t(skybox_rendering_sequence[skr].tcoord[i][0])]; \
403  t1 = ttca[size_t(skybox_rendering_sequence[skr].tcoord[i][1])]; \
404  s2 = stca[size_t(skybox_rendering_sequence[skr].tcoord[i][2])]; \
405  t2 = ttca[size_t(skybox_rendering_sequence[skr].tcoord[i][3])]; \
406  if (!multitex) GFXTexCoord2f( s1, t1 ); \
407  else GFXTexCoord4f( s1, t1, s2, t2 ); \
408  GFXVertex3f( skybox_rendering_sequence[skr].vertices[i][0]*size, \
409  skybox_rendering_sequence[skr].vertices[i][1]*size, \
410  skybox_rendering_sequence[skr].vertices[i][2]*size );
411 #endif
412 
413  GFXBegin( GFXQUAD );
414  VERTEX( 0 );
415  VERTEX( 1 );
416  VERTEX( 2 );
417  VERTEX( 3 );
418  GFXEnd();
419 
420  #undef VERTEX
421  }
422 
423 
424 #ifdef NV_CUBE_MAP
425  GFXToggleTexture( false, 0, CUBEMAP );
426 #else
427  for (lyr = 0; lyr < numlayers; lyr++) {
428  GFXToggleTexture( false, lyr );
429  if (lyr < numlayers) GFXTextureCoordGenMode( lyr, NO_GEN, NULL, NULL );
430  }
431  if (tex)
432  tex->SetupPass( -1, 0, ONE, ZERO );
433 #endif
434  }
435 
436  GFXActiveTexture( 0 );
438  GFXCenterCamera( false );
439  }
440  }
441  //GFXLoadIdentity(MODEL);
442  //GFXTranslate (MODEL,_Universe->AccessCamera()->GetPosition());
443  GFXCenterCamera( true );
444 //GFXEnable(DEPTHWRITE);
445  GFXDisable( TEXTURE0 );
446  GFXDisable( LIGHTING );
447  GFXColor( 1, 1, 1, 1 );
448  GFXDisable( TEXTURE1 );
450  GFXBlendMode( ONE, ONE );
451  static float background_velocity_scale =
452  XMLSupport::parse_float( vs_config->getVariable( "graphics", "background_star_streak_velocity_scale", "0" ) );
453  stars->DrawAll( QVector( 0, 0, 0 ), _Universe->AccessCamera()->GetVelocity().Scale(
454  background_velocity_scale ), _Universe->AccessCamera()->GetAngularVelocity(), true, true );
455  GFXBlendMode( ONE, ZERO );
456  GFXEnable( DEPTHTEST );
458  GFXCenterCamera( false );
459  //_Universe->AccessCamera()->UpdateGFX(false);
460 }
void Background::EnableBG ( bool  tf)

Definition at line 120 of file background.cpp.

Referenced by CockpitKeys::Inside().

121 {
122  Enabled = tf;
123 }

The documentation for this class was generated from the following files: