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
gl_misc.cpp File Reference
#include <string.h>
#include "gl_globals.h"
#include "vegastrike.h"
#include "gfxlib.h"
#include "vs_globals.h"
#include "gl_light.h"
#include "config_xml.h"
#include "winsys.h"

Go to the source code of this file.

Macros

#define GL_MISC_CPP
 

Functions

bool GFXMultiTexAvailable ()
 
void GFXCircle (float x, float y, float wid, float hei)
 
void GFXBeginScene ()
 resets all local lights and sets identity matrix More...
 
void GFXEndScene ()
 Flushes and Swaps buffers. More...
 
void GFXClear (const GFXBOOL colorbuffer, const GFXBOOL depthbuffer, const GFXBOOL stencilbuffer)
 Clears the Z buffer. Also clears color buffer if GFXTRUE passed in. More...
 
GFXBOOL GFXCapture (char *filename)
 Screen capture (FIXME) More...
 
void GFXGetPolygonOffset (float *factor, float *units)
 
void GFXPolygonOffset (float factor, float units)
 Sets Depth Offset for polgyons. More...
 
void GFXPolygonMode (const enum POLYMODE polymode)
 Sets the polygon rasterization mode. More...
 
void GFXCullFace (const enum POLYFACE polyface)
 Sets the facecull mode. More...
 
void GFXPointSize (const float size)
 Sets the size in pixels of a GFXPOINT. More...
 
void GFXLineWidth (const float size)
 Sets the line width in pixels of a GFXLINE. More...
 
void GFXBegin (const enum POLYTYPE ptype)
 Begins a polytype. More...
 
void GFXColorf (const GFXColor &col)
 Specifies a color for henceforth drawn vertices to share. More...
 
GFXColor GFXColorf ()
 Gets the current color. More...
 
void GFXColor4f (const float r, const float g, const float b, const float a)
 Specifies a color for henceforth drawn vertices to share. More...
 
void GFXTexCoord2f (const float s, const float t)
 Specifies a pair of texture coordinates for given vertex. More...
 
void GFXTexCoord4f (const float s, const float t, const float u, const float v)
 Specifies four texture coordinates for a given vertex (2 textures) More...
 
void GFXTexCoord224f (const float s, const float t, const float s2, const float t2, const float s3, const float t3, const float u3, const float v3)
 Specifies four texture coordinates for a given vertex (3 textures) More...
 
void GFXNormal3f (const float i, const float j, const float k)
 Specifies a normal with 3 floats. More...
 
void GFXNormal (const Vector &n)
 Specifies a notmal with 1 vector. More...
 
void GFXVertex3f (const float x, const float y, const float z)
 Specifies a vertex with 3 floats. More...
 
void GFXVertex3f (const double x, const double y, const double z)
 
void GFXVertex3d (const double x, const double y, const double z)
 
void GFXVertexf (const Vector &v)
 Specifies a vertex with a vector. More...
 
void GFXVertexf (const QVector &v)
 
void GFXEnd ()
 Ends the current set of polytypes. More...
 
int GFXCreateList ()
 Creates a Display list. 0 is returned if no memory is avail for a display list. More...
 
GFXBOOL GFXEndList ()
 Ends the display list call. Returns false if unsuccessful. More...
 
void GFXCallList (int list)
 Draws a given display list. More...
 
void GFXDeleteList (int list)
 Removes a display list from application memory. More...
 
void GFXSubwindow (int x, int y, int xsize, int ysize)
 Creates a subwindow with the current parameters for center and size. More...
 
void GFXSubwindow (float x, float y, float xsize, float ysize)
 
Vector GFXDeviceToEye (int x, int y)
 convertes eyespace to 3space at the near plane More...
 

Variables

static float last_factor = 0
 
static float last_units = 0
 

Macro Definition Documentation

#define GL_MISC_CPP

Definition at line 22 of file gl_misc.cpp.

Function Documentation

void GFXBegin ( const enum POLYTYPE  ptype)

Begins a polytype.

Definition at line 152 of file gl_misc.cpp.

References GFXLINE, GFXLINESTRIP, GFXPOINT, GFXPOLY, GFXQUAD, GFXQUADSTRIP, GFXTRI, GFXTRIFAN, and GFXTRISTRIP.

Referenced by AnimationDraw(), ParticlePoint::Draw(), GuiTexture::draw(), Background::Draw(), VSSprite::Draw(), BaseInterface::Room::BaseText::Draw(), BaseInterface::Room::Draw(), ParticleTrail::DrawAndUpdate(), Animation::DrawAsVSSprite(), Radar::SphereDisplay::DrawBackground(), Radar::BubbleDisplay::DrawBackground(), NavigationSystem::DrawButtonOutline(), NavigationSystem::DrawCircle(), DrawCrosshairs(), NavigationSystem::DrawCursor(), DrawDamageFlash(), DrawFrustum(), NavigationSystem::DrawGalaxy(), NavigationSystem::DrawGrid(), Radar::PlaneDisplay::DrawGround(), DrawGun(), NavigationSystem::DrawHalfCircleBottom(), NavigationSystem::DrawHalfCircleTop(), DrawHUDSprite(), DrawITTSLine(), DrawITTSMark(), NavigationSystem::DrawJump(), NavigationSystem::DrawMissile(), NavigationSystem::DrawNavCircle(), Animation::DrawNoTransform(), Animation::DrawNow(), DrawOneTargetBox(), NavigationSystem::DrawPlanet(), DrawShield(), DrawSquare(), NavigationSystem::DrawStation(), Radar::PlaneDisplay::DrawTarget(), NavigationSystem::DrawTargetCorners(), Radar::SphereDisplay::DrawTargetMarker(), Radar::BubbleDisplay::DrawTargetMarker(), Radar::PlaneDisplay::DrawTargetMarker(), Radar::SphereDisplay::DrawTrack(), Radar::BubbleDisplay::DrawTrack(), GFXCircle(), and Box::ProcessDrawQueue().

153 {
154  GLenum mode;
155  switch (ptype)
156  {
157  case GFXTRI:
158  mode = GL_TRIANGLES;
159  break;
160  case GFXLINE:
161  mode = GL_LINES;
162  break;
163  case GFXTRISTRIP:
164  mode = GL_TRIANGLE_STRIP;
165  break;
166  case GFXTRIFAN:
167  mode = GL_TRIANGLE_FAN;
168  break;
169  case GFXQUAD:
170  mode = GL_QUADS;
171  break;
172  case GFXQUADSTRIP:
173  mode = GL_QUAD_STRIP;
174  break;
175  case GFXLINESTRIP:
176  mode = GL_LINE_STRIP;
177  break;
178  case GFXPOLY:
179  mode = GL_POLYGON;
180  break;
181  case GFXPOINT:
182  mode = GL_POINTS;
183  break;
184  default:
185  mode = GL_POINTS;
186  assert( 0 ||! "Bad case in gl_misc.cpp." );
187  break;
188  }
189  glBegin( mode );
190 }
void GFXBeginScene ( )

resets all local lights and sets identity matrix

Definition at line 54 of file gl_misc.cpp.

References GFXLoadIdentity(), light_rekey_frame(), and MODEL.

Referenced by base_main_loop(), bootstrap_draw(), gamemenu_draw(), nav_main_loop(), GameUniverse::StartDraw(), and GameUniverse::StartGFX().

55 {
56  GFXLoadIdentity( MODEL ); //bad this should instead load the cached view matrix
58 }
void GFXCallList ( int  list)

Draws a given display list.

Definition at line 312 of file gl_misc.cpp.

Referenced by GFXVertexList::Draw().

313 {
314 //VSFileSystem::Fprintf (stderr,"CallListStart");///causes crash with GF2 privaledge instruction on Win2k in certain instances
315 //fflush (stderr);
316  glCallList( list );
317 //VSFileSystem::Fprintf (stderr,"CallListEnd");
318 //fflush (stderr);
319 }
GFXBOOL GFXCapture ( char *  filename)

Screen capture (FIXME)

Definition at line 73 of file gl_misc.cpp.

References GFXFALSE.

74 {
75  return GFXFALSE;
76 }
void GFXCircle ( float  x,
float  y,
float  wid,
float  hei 
)

Definition at line 37 of file gl_misc.cpp.

References UniverseUtil::cos(), f, g_game, VegaConfig::getVariable(), GFXBegin(), GFXEnd(), GFXLINESTRIP, GFXVertex3f(), i, int, M_PI, Magnitude(), XMLSupport::parse_float(), UniverseUtil::sin(), Vector, vs_config, game_data_t::x_resolution, and game_data_t::y_resolution.

Referenced by DrawCrosshairs().

38 {
39  static float aaccuracy = XMLSupport::parse_float( vs_config->getVariable( "graphics", "circle_accuracy", "0.1" ) );
40  float segmag =
41  ( Vector( wid*g_game.x_resolution, 0,
42  0 )
43  -Vector( wid*g_game.x_resolution*cos( 2.*M_PI/360.0 ), hei*g_game.y_resolution*sin( 2.*M_PI/360.0 ), 0 ) ).Magnitude();
44  int accuracy = (int) ( 360.0f*aaccuracy*(1.0f < segmag ? 1.0 : segmag) );
45  if (accuracy < 4) accuracy = 4;
46  //const int accuracy=((wid*g_game.x_resolution)+(hei*g_game.y_resolution))*M_PI;
48  float iaccuracy = 1.0f/accuracy;
49  for (int i = 0; i <= accuracy; i++)
50  GFXVertex3f( x+wid*cos( i*2.*M_PI*iaccuracy ), y+hei*sin( i*2.*M_PI*iaccuracy ), 0 );
51  GFXEnd();
52 }
void GFXClear ( const GFXBOOL  colorbuffer,
const GFXBOOL  depthbuffer,
const GFXBOOL  stencilbuffer 
)

Clears the Z buffer. Also clears color buffer if GFXTRUE passed in.

Definition at line 66 of file gl_misc.cpp.

Referenced by bootstrap_draw(), Background::Draw(), WindowManager::draw(), GameCockpit::Draw(), BaseInterface::Room::BaseShip::Draw(), Mesh::ProcessUndrawnMeshes(), Mesh::ProcessZFarMeshes(), Briefing::Render(), and StartGUIFrame().

67 {
68  glClear( (colorbuffer ? GL_COLOR_BUFFER_BIT : 0)
69  |(depthbuffer ? GL_DEPTH_BUFFER_BIT : 0)
70  |(stencilbuffer ? GL_STENCIL_BUFFER_BIT : 0) );
71 }
void GFXColor4f ( const float  r,
const float  g,
const float  b,
const float  a 
)
GFXColor GFXColorf ( )

Gets the current color.

Definition at line 197 of file gl_misc.cpp.

198 {
199  float col[4];
200  glGetFloatv( GL_CURRENT_COLOR, col ); //It's best this way, we don't use it much, anyway.
201  return GFXColor( col[0], col[1], col[2], col[3] );
202 }
int GFXCreateList ( )

Creates a Display list. 0 is returned if no memory is avail for a display list.

Definition at line 298 of file gl_misc.cpp.

Referenced by CreateLists(), and GFXVertexList::RefreshDisplayList().

299 {
300  glGetError();
301  int list = glGenLists( 1 );
302  glNewList( list, GL_COMPILE );
303  return list;
304 }
void GFXCullFace ( const enum POLYFACE  polyface)

Sets the facecull mode.

Definition at line 123 of file gl_misc.cpp.

References GFXBACK, GFXFRONT, and GFXFRONTANDBACK.

Referenced by setupGLState().

124 {
125  GLenum face;
126  switch (polyface)
127  {
128  case GFXFRONT:
129  face = GL_FRONT;
130  break;
131  default:
132  case GFXBACK:
133  face = GL_BACK;
134  break;
135  case GFXFRONTANDBACK:
136  face = GL_FRONT_AND_BACK;
137  break;
138  }
139  glCullFace( face );
140 }
void GFXDeleteList ( int  list)

Removes a display list from application memory.

Definition at line 321 of file gl_misc.cpp.

Referenced by GFXVertexList::RefreshDisplayList(), and GFXVertexList::~GFXVertexList().

322 {
323  if ( glIsList( list ) )
324  glDeleteLists( list, 1 );
325 }
Vector GFXDeviceToEye ( int  x,
int  y 
)

convertes eyespace to 3space at the near plane

Definition at line 343 of file gl_misc.cpp.

References b, f, g_game, GFXGetFrustumVars(), Vector, game_data_t::x_resolution, and game_data_t::y_resolution.

Referenced by MouseCoordinate().

344 {
345  float l, r, b, t, n, f;
346  GFXGetFrustumVars( true, &l, &r, &b, &t, &n, &f );
347  return Vector( (l+(r-l)*float(x)/g_game.x_resolution),
348  (t+(b-t)*float(y)/g_game.y_resolution),
349  n );
350 }
GFXBOOL GFXEndList ( )

Ends the display list call. Returns false if unsuccessful.

Definition at line 306 of file gl_misc.cpp.

Referenced by CreateLists(), and GFXVertexList::RefreshDisplayList().

307 {
308  glEndList();
309  return glGetError() != GL_OUT_OF_MEMORY;
310 }
void GFXEndScene ( )

Flushes and Swaps buffers.

Definition at line 60 of file gl_misc.cpp.

References winsys_swap_buffers().

Referenced by base_main_loop(), bootstrap_draw(), gamemenu_draw(), nav_main_loop(), GameUniverse::StartDraw(), and GameUniverse::StartGFX().

61 {
62  glFlush();
63  winsys_swap_buffers(); //swap the buffers
64 }
void GFXGetPolygonOffset ( float factor,
float units 
)

Definition at line 81 of file gl_misc.cpp.

References last_factor, and last_units.

Referenced by SetupSpecMapFirstPass().

82 {
83  *factor = last_factor;
84  *units = last_units;
85 }
bool GFXMultiTexAvailable ( )

Definition at line 32 of file gl_misc.cpp.

References gl_options, and gl_options_t::Multitexture.

33 {
34  return gl_options.Multitexture != 0;
35 }
void GFXNormal ( const Vector n)

Specifies a notmal with 1 vector.

Definition at line 263 of file gl_misc.cpp.

264 {
265  glNormal3fv( &n.i );
266 }
void GFXNormal3f ( const float  i,
const float  j,
const float  k 
)

Specifies a normal with 3 floats.

Definition at line 258 of file gl_misc.cpp.

259 {
260  glNormal3f( i, j, k );
261 }
void GFXPointSize ( const float  size)
void GFXPolygonMode ( const enum POLYMODE  polymode)

Sets the polygon rasterization mode.

Definition at line 104 of file gl_misc.cpp.

References GFXFILLMODE, GFXLINEMODE, and GFXPOINTMODE.

Referenced by setupGLState().

105 {
106  GLenum mode;
107  switch (polymode)
108  {
109  default:
110  case GFXFILLMODE:
111  mode = GL_FILL;
112  break;
113  case GFXLINEMODE:
114  mode = GL_LINE;
115  break;
116  case GFXPOINTMODE:
117  mode = GL_POINT;
118  break;
119  }
120  glPolygonMode( GL_FRONT_AND_BACK, mode );
121 }
void GFXPolygonOffset ( float  factor,
float  units 
)

Sets Depth Offset for polgyons.

Definition at line 87 of file gl_misc.cpp.

References last_factor, and last_units.

Referenced by Logo::ProcessDrawQueue(), SphereMesh::ProcessDrawQueue(), CityLights::ProcessDrawQueue(), quadsquare::Render(), setupGLState(), and SetupSpecMapFirstPass().

88 {
89  last_factor = factor;
90  last_units = units;
91  if (!factor && !units) {
92  glDisable( GL_POLYGON_OFFSET_FILL );
93  glDisable( GL_POLYGON_OFFSET_POINT );
94  glDisable( GL_POLYGON_OFFSET_LINE );
95  glPolygonOffset( 0, 0 );
96  } else {
97  glPolygonOffset( factor, units );
98  glEnable( GL_POLYGON_OFFSET_FILL );
99  glEnable( GL_POLYGON_OFFSET_POINT );
100  glEnable( GL_POLYGON_OFFSET_LINE );
101  }
102 }
void GFXSubwindow ( int  x,
int  y,
int  xsize,
int  ysize 
)

Creates a subwindow with the current parameters for center and size.

Definition at line 327 of file gl_misc.cpp.

References g_game, game_data_t::x_resolution, and game_data_t::y_resolution.

Referenced by GFXSubwindow(), Camera::RestoreViewPort(), and Camera::UpdateGFX().

328 {
329  glViewport( x, y, xsize, ysize );
330  glScissor( x, y, xsize, ysize );
331  if (x == 0 && y == 0 && xsize == g_game.x_resolution && ysize == g_game.y_resolution)
332  glDisable( GL_SCISSOR_TEST );
333  else
334  glEnable( GL_SCISSOR_TEST );
335 }
void GFXSubwindow ( float  x,
float  y,
float  xsize,
float  ysize 
)

Definition at line 337 of file gl_misc.cpp.

References g_game, GFXSubwindow(), game_data_t::x_resolution, and game_data_t::y_resolution.

338 {
340  int(ysize*g_game.y_resolution) );
341 }
void GFXTexCoord224f ( const float  s,
const float  t,
const float  s2,
const float  t2,
const float  s3,
const float  t3,
const float  u3,
const float  v3 
)

Specifies four texture coordinates for a given vertex (3 textures)

Definition at line 237 of file gl_misc.cpp.

References gl_options, glMultiTexCoord2fARB_p, glMultiTexCoord4fARB_p, and gl_options_t::Multitexture.

Referenced by GFXVertexList::RefreshDisplayList().

245 {
246 #if !defined (IRIX)
247  if (gl_options.Multitexture) {
248  glMultiTexCoord2fARB_p( GL_TEXTURE0_ARB, s, t );
249  glMultiTexCoord2fARB_p( GL_TEXTURE1_ARB, s2, t2 );
250  glMultiTexCoord4fARB_p( GL_TEXTURE2_ARB, s3, t3, u3, v3 );
251  } else
252 #endif
253  {
254  glTexCoord2f( s, t );
255  }
256 }
void GFXTexCoord2f ( const float  s,
const float  t 
)

Specifies a pair of texture coordinates for given vertex.

Definition at line 219 of file gl_misc.cpp.

Referenced by AnimationDraw(), ParticlePoint::Draw(), GuiTexture::draw(), VSSprite::Draw(), Animation::DrawAsVSSprite(), DrawDamageFlash(), DrawHUDSprite(), Animation::DrawNoTransform(), and Animation::DrawNow().

220 {
221  glTexCoord2f( s, t );
222 }
void GFXTexCoord4f ( const float  s,
const float  t,
const float  u,
const float  v 
)

Specifies four texture coordinates for a given vertex (2 textures)

Definition at line 224 of file gl_misc.cpp.

References gl_options, glMultiTexCoord2fARB_p, and gl_options_t::Multitexture.

Referenced by VSSprite::Draw(), Animation::DrawAsVSSprite(), Animation::DrawNoTransform(), and Animation::DrawNow().

225 {
226 #if !defined (IRIX)
227  if (gl_options.Multitexture) {
228  glMultiTexCoord2fARB_p( GL_TEXTURE0_ARB, s, t );
229  glMultiTexCoord2fARB_p( GL_TEXTURE1_ARB, u, v );
230  } else
231 #endif
232  {
233  glTexCoord2f( s, t );
234  }
235 }
void GFXVertex3d ( const double  x,
const double  y,
const double  z 
)

Definition at line 278 of file gl_misc.cpp.

Referenced by ParticlePoint::Draw(), DrawGun(), and DrawShield().

279 {
280  glVertex3d( x, y, z );
281 }
void GFXVertex3f ( const double  x,
const double  y,
const double  z 
)

Definition at line 273 of file gl_misc.cpp.

274 {
275  glVertex3d( x, y, z );
276 }
void GFXVertexf ( const QVector v)

Definition at line 288 of file gl_misc.cpp.

289 {
290  glVertex3d( v.i, v.j, v.k );
291 }

Variable Documentation

float last_factor = 0
static

Definition at line 78 of file gl_misc.cpp.

Referenced by GFXGetPolygonOffset(), and GFXPolygonOffset().

float last_units = 0
static

Definition at line 79 of file gl_misc.cpp.

Referenced by GFXGetPolygonOffset(), and GFXPolygonOffset().