VoxelFarm::GL Namespace Reference

The GL namespace implements rendering over OpenGL. More...

Classes

class  CGLCellData
 A CellData object for rendering in OpenGL. More...
 
class  CSolid
 
struct  Frustum
 Viewing Frustum. More...
 
struct  Plane
 A 3D plane used to extract Frustum. More...
 
struct  RGBImageRec
 

Typedefs

typedef void OnBeforeRender()
 Prototype for BeforeRender event. This event fires before rendering begins.
 
typedef void OnAfterRender()
 Prototype for AfterRender event. This event fires after the world scene is rendered.
 

Functions

void computeOcclusion (Scene *scene, CClipmapView *clipmapView)
 
void render (Scene *scene, Scene *prevScene, float sceneBlend, CClipmapView *clipmapView)
 Renders the world. At any point in time, up to two different scenes could be active. This function will render a transition between the two scenes. More...
 
void renderShadowCasters (Scene *scene, CClipmapView *clipmapView)
 Renders only the shadow casting elements in the world. This is used to create shadow maps by rendering from the light's point of view. More...
 
void extractFrustum (Frustum &f)
 
bool sphereInFrustum (Frustum &f, GLfloat x, GLfloat y, GLfloat z, GLfloat radius)
 
int InitGL (GLvoid)
 Initializes OpenGL.
 
BOOL CreateGLWindow (char *title, int width, int height, int bits, bool fullscreenflag, WNDPROC WndProc, bool hosted, HWND parent)
 Creates the main window. More...
 
GLvoid KillGLWindow ()
 Destroys the main window.
 
GLvoid ReSizeGLScene (GLsizei width, GLsizei height)
 Resizes the GL context. More...
 
bool IsExtensionSupported (char *szTargetExtension)
 Determines whether the specified OpenGL extension is supported.
 
RGBImageRecloadImg (const char *szName)
 Load a BMP image.
 
bool loadMaterials (CMaterialLibrary *materialLibrary, char *path, bool loadCompressed)
 Load material definitions and textures into main memory and GPU memory.
 
void loadShaders ()
 Initializes GLSL shaders.
 
void clearDisplacementMaps ()
 Clear the created displacement maps.
 
bool bake (CClipmapView *clipmapView, StatTracker &stats)
 Moves multiple Cells from main memory into GPU memory.
 
void disposeDeadCells (CClipmapView *clipmapView, int iterations)
 Disposes a specified number of inactive cells, removing them from GPU memory.
 
void bakeCell (CClipmapView *clipmapView, CGLCellData *cellData)
 Moves the specified Cell data from main memory into GPU memory.
 
void orthogonalStart ()
 Starts orthogonal projection.
 
void orthogonalEnd ()
 Ends orthogonal projection.
 
bool createIcoSphere (float radius, float section, int levels, VoxelFarm::CCellData::CVert *verts, int &vertCount, GLushort *faceIndices, int &faceCount)
 
int DrawGLScene (CClipmapView *clipmapView)
 Draws the scene to screen.
 
void recomputeShadows ()
 
void generateShadowFBO ()
 Initializes FBO for Sunlight shadows.
 
void setShadowTextureMatrix (GLuint textureSlot=GL_TEXTURE7)
 Computes and stores the Sunlight shadow matrix.
 
void generateSkylightFBO ()
 Initializes FBO for Sunlight shadows.
 
void setSkylightTextureMatrix ()
 Computes and stores the Skylight shadow matrix.
 
unsigned char * readShaderFile (char *filename)
 Load shader text file.
 
GLuint compileProgram (char *vsrc, char *psrc, int attributeCount, int ids[], char *names[])
 Compile shader program.
 

Variables

GLuint glCellRenderProgram
 GLSL program ID for rendering world geometry.
 
GLuint uniform_cellRenderProgram_fade
 Shader parameter to control fading effect for cell. This is used to smooth LOD transitions.
 
GLuint uniform_cellRenderProgram_offset
 Shader parameter for the cell's absolute offset.
 
GLuint uniform_cellRenderProgram_worldOffset
 Shader parameter for the cell's offset based on the world coordinates when rendering started. This is used to avoid numeric representation errors, since the actual offset may be so large the fractional presicion may not be enough for finely placed detail.
 
GLuint uniform_cellRenderProgram_relOffset
 Shader parameter for the cell's relative offset to the viewer.
 
GLuint uniform_cellRenderProgram_cursorPos
 Shader parmeter for the carve cursor coordinates.
 
GLuint uniform_cellRenderProgram_cursorHintPos
 Shader parmeter for the add cursor coordinates.
 
GLuint uniform_cellRenderProgram_cursorPosMin
 Shader parmeter for the lower corner of the cursor scope.
 
GLuint uniform_cellRenderProgram_cursorPosMax
 Shader parmeter for the highest corner of the cursor scope.
 
GLuint uniform_cellRenderProgram_textures
 Shader parameter for the material texture array.
 
GLuint uniform_cellRenderProgram_noiseTexture
 Shader parameter for pink noise texture.
 
GLuint uniform_cellRenderProgram_materialArray
 Shader parameter for Rectangle texture that packs material information for the shader.
 
GLuint uniform_cellRenderProgram_faceNormal
 Shader parameter for array of vertex normals. These normals are not smoothed.
 
GLuint uniform_cellRenderProgram_materialChannelA
 Shader parameter for channel A of vertex material data.
 
GLuint uniform_cellRenderProgram_materialChannelB
 Shader parameter for channel B of vertex material data.
 
GLuint uniform_cellRenderProgram_materialChannelC
 Shader parameter for channel C of vertex material data.
 
GLuint uniform_cellRenderProgram_lightDir
 Shader parameter for array of light incidence vectors.
 
GLuint uniform_cellRenderProgram_cellSize
 Shader parameter for the cell dimension.
 
GLuint uniform_cellRenderProgram_snowHeight
 Shader parameter for an absolute height value where snow starts to appear over materials.
 
GLuint uniform_cellRenderProgram_LOD
 Shader parameter for Level of Detail for the cell.
 
GLuint uniform_cellRenderProgram_viewerPos
 Shader parameter for current viewer position.
 
GLuint uniform_cellRenderProgram_shadowMap
 Shader parameter for the Sunlight shadow map.
 
GLuint uniform_cellRenderProgram_shadowMapPhysics
 
GLuint uniform_cellRenderProgram_skylightMap
 Shader parameter for the Skylight shadow map.
 
GLuint uniform_cellRenderProgram_sunDir
 
GLuint uniform_cellRenderProgram_moonDir
 
GLuint uniform_cellRenderProgram_sunColor
 
GLuint uniform_cellRenderProgram_skyColor
 
GLuint uniform_cellRenderProgram_ambColor1
 
GLuint uniform_cellRenderProgram_ambColor2
 
GLuint uniform_cellRenderProgram_ambBase
 
GLuint uniform_cellRenderProgram_v3CameraPos
 
GLuint uniform_cellRenderProgram_v3InvWavelength
 
GLuint uniform_cellRenderProgram_fCameraHeight
 
GLuint uniform_cellRenderProgram_fCameraHeight2
 
GLuint uniform_cellRenderProgram_fOuterRadius
 
GLuint uniform_cellRenderProgram_fOuterRadius2
 
GLuint uniform_cellRenderProgram_fInnerRadius
 
GLuint uniform_cellRenderProgram_fInnerRadius2
 
GLuint uniform_cellRenderProgram_fKrESun
 
GLuint uniform_cellRenderProgram_fKmESun
 
GLuint uniform_cellRenderProgram_fKr4PI
 
GLuint uniform_cellRenderProgram_fKm4PI
 
GLuint uniform_cellRenderProgram_fScale
 
GLuint uniform_cellRenderProgram_fScaleDepth
 
GLuint uniform_cellRenderProgram_fScaleOverScaleDepth
 
GLuint uniform_cellRenderProgram_g
 
GLuint uniform_cellRenderProgram_g2
 
GLuint uniform_cellRenderProgram_sceneHeightBounds
 
GLuint uniform_cellRenderProgram_vertexPos
 
GLuint uniform_cellRenderProgram_vertexNormals
 
GLuint uniform_cellRenderProgram_vertexMaterialsA
 
GLuint uniform_cellRenderProgram_vertexMaterialsB
 
GLuint uniform_cellRenderProgram_vertexColor
 
GLuint uniform_cellRenderProgram_fragmentRot
 
GLuint glWaterProgram
 GLSL program ID for rendering water.
 
GLuint uniform_waterProgram_fade
 Shader parameter to control fading effect for cell. This is used to smooth LOD transitions.
 
GLuint uniform_waterProgram_offset
 Shader parameter for the cell's absolute offset.
 
GLuint uniform_waterProgram_worldOffset
 Shader parameter for the cell's offset based on the world coordinates when rendering started. This is used to avoid numeric representation errors, since the actual offset may be so large the fractional presicion may not be enough for finely placed detail.
 
GLuint uniform_waterProgram_relOffset
 Shader parameter for the cell's relative offset to the viewer.
 
GLuint uniform_waterProgram_cursorPos
 Shader parmeter for the carve cursor coordinates.
 
GLuint uniform_waterProgram_cursorHintPos
 Shader parmeter for the add cursor coordinates.
 
GLuint uniform_waterProgram_cursorPosMin
 Shader parmeter for the lower corner of the cursor scope.
 
GLuint uniform_waterProgram_cursorPosMax
 Shader parmeter for the highest corner of the cursor scope.
 
GLuint uniform_waterProgram_textures
 Shader parameter for the material texture array.
 
GLuint uniform_waterProgram_noiseTexture
 Shader parameter for pink noise texture.
 
GLuint uniform_waterProgram_materialArray
 Shader parameter for Rectangle texture that packs material information for the shader.
 
GLuint uniform_waterProgram_faceNormal
 Shader parameter for array of vertex normals. These normals are not smoothed.
 
GLuint uniform_waterProgram_materialChannelA
 Shader parameter for channel A of vertex material data.
 
GLuint uniform_waterProgram_materialChannelB
 Shader parameter for channel B of vertex material data.
 
GLuint uniform_waterProgram_materialChannelC
 Shader parameter for channel C of vertex material data.
 
GLuint uniform_waterProgram_lightDir
 Shader parameter for array of light incidence vectors.
 
GLuint uniform_waterProgram_cellSize
 Shader parameter for the cell dimension.
 
GLuint uniform_waterProgram_snowHeight
 Shader parameter for an absolute height value where snow starts to appear over materials.
 
GLuint uniform_waterProgram_LOD
 Shader parameter for Level of Detail for the cell.
 
GLuint uniform_waterProgram_viewerPos
 Shader parameter for current viewer position.
 
GLuint uniform_waterProgram_shadowMap
 Shader parameter for the Sunlight shadow map.
 
GLuint uniform_waterProgram_skylightMap
 Shader parameter for the Skylight shadow map.
 
GLuint uniform_waterProgram_sunDir
 
GLuint uniform_waterProgram_moonDir
 
GLuint uniform_waterProgram_sunColor
 
GLuint uniform_waterProgram_skyColor
 
GLuint uniform_waterProgram_ambColor1
 
GLuint uniform_waterProgram_ambColor2
 
GLuint uniform_waterProgram_ambBase
 
GLuint uniform_waterProgram_v3CameraPos
 
GLuint uniform_waterProgram_v3InvWavelength
 
GLuint uniform_waterProgram_fCameraHeight
 
GLuint uniform_waterProgram_fCameraHeight2
 
GLuint uniform_waterProgram_fOuterRadius
 
GLuint uniform_waterProgram_fOuterRadius2
 
GLuint uniform_waterProgram_fInnerRadius
 
GLuint uniform_waterProgram_fInnerRadius2
 
GLuint uniform_waterProgram_fKrESun
 
GLuint uniform_waterProgram_fKmESun
 
GLuint uniform_waterProgram_fKr4PI
 
GLuint uniform_waterProgram_fKm4PI
 
GLuint uniform_waterProgram_fScale
 
GLuint uniform_waterProgram_fScaleDepth
 
GLuint uniform_waterProgram_fScaleOverScaleDepth
 
GLuint uniform_waterProgram_g
 
GLuint uniform_waterProgram_g2
 
GLuint uniform_waterProgram_sceneHeightBounds
 
GLuint uniform_waterProgram_vertexPos
 
GLuint uniform_waterProgram_vertexNormals
 
GLuint uniform_waterProgram_vertexMaterialsA
 
GLuint uniform_waterProgram_vertexMaterialsB
 
GLuint uniform_waterProgram_vertexColor
 
GLuint uniform_waterProgram_time
 
GLuint glBillboardProgram
 GLSL program ID for rendering billboards.
 
GLuint uniform_billboardProgram_fade
 Shader parameter to control fading effect for cell. This is used to smooth LOD transitions.
 
GLuint uniform_billboardProgram_time
 Shader parameter for the current world time. This is used to animate wind.
 
GLuint uniform_billboardProgram_texture
 Shader parameter for the billboard texture.
 
GLuint uniform_billboardProgram_noise
 Shader parameter for a pink noise texture.
 
GLuint uniform_billboardProgram_camUp
 Shader parameter for camera up direction vector.
 
GLuint uniform_billboardProgram_camRight
 Shader parameter for camera right direction vector.
 
GLuint uniform_billboardProgram_offset
 Shader parameter for the cell's absolute offset.
 
GLuint uniform_billboardProgram_cellSize
 Shader parameter for the cell dimension.
 
GLuint uniform_billboardProgram_viewerPos
 Shader parameter for current viewer position.
 
GLuint uniform_billboardProgram_shadowMap
 Shader parameter for the Sunlight shadow map.
 
GLuint uniform_billboardProgram_skylightMap
 Shader parameter for the Skylight shadow map.
 
GLuint uniform_billboardProgram_applyColor
 Shader parameter for an array of colors used to colorize billboards.
 
GLuint uniform_billboardProgram_v3CameraPos
 
GLuint uniform_billboardProgram_sunDir
 
GLuint uniform_billboardProgram_sunColor
 
GLuint uniform_billboardProgram_skyColor
 
GLuint uniform_billboardProgram_ambColor1
 
GLuint uniform_billboardProgram_ambColor2
 
GLuint uniform_billboardProgram_ambBase
 
GLuint uniform_billboardProgram_v3InvWavelength
 
GLuint uniform_billboardProgram_fCameraHeight
 
GLuint uniform_billboardProgram_fCameraHeight2
 
GLuint uniform_billboardProgram_fOuterRadius
 
GLuint uniform_billboardProgram_fOuterRadius2
 
GLuint uniform_billboardProgram_fInnerRadius
 
GLuint uniform_billboardProgram_fInnerRadius2
 
GLuint uniform_billboardProgram_fKrESun
 
GLuint uniform_billboardProgram_fKmESun
 
GLuint uniform_billboardProgram_fKr4PI
 
GLuint uniform_billboardProgram_fKm4PI
 
GLuint uniform_billboardProgram_fScale
 
GLuint uniform_billboardProgram_fScaleDepth
 
GLuint uniform_billboardProgram_fScaleOverScaleDepth
 
GLuint uniform_billboardProgram_g
 
GLuint uniform_billboardProgram_g2
 
GLuint uniform_billboardProgram_sceneHeightBounds
 
GLuint uniform_billboardProgram_vertexPos
 
GLuint uniform_billboardProgram_vertexNormal
 
GLuint uniform_billboardProgram_vertexUV
 
GLuint uniform_billboardProgram_vertexColor
 
GLuint glInstanceProgram
 GLSL program ID for rendering instances.
 
GLuint uniform_instanceProgram_fade
 Shader parameter to control fading effect for cell. This is used to smooth LOD transitions.
 
GLuint uniform_instanceProgram_time
 Shader parameter for the current world time. This is used to animate wind.
 
GLuint uniform_instanceProgram_texture
 Shader parameter for the instance texture.
 
GLuint uniform_instanceProgram_noise
 Shader parameter for a pink noise texture.
 
GLuint uniform_instanceProgram_camUp
 Shader parameter for camera up direction vector.
 
GLuint uniform_instanceProgram_camRight
 Shader parameter for camera right direction vector.
 
GLuint uniform_instanceProgram_offset
 Shader parameter for the cell's absolute offset.
 
GLuint uniform_instanceProgram_cellSize
 Shader parameter for the cell dimension.
 
GLuint uniform_instanceProgram_viewerPos
 Shader parameter for current viewer position.
 
GLuint uniform_instanceProgram_shadowMap
 Shader parameter for the Sunlight shadow map.
 
GLuint uniform_instanceProgram_skylightMap
 Shader parameter for the Skylight shadow map.
 
GLuint uniform_instanceProgram_applyColor
 Shader parameter for an array of colors used to colorize instances.
 
GLuint uniform_instanceProgram_sunDir
 
GLuint uniform_instanceProgram_sunColor
 
GLuint uniform_instanceProgram_skyColor
 
GLuint uniform_instanceProgram_ambColor1
 
GLuint uniform_instanceProgram_ambColor2
 
GLuint uniform_instanceProgram_ambBase
 
GLuint glShadowCasterProgram
 GLSL program ID for rendering light occluders to the shadow maps.
 
GLuint uniform_shadowCasterProgram_vertexPos
 
GLuint glUICubeProgram
 GLSL program ID for rendering material samples in the UI.
 
GLuint uniform_UICubeProgram_textures
 Shader parameter for material texture array.
 
GLuint materialArray
 Texture Id for the material information array.
 
GLuint textureArray
 Texture Id for the material texture array.
 
GLuint instanceTextureArray
 Texture Id for the instance texture array.
 
GLuint noiseTexture
 Texture Id for a pink noise texture array.
 
GLuint billboardTexture
 Texture Id for the billboard texture atlas.
 
GLuint shadowDepthTextureId
 Texture Id for the Sunlight shadowmap.
 
GLuint shadowDepthTextureIdPhysics
 
GLuint skylightDepthTextureId
 Texture Id for the Skylight shadowmap.
 
Algebra::Vector sunDir
 
Algebra::Vector moonDir
 
Algebra::Vector sunColor
 
Algebra::Vector skyColor
 
Algebra::Vector skyColorBillboards
 
Algebra::Vector ambColor1
 
Algebra::Vector ambColor2
 
Algebra::Vector ambBase
 
float planetRadius
 
float atmosphereRadius
 
double lastShadowXpos
 Last viewer X position for wich shadowing was computed.
 
double lastShadowYpos
 Last viewer Y position for wich shadowing was computed.
 
double lastShadowZpos
 Last viewer Z position for wich shadowing was computed.
 
double lastShadowXposPhys
 
double lastShadowYposPhys
 
double lastShadowZposPhys
 
bool lineMode
 Show lines instead of trianles.
 
bool debugMode
 Show lines instead of trianles.
 
GLenum lastGLError
 
const int ERROR_INITIALIZATION_FAILED = 501
 Engine shutdown failed.
 
const int ERROR_SHUTDOWN_FAILED = 502
 Engine shutdown failed.
 
const int ERROR_RESOLUTION_NOT_SUPPORTED = 503
 Video resolution is not supported.
 
const int ERROR_SHADER = 504
 Shader error.
 
HDC hDC
 HDC object for the main window.
 
HGLRC hRC
 HRC object for the main window.
 
HWND hWnd
 Handle for the main window.
 
HINSTANCE hInstance
 HINSTANCE object for the main window.
 
bool fullscreen
 Signals whether the application is full screen.
 
int window_width
 Width of the main window.
 
int window_height
 Height of the main window.
 
const int MATERIAL_PROPERTY_COUNT = 14
 Number of properties in each material defintion inside the GPU material array.
 
GLuint shadowFBOId
 FBO Id for the Sunlight shadow.
 
GLuint shadowFBOIdPhysics
 FBO Id for the Sunlight shadow for physics fragments.
 
int shadowMapWidth
 Shadowmap Width for the Sunlight shadow.
 
int shadowMapHeight
 Shadowmap Height for the Sunlight shadow.
 
GLuint skylightFBOId
 FBO Id for the Skylight shadow.
 
int skylightMapWidth
 Shadowmap Width for the Skylight shadow.
 
int skylightMapHeight
 Shadowmap Height for the Skylight shadow.
 
GLuint cloudTextureId
 
OnBeforeRenderbeforeRender
 Pointer to BeforeRender event. This event fires before rendering begins.
 
OnBeforeRenderafterRender
 Pointer to AfterRender event. This event fires after the world scene is rendered.
 

Detailed Description

The GL namespace implements rendering over OpenGL.

The GL namespace deals with the state and functionality required to render the VoxelFarm data using OpenGL

Function Documentation

BOOL VoxelFarm::GL::CreateGLWindow ( char *  title,
int  width,
int  height,
int  bits,
bool  fullscreenflag,
WNDPROC  WndProc,
bool  hosted,
HWND  parent 
)

Creates the main window.

Parameters
titleTitle for the window in the OS
widthWidth in pixels for the window
heightHeight in pixels for the window
bitsColor-depth in number of bits for the window (32, 16)
fullscreenflagRun full scren
WndProcPointer to a WndProc function to handle OS events
hostedIs this a standalone or hosted window
void VoxelFarm::GL::render ( Scene scene,
Scene prevScene,
float  sceneBlend,
CClipmapView clipmapView 
)

Renders the world. At any point in time, up to two different scenes could be active. This function will render a transition between the two scenes.

Parameters
sceneCurrent scene to be rendered
prevScenePrevious scene, the one that should be fading out
sceneBlendA value between 0 and 1 specifying how much of each scene is still present. This is used to gradually transition from one scene to the next
clipmapViewAn index of CellData objects to be used by rendering
void VoxelFarm::GL::renderShadowCasters ( Scene scene,
CClipmapView clipmapView 
)

Renders only the shadow casting elements in the world. This is used to create shadow maps by rendering from the light's point of view.

Parameters
sceneCurrent scene to be rendered
clipmapViewAn index of CellData objects to be used by rendering
GLvoid VoxelFarm::GL::ReSizeGLScene ( GLsizei  width,
GLsizei  height 
)

Resizes the GL context.

Parameters
widthNew width in pixels for the window
heightNew height in pixels for the window