gfx::GFX Class Reference

Facade for graphics system (OpenGL). More...

#include <gfx_opengl.hh>

List of all members.

Public Types

enum  ePrim {
  ePrim_POINTS = GL_POINTS, ePrim_LINES = GL_LINES, ePrim_LINE_LOOP = GL_LINE_LOOP, ePrim_TRIANGLES = GL_TRIANGLES,
  ePrim_TRIANGLE_STRIP = GL_TRIANGLE_STRIP, ePrim_QUADS = GL_QUADS, ePrim_QUAD_STRIP = GL_QUAD_STRIP, ePrim_POLYGON = GL_POLYGON
}
 For Begin()/End(). More...
enum  ePolygonMode { ePolygonMode_POINT = GL_POINT, ePolygonMode_LINE = GL_LINE, ePolygonMode_FILL = GL_FILL, ePolygonMode_DEFAULT = GL_FILL }
enum  eBlend {
  eBlend_SRC_ALPHA = GL_SRC_ALPHA, eBlend_SRC_COLOR = GL_SRC_COLOR, eBlend_ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA, eBlend_DST_ALPHA = GL_DST_ALPHA,
  eBlend_DST_COLOR = GL_DST_COLOR, eBlend_ONE_MINUS_DST_ALPHA = GL_ONE_MINUS_DST_ALPHA, eBlend_DST_ONE = GL_ONE
}
 Fragment blending. More...
enum  eColorFormat { eColorFormat_RGBA = GL_RGBA, eColorFormat_RGBA8 = GL_RGBA8, eColorFormat_BGRA = GL_BGRA }
 Color formats. More...
enum  eDepthTest { eDepthTest_DISABLE, eDepthTest_ENABLE }
 Depth test. More...
enum  eShadeModel { eShadeModel_FLAT = GL_FLAT, eShadeModel_NORMAL = GL_FLAT, eShadeModel_SMOOTH = GL_SMOOTH }
 Color shading. More...
enum  eAntialias {
  eAntialias_OFF = 0, eAntialias_1 = 1, eAntialias_2 = 2, eAntialias_3 = 3,
  eAntialias_DEFAULT = eAntialias_OFF
}
enum  eKey {
  eKey_ENTER = 0xd, eKey_ESC = 27, eKey_TAB = 0x9, eKey_BACKSPACE = 0x8,
  eKey_DELETE = 0x7f, eKey_CTRL_C = 0x3, eKey_CTRL_P = 0x10, eKey_CTRL_S = 0x13,
  eKey_CTRL_X = 0x18, eKey_CTRL_Z = 0x1a, eKey_1 = 0x31, eKey_PLUS = 0x2b,
  eKey_MINUS = 0x2d, eKey_LEFT = 0x64, eKey_RIGHT = 0x66, eKey_UP = 0x65,
  eKey_DOWN = 0x67, eKey_HOME = 0x6a, eKey_END = 0x6b, eKey_F1 = 0x1,
  eKey_F2 = 0x2, eKey_F3 = 0x3, eKey_F4 = 0x4, eKey_F5 = 0x5,
  eKey_F6 = 0x6, eKey_F7 = 0x7, eKey_F8 = 0x8, eKey_F9 = 0x9,
  eKey_F10 = 0xa, eKey_F11 = 0xb, eKey_F12 = 0xc
}
 Keyboard. More...

Public Member Functions

CLASS_METHOD void Begin (ePrim prim)
CLASS_METHOD void End (void)
CLASS_METHOD void Begin2D (const Rect< int > &rect)
CLASS_METHOD void End2D (void)
CLASS_METHOD void BeginAux (void)
CLASS_METHOD void EndAux (void)
CLASS_METHOD void Vertex (const EyeVertex *v)
CLASS_METHOD void Vertex (const EyeVertex &v)
CLASS_METHOD void Vertex2D (fp x, fp y)
CLASS_METHOD void Normal (const NormalVertex &n)
CLASS_METHOD void Color (const RGBA rgba)
CLASS_METHOD void DrawRect2D (const Rect< int > &rect, const RGBA rgba)
CLASS_METHOD Modes GetModes (void)
CLASS_METHOD void SetModes (const Modes &modes)
CLASS_METHOD void SetPolygonMode (const ePolygonMode polygonMode)
CLASS_METHOD bool EnableDepthMask (const bool enable)
CLASS_METHOD bool EnableDepthTest (const bool enable)
CLASS_METHOD bool EnableTexture2 (const bool enable)
CLASS_METHOD ePrim Polygon2Prim (const uint vertexCnt)
CLASS_METHOD void SetShadeModel (const eShadeModel shade)
CLASS_METHOD void SetLineWidth (const fp lineWidth, const bool lineSmooth=false)
CLASS_METHOD void SetPointSize (const fp pointSize)
CLASS_METHOD void EnableLighting (const bool enable=true)
CLASS_METHOD bool IfLighting (void)
CLASS_METHOD void SetLight (Light &light, const bool enable=true)
CLASS_METHOD void SetMaterial (Material &material)
CLASS_METHOD void IdentityTextureMatrix (void)
CLASS_METHOD void SetTextureMatrix (const Matrix &m)
CLASS_METHOD void SetTextureMatrix (const fp[16])
CLASS_METHOD void GetTextureMatrix (fp[16])
CLASS_METHOD void TranslateTextureMatrix (fp x, fp y, fp z)
CLASS_METHOD void RotateTextureMatrix (const Degree deg, fp x, fp y, fp z)
CLASS_METHOD void EnableTranslucent (void)
CLASS_METHOD void DisableTranslucent (void)
CLASS_METHOD void EnableBlend (const eBlend src=eBlend_SRC_ALPHA, const eBlend dst=eBlend_ONE_MINUS_SRC_ALPHA, const eDepthTest depthTest=eDepthTest_ENABLE)
CLASS_METHOD void DisableBlend (void)
CLASS_METHOD void SetBlendFunc (const eBlend src, const eBlend dst)
CLASS_METHOD void BeginBlendImage (const uint width, const eColorFormat colorFormat=eColorFormat_RGBA)
CLASS_METHOD void BlendImage (const void *img, const uint imgLen)
CLASS_METHOD void GetBlendImage (void *img, const uint imgLen)
CLASS_METHOD void EndBlendImage (void)
CLASS_METHOD void EnableAntialias (const eAntialias antialias)
CLASS_METHOD bool EnableFog (const bool enable)
CLASS_METHOD bool EnableFog (const bool enable, const float fogDensity, const RGBA fogRgba)
CLASS_METHOD void SetFogColor (const RGBA rgba)
CLASS_METHOD RGBA GetFogColor (void)
CLASS_METHOD void SetFogDensity (const fp fogDensity)
CLASS_METHOD void SetBaseFogDensity (const fp baseFogDensity)
CLASS_METHOD fp GetFogDensity (void)
CLASS_METHOD void SetViewport (const Rect< int > &rect, bool force=false)
CLASS_METHOD void ClearViewport (void)
CLASS_METHOD Rect< int > GetViewport (void)
CLASS_METHOD
WidthHeight< int > 
GetWindow (void)
CLASS_METHOD Rect< int > GetWindowRect (void)
CLASS_METHOD void SetPerspective (const Perspective &perspective)
CLASS_METHOD void SetPerspective (const Perspective &perspective, const WidthHeight< int > &widthHeight)
CLASS_METHOD Perspective GetPerspective (void)
CLASS_METHOD fp GetPerspectiveFov (void)
CLASS_METHOD Vector2 Project (const EyeVertex &ev)
CLASS_METHOD bool IfVisible (const Vector3 &v)
CLASS_METHOD bool IfVisibleSphere (const Vector3 &v, const fp radius)
CLASS_METHOD void PostRedisplay (void)
CLASS_METHOD void ClearError (void)
CLASS_METHOD void CheckError (const string funcName=string(), bool dumpcore=false)
CLASS_METHOD Milliseconds GetTick (void)
 
Returns:
Elapsed (total) time since program start.

CLASS_METHOD Milliseconds GetTickDelta (void)
 
Returns:
Amount of time between now and previous tick.

CLASS_METHOD Milliseconds GetTickFreq (void)
 
Returns:
Frequency of timer-tick.

CLASS_METHOD void SetTickFreq (const Milliseconds freq)
CLASS_METHOD void SetBackgroundColor (const RGBA rgba)
CLASS_METHOD void Init (int argc, char **argv)
CLASS_METHOD void Start (void)
CLASS_METHOD bool IfReady (void)
 If gfxsys is ready to execute graphics functions.

Public Attributes

CLASS_CONST uint MATRIX_ELEMS = 16

Private Member Functions

 GFX (void)
 ~GFX ()
CLASS_METHOD bool Enable (const bool enable, bool &var, const GLenum mode)
CLASS_METHOD void ComputeFrustum (void)
CLASS_METHOD void Cmdargs (int argc, char **argv)
CLASS_METHOD void CheckCapabilities (void)
CLASS_METHOD void ConfigureSettingsBeforeReady (void)
CLASS_METHOD void ConfigureSettingsAfterReady (void)
CLASS_METHOD void Idle (void)
CLASS_METHOD void Reshape (int w, int h)
CLASS_METHOD void Display (void)
CLASS_METHOD void Timer (int unused)
CLASS_METHOD void MouseButtonHandler (int button, int state, int x, int y)
CLASS_METHOD void MouseMotionPassiveHandler (int x, int y)
CLASS_METHOD void MouseMotionHandler (int x, int y)
CLASS_METHOD void ResetModelViewMatrix (void)
CLASS_METHOD void UpdatePerspective (void)
CLASS_METHOD fp PerspectiveAngle (const fp size, const fp dist)

Private Attributes

CLASS_VAR bool msReady = false
CLASS_VAR
WidthHeight< int > 
msWindow
 any similarity to fictitious operating-system is unintentional ;-)
CLASS_VAR Rect< int > msViewport
CLASS_VAR Perspective msPerspective
CLASS_VAR fp msFrustum [6][4]
 frustum has 6 planes
CLASS_VAR GLfloat msProjectionMatrix [GFX::MATRIX_ELEMS]
CLASS_VAR Milliseconds msTick
 time-stamp of last tick
CLASS_VAR Milliseconds msTickFreq = GFX::DEFAULT_TICK_FREQ_MILLISEC
 frequency of timer-ticks
CLASS_CONST uint DEFAULT_TICK_FREQ_MILLISEC = 20
CLASS_VAR Modes msModes
CLASS_VAR Modes msModesSaved2D
CLASS_VAR GLint msIfAuxBuffer = false
CLASS_CONST ePrim msPrimTable [5]
CLASS_VAR RGBA msFogColor
CLASS_VAR GLint msFogMode = GL_EXP
CLASS_VAR fp msFogDensity = 0.0
CLASS_VAR fp msBaseFogDensity = 0.000012
CLASS_VAR int msBlockNest = 0
CLASS_VAR int msAuxBlockNest = 0
CLASS_VAR bool msComputedFrustum

Classes

class  Light
 Opaque struct to define a light source. More...
class  Material
 Opaque struct to define a material. More...
class  Modes
 Modes (states) of graphics system. More...
struct  Perspective


Detailed Description

Facade for graphics system (OpenGL).

///
/// Primitives:
/// -----------
/// GFX::Begin/End()             block that draws a primitive
/// GFX::Begin/End2D()           block that draws in 2D orthogonal (pass Rect relative to viewport)
/// GFX::Begin/EndAux()          block that draws into auxillary buffer
/// GFX::Vertex()                send 3D vertex
/// GFX::Vertex2D()              send 2D vertex
/// GFX::Normal()                send normal vector
/// GFX::Color()                 send RGBA
/// GFX::DrawRect2D()            draw 2D rectangle
/// 
/// Modes:
/// ------
/// GFX::SetPolygonMode()		 fill, line
/// GFX::GetModes()              get all modes
/// GFX::SetModes()              set all modes (could be slow)
/// GFX::EnableDepthMask()       enable writing to depth buffer
/// GFX::EnableDepthTest()       enable depth test
/// GFX::EnableTexture2()        enable 2D textures
/// GFX::Polygon2Prim()          convert vertex cnt of polygon to a GFX::ePrim enum (4 = ePrim_QUADS)
/// GFX::SetShade                specify shading (smooth/flat)
/// GFX::SetLineWidth()          specify line width and line smooth
/// GFX::SetPointSize()          set size of 2D point
///
/// Lighting:
/// ---------
/// GFX::Light class			 defines a light source
/// GFX::SetLight(Light,bool)	 enables/disables one light source
/// GFX::EnableLighting(bool)    enables/disbles all lights (global switch)
/// GFX::IfLighting()            true if lighting is enabled
///
/// Material:
/// ---------
/// GFX::Material class			 defines material properties
/// GFX::SetMaterial(Material)	 sets material properties (really enabled/disable by lighting)
///
/// Texture matrix:
/// -------------
/// GFX::IdentityTextureMatrix()
/// GFX::SetTextureMatrix()
/// GFX::GetTextureMatrix()
/// GFX::TranslateTextureMatrix()
/// GFX::RotateTextureMatrix()
///
/// Translucency:
/// -------------
/// GFX::EnableTranslucent()     enable translucency
/// GFX::DisableTranslucent()	 disable translucency
///
/// Fragment blending:
/// ------------------
/// GFX::EnableBlend()           enable fragment blending
/// GFX::DisableBlend()
///
/// Image blending:
/// ---------------
/// GFX::*BlendImage()           blending images (unrelated to fragment blending)
///
/// Antialiasing:
/// -------------
/// GFX::EnableAntialias()       enable anti-aliasing (FSAA actually)
/// GFX::IfAntialias()           if anti-aliasing mode is enabled
///
/// Fog:
/// ----
/// GFX::EnableFog()             enable fog, change fog density/color
/// GFX::SetFogColor()           set fog color
/// GFX::GetFogColor()           get fog color
/// GFX::SetFogDensity()         set fog density (tiny values have big effect)
/// GFX::SetBaseFogDensity()     multiplier
/// GFX::GetFogDensity()         get fog density
///
/// Viewport, perspective, frustum:
/// -------------------------------
/// GFX::SetViewport()           set viewport
/// GFX::Set/GetPerspective()    set perspective/frustum
/// GFX::Project()               project a 3D vertex into a 2D point
/// GFX::IfVisible()             if vertex is visible (inside view frustum)
/// GFX::IfVisibleSphere()       if sphere is visible (inside view frustum)
///
/// Events, error-checking:
/// -----------------------
/// GFX::PostRedisplay()         post display/paint event
/// GFX::ClearError()            forget any gfxsys errors
/// GFX::CheckError()            check if any gfxsys errors are happening
///
/// Timer:
/// ------
/// GFX::SetTickFreq()			 set frequency of timer-tick in milliseconds
/// GFX::GetTick*()              timer-tick info
///
/// Misc:
/// -----
/// GFX::SetBackgroundColor()	 set fill color
///
/// Initialization:
/// ---------------
/// GFX::Init()                  initialize but don't run gfxsys
/// GFX::Start()                 starts gfxsys (creates window, enters event loop)
/// GFX::IfReady()               if gfxsys is ready to run (execute graphics operations)
///
/// =============================================================================
///
/// Usage:
/// ------
/// Float args must be passed as type fp.
/// Otherwise, vector forms would malfunction if passed wrong type such as double.
///
/// NonThreadable:
/// -------------
/// GFX class is nonthreadable and only should be executed by the main thread.
/// It has micro-grain methods such as GFX::Vertex() that makes locking impractical.
/// Engine has support for letting threads enqueue "graphics tasks" which
/// the main thread dequeues and executes (useful for procedural textures eg).
///
/// 

Member Enumeration Documentation

enum gfx::GFX::ePrim

For Begin()/End().

Enumerator:
ePrim_POINTS 
ePrim_LINES 
ePrim_LINE_LOOP 
ePrim_TRIANGLES 
ePrim_TRIANGLE_STRIP 
ePrim_QUADS 
ePrim_QUAD_STRIP 
ePrim_POLYGON 

enum gfx::GFX::ePolygonMode

Enumerator:
ePolygonMode_POINT 
ePolygonMode_LINE 
ePolygonMode_FILL 
ePolygonMode_DEFAULT 

enum gfx::GFX::eBlend

Fragment blending.

Enumerator:
eBlend_SRC_ALPHA 
eBlend_SRC_COLOR 
eBlend_ONE_MINUS_SRC_ALPHA 
eBlend_DST_ALPHA 
eBlend_DST_COLOR 
eBlend_ONE_MINUS_DST_ALPHA 
eBlend_DST_ONE 

enum gfx::GFX::eColorFormat

Color formats.

Enumerator:
eColorFormat_RGBA 
eColorFormat_RGBA8 
eColorFormat_BGRA 

enum gfx::GFX::eDepthTest

Depth test.

Enumerator:
eDepthTest_DISABLE 
eDepthTest_ENABLE 

enum gfx::GFX::eShadeModel

Color shading.

Enumerator:
eShadeModel_FLAT 
eShadeModel_NORMAL 
eShadeModel_SMOOTH 

enum gfx::GFX::eAntialias

Enumerator:
eAntialias_OFF  really means don't explicitly enable AA
eAntialias_1  least antialiasing (faster)
eAntialias_2 
eAntialias_3  more antialiasing (slower)
eAntialias_DEFAULT 

enum gfx::GFX::eKey

Keyboard.

Enumerator:
eKey_ENTER 
eKey_ESC 
eKey_TAB 
eKey_BACKSPACE 
eKey_DELETE 
eKey_CTRL_C 
eKey_CTRL_P 
eKey_CTRL_S 
eKey_CTRL_X 
eKey_CTRL_Z 
eKey_1 
eKey_PLUS 
eKey_MINUS 
eKey_LEFT 
eKey_RIGHT 
eKey_UP 
eKey_DOWN 
eKey_HOME 
eKey_END 
eKey_F1 
eKey_F2 
eKey_F3 
eKey_F4 
eKey_F5 
eKey_F6 
eKey_F7 
eKey_F8 
eKey_F9 
eKey_F10 
eKey_F11 
eKey_F12 


Constructor & Destructor Documentation

gfx::GFX::GFX ( void   )  [private]

ctor/dtor.

gfx::GFX::~GFX (  )  [private]


Member Function Documentation

CLASS_METHOD void gfx::GFX::Begin ( ePrim  prim  )  [inline]

Block for drawing graphics primitives. Only a restricted subset of OpenGL functions are allowed between glBegin()...glEnd().

CLASS_METHOD void gfx::GFX::End ( void   )  [inline]

void gfx::GFX::Begin2D ( const Rect< int > &  rect  ) 

Draw in 2D. Afterwards, restores 3D drawing. Should enclose the usual Begin/End() blocks.

Parameters:
viewport Relative to the current viewport (not main window). (x1,y1) = top/left (NW) (x2,y2) = bottom/right (SE)

void gfx::GFX::End2D ( void   ) 

void gfx::GFX::BeginAux ( void   ) 

Block to draw in auxillary buffer.

Draw in auxillary buffer.

As of late 2006, some/most OpenGL implementations don't have GL_AUXn buffers. A slower alternative is to use the GL_BACK buffer and save/restore the affected area.

void gfx::GFX::EndAux ( void   ) 

CLASS_METHOD void gfx::GFX::Vertex ( const EyeVertex v  )  [inline]

Send 3D vertex.

gfx is based on Vector structs which can be cast as GLfloat[3]. SelfCheck() will catch if the cast would fail, in which case, make PORTABLE_VERTEX=1 will compile slower non-vector code.

CLASS_METHOD void gfx::GFX::Vertex ( const EyeVertex v  )  [inline]

CLASS_METHOD void gfx::GFX::Vertex2D ( fp  x,
fp  y 
) [inline]

Send 2D vertex.

CLASS_METHOD void gfx::GFX::Normal ( const NormalVertex n  )  [inline]

Send normal vector.

CLASS_METHOD void gfx::GFX::Color ( const RGBA  rgba  )  [inline]

Send RGBA.

void gfx::GFX::DrawRect2D ( const Rect< int > &  rect,
const RGBA  rgba 
)

Draw 2D rectangle.

Draw 2D rectangle.

Precondition:
Must be called only between GFX::Begin2D() and GFX::End2D().

CLASS_METHOD bool gfx::GFX::Enable ( const bool  enable,
bool &  var,
const GLenum  mode 
) [inline, private]

CLASS_METHOD Modes gfx::GFX::GetModes ( void   )  [inline]

void gfx::GFX::SetModes ( const Modes modes  ) 

Set all modes.

void gfx::GFX::SetPolygonMode ( const ePolygonMode  polygonMode  ) 

Polygon drawing mode (fill, line).

bool gfx::GFX::EnableDepthMask ( const bool  enable  ) 

Depth mask vs. depth test: Depth mask controls writing to depth buffer. Depth test affects culling polygons.

bool gfx::GFX::EnableDepthTest ( const bool  enable  ) 

CLASS_METHOD bool gfx::GFX::EnableTexture2 ( const bool  enable  )  [inline]

CLASS_METHOD ePrim gfx::GFX::Polygon2Prim ( const uint  vertexCnt  )  [inline]

For passing to Begin(ePrim), maps a vertex count of a polygon to a GFX::ePrim enum. 3 = ePrim_TRIANGLES, 4 = ePrim_QUADS

void gfx::GFX::SetShadeModel ( const eShadeModel  shadeModel  ) 

Set color shading.

void gfx::GFX::SetLineWidth ( const fp  lineWidth,
const bool  lineSmooth = false 
)

Specify line width and smooth line. Smooth line is usually appropriate if line width is fractional, but if the line is moved, aliasing causes flicker.

void gfx::GFX::SetPointSize ( const fp  pointSize  ) 

Specify size of 2D point.

CLASS_METHOD void gfx::GFX::EnableLighting ( const bool  enable = true  )  [inline]

Enables or disables all lights (global switch).

CLASS_METHOD bool gfx::GFX::IfLighting ( void   )  [inline]

void gfx::GFX::SetLight ( Light light,
const bool  enable = true 
)

Defines and enables/disable one light.

Enable/disable a light source.

void gfx::GFX::SetMaterial ( Material material  ) 

Enables/disables material.

Enable/disable material.

void gfx::GFX::IdentityTextureMatrix ( void   ) 

Load identity.

void gfx::GFX::SetTextureMatrix ( const Matrix m  ) 

void gfx::GFX::SetTextureMatrix ( const   fp[16]  ) 

Load texture matrix into gfxsys.

void gfx::GFX::GetTextureMatrix ( fp  m[16]  ) 

Copy texture matrix from gfxsys to app mem.

void gfx::GFX::TranslateTextureMatrix ( fp  x,
fp  y,
fp  z 
)

Translate texture matrix.

void gfx::GFX::RotateTextureMatrix ( const Degree  deg,
fp  x,
fp  y,
fp  z 
)

Rotate texture matrix.

void gfx::GFX::EnableTranslucent ( void   ) 

Methods to enable translucent polygons.

Enable translucency.

void gfx::GFX::DisableTranslucent ( void   ) 

void gfx::GFX::EnableBlend ( const eBlend  src = eBlend_SRC_ALPHA,
const eBlend  dst = eBlend_ONE_MINUS_SRC_ALPHA,
const eDepthTest  depthTest = eDepthTest_ENABLE 
)

Methods to blend fragments (not to be confused with blending images). Optionally disable depth test to prevent artifacts such as flickering textures etc.

void gfx::GFX::DisableBlend ( void   ) 

CLASS_METHOD void gfx::GFX::SetBlendFunc ( const eBlend  src,
const eBlend  dst 
) [inline]

void gfx::GFX::BeginBlendImage ( const uint  width,
const eColorFormat  colorFormat = eColorFormat_RGBA 
)

Blending images (unrelated to fragment blending). How to use: GFX::BeginBlendImage( 512, eColorFormat_RGBA ); GFX::BlendImage( buf0, buf0Len ); GFX::BlendImage( buf1, buf1Len ); ... GFX::GetBlendImage( blendedBuf, blendedBufLen ); GFX::EndBlendImage();

CLASS_METHOD void gfx::GFX::BlendImage ( const void *  img,
const uint  imgLen 
)

CLASS_METHOD void gfx::GFX::GetBlendImage ( void *  img,
const uint  imgLen 
)

void gfx::GFX::EndBlendImage ( void   ) 

void gfx::GFX::EnableAntialias ( const eAntialias  antialias  ) 

Antialiasing.

Antialiasing. Safe to call before gfxsys is ready (which actually is the only way this currently can work on Nvidia).

bool gfx::GFX::EnableFog ( const bool  enable  ) 

Fog.

Enable fog in OpenGL. Setting the fog parameters is tricky (esp. across OpenGL implementations). GL_FOG_DENSITY is extremely sensitive and the value used here is far lower than the example in the red book.

CLASS_METHOD bool gfx::GFX::EnableFog ( const bool  enable,
const float  fogDensity,
const RGBA  fogRgba 
)

void gfx::GFX::SetFogColor ( const RGBA  rgba  ) 

RGBA gfx::GFX::GetFogColor ( void   ) 

void gfx::GFX::SetFogDensity ( const fp  fogDensity  ) 

void gfx::GFX::SetBaseFogDensity ( const fp  baseFogDensity  ) 

fp gfx::GFX::GetFogDensity ( void   ) 

void gfx::GFX::SetViewport ( const Rect< int > &  rect,
bool  force = false 
)

Set viewport geometry (a subdivision of the main window). rect.x,y specifies bottom-left corner (not top-left).

void gfx::GFX::ClearViewport ( void   ) 

Clear viewport (part of color/depth buffers that viewport occupies).

Precondition:
SetViewport().

Rect< int > gfx::GFX::GetViewport ( void   ) 

Get dimensions of window or viewport.

WidthHeight< int > gfx::GFX::GetWindow ( void   ) 

Rect< int > gfx::GFX::GetWindowRect ( void   ) 

void gfx::GFX::SetPerspective ( const Perspective perspective  ) 

Change frustum by computing projection matrix.

void gfx::GFX::SetPerspective ( const Perspective perspective,
const WidthHeight< int > &  widthHeight 
)

CLASS_METHOD Perspective gfx::GFX::GetPerspective ( void   )  [inline]

CLASS_METHOD fp gfx::GFX::GetPerspectiveFov ( void   )  [inline]

Vector2 gfx::GFX::Project ( const EyeVertex ev  ) 

Project a 3D vertex to a 2D point.

Project a 3D vertex to a 2D point.

This is a highly-optimized version of Mesa 6.3.2 gluProject(). The major improvement is bypassing multiplying the modelview matrix since Palomino identity-maps it. Minor improvements are streamling the function args, bypassing unneeded calculations, and using single-precision.

GLint GLAPIENTRY gluProject(GLdouble objx, GLdouble objy, GLdouble objz, const GLdouble modelMatrix[OPENGL_MATRIX_ELEMS], const GLdouble projMatrix[OPENGL_MATRIX_ELEMS], const GLint viewport[4], GLdouble *winx, GLdouble *winy, GLdouble *winz) { double in[4]; double out[4];

in[0]=objx; in[1]=objy; in[2]=objz; in[3]=1.0; __gluMultMatrixVecd(modelMatrix, in, out); __gluMultMatrixVecd(projMatrix, out, in); if (in[3] == 0.0) return(GL_FALSE); in[0] /= in[3]; in[1] /= in[3]; in[2] /= in[3]; // Map x, y and z to range 0-1 in[0] = in[0] * 0.5 + 0.5; in[1] = in[1] * 0.5 + 0.5; in[2] = in[2] * 0.5 + 0.5;

// Map x,y to viewport in[0] = in[0] * viewport[2] + viewport[0]; in[1] = in[1] * viewport[3] + viewport[1];

*winx=in[0]; *winy=in[1]; *winz=in[2]; return(GL_TRUE); }

INTERN void __gluMultMatrixVecd(const GLdouble matrix[OPENGL_MATRIX_ELEMS], const GLdouble in[4], GLdouble out[4]) { int i;

for (i=0; i<4; i++) { out[i] = in[0] * matrix[0*4+i] + in[1] * matrix[1*4+i] + in[2] * matrix[2*4+i] + in[3] * matrix[3*4+i]; } }

Gollum originally wrote this function.

bool gfx::GFX::IfVisible ( const Vector3 v  ) 

Returns:
True if a vertex is visible. Implemented using view frustum. Bilbo Baggins originally wrote this code.

bool gfx::GFX::IfVisibleSphere ( const Vector3 origin,
const fp  radius 
)

Returns:
True if a sphere is visible. Implemented using view frustum.
Parameters:
origin Origin of sphere in Eye Space.
radius Sam Gamgee originally wrote this code.

void gfx::GFX::ComputeFrustum ( void   )  [private]

Compute frustum. This function is called only once so it doesn't need to be optimal. Tom Bombadil originally wrote this code.

CLASS_METHOD void gfx::GFX::PostRedisplay ( void   )  [inline]

Tell gfxsys to redisplay.

void gfx::GFX::ClearError ( void   ) 

Error handling.

OpenGL error handling. OpenGL error code is sticky. glGetError() clears it.

void gfx::GFX::CheckError ( const string  funcName = string(),
bool  dumpcore = false 
)

Milliseconds gfx::GFX::GetTick ( void   ) 

Returns:
Elapsed (total) time since program start.

Interface for registered timer-tick handlers (base::Event:mTick).

Interface for timer-tick handlers.

Milliseconds gfx::GFX::GetTickDelta ( void   ) 

Returns:
Amount of time between now and previous tick.

Milliseconds gfx::GFX::GetTickFreq ( void   ) 

Returns:
Frequency of timer-tick.

CLASS_METHOD void gfx::GFX::SetTickFreq ( const Milliseconds  freq  ) 

void gfx::GFX::SetBackgroundColor ( const RGBA  color  ) 

Set background color.

void gfx::GFX::Init ( int  argc,
char **  argv 
)

GFX system methods.

Bringup the gfxysys, but don't transfer control to it yet. Caller should later GFX::Start() after this.

Parameters:
argc 
argv 

void gfx::GFX::Start ( void   ) 

Transfer control to gfxsys. GFX::Init() should be called first.

CLASS_METHOD bool gfx::GFX::IfReady ( void   )  [inline]

If gfxsys is ready to execute graphics functions.

CLASS_METHOD void gfx::GFX::Cmdargs ( int  argc,
char **  argv 
) [private]

void gfx::GFX::CheckCapabilities ( void   )  [private]

Check OpenGL version and capabilities.

Precondition:
glutInit() called first.

void gfx::GFX::ConfigureSettingsBeforeReady ( void   )  [private]

Configure GFX from settings.conf parameters BEFORE OpenGL is ready. THIS MUST NOT AFFECT OPENGL STATE.

void gfx::GFX::ConfigureSettingsAfterReady ( void   )  [private]

Configure GFX from settings.conf parameters AFTER OpenGL is ready. These settings require OpenGL functions to be available.

void gfx::GFX::Idle ( void   )  [private]

GLUT idle function. CPU usage can remain high even when no rendering is being done because of GLUT continually calling idle callbacks (mitigated by yielding CPU).

void gfx::GFX::Reshape ( int  width,
int  height 
) [private]

GLUT reshape window callback. GLUT doesn't pass (x,y). But if ever needed, can get from glutGet(GLUT_WINDOW_X/Y).

void gfx::GFX::Display ( void   )  [private]

GLUT display callback.

CLASS_METHOD void gfx::GFX::Timer ( int  unused  )  [private]

void gfx::GFX::MouseButtonHandler ( int  glutButton,
int  glutState,
int  x,
int  y 
) [private]

Callback invoked by GLUT when one mouse button is pressed or released.

void gfx::GFX::MouseMotionPassiveHandler ( int  x,
int  y 
) [private]

Callback invoked by GLUT when mouse moved while no button is pressed.

void gfx::GFX::MouseMotionHandler ( int  x,
int  y 
) [private]

Callback invoked by GLUT when mouse moved while a button(s) is pressed.

void gfx::GFX::ResetModelViewMatrix ( void   )  [private]

Reset and select modelview matrix.

void gfx::GFX::UpdatePerspective ( void   )  [private]

Update projection matrix (after viewport is changed).

fp gfx::GFX::PerspectiveAngle ( const fp  size,
const fp  dist 
) [private]

Calculate the angle to be passed to gluPerspective() so that a scene is visible. This function originates from the OpenGL Red Book.

Parameters:
size The size of the segment when the angle is intersected at "dist" (ie at the outermost edge of the angle of vision).
dist Distance from viewpoint to scene.


Member Data Documentation

CLASS_CONST uint gfx::GFX::MATRIX_ELEMS = 16

bool gfx::GFX::msReady = false [private]

WidthHeight< int > gfx::GFX::msWindow [private]

any similarity to fictitious operating-system is unintentional ;-)

Rect< int > gfx::GFX::msViewport [private]

GFX::Perspective gfx::GFX::msPerspective [private]

fp gfx::GFX::msFrustum [private]

frustum has 6 planes

GLfloat gfx::GFX::msProjectionMatrix [private]

Milliseconds gfx::GFX::msTick [private]

time-stamp of last tick

Milliseconds gfx::GFX::msTickFreq = GFX::DEFAULT_TICK_FREQ_MILLISEC [private]

frequency of timer-ticks

CLASS_CONST uint gfx::GFX::DEFAULT_TICK_FREQ_MILLISEC = 20 [private]

GFX::Modes gfx::GFX::msModes [private]

GFX::Modes gfx::GFX::msModesSaved2D [private]

GLint gfx::GFX::msIfAuxBuffer = false [private]

const GFX::ePrim gfx::GFX::msPrimTable [private]

Initial value:

RGBA gfx::GFX::msFogColor [private]

GLint gfx::GFX::msFogMode = GL_EXP [private]

fp gfx::GFX::msFogDensity = 0.0 [private]

fp gfx::GFX::msBaseFogDensity = 0.000012 [private]

int gfx::GFX::msBlockNest = 0 [private]

int gfx::GFX::msAuxBlockNest = 0 [private]

bool gfx::GFX::msComputedFrustum [private]


The documentation for this class was generated from the following files: Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:27 2007