SLProject 4.0.000
SLBackground Class Reference

Defines a 2D-Background for the OpenGL framebuffer background. More...

#include <SLBackground.h>

Inheritance diagram for SLBackground:
[legend]

Public Member Functions

 SLBackground (SLstring shaderDir)
 The constructor initializes to a uniform BLACK background color. More...
 
 SLBackground (SLGLProgram *textureOnlyProgram, SLGLProgram *colorAttributeProgram)
 The constructor initializes to a uniform gray background color. More...
 
 ~SLBackground ()
 
void render (SLint widthPX, SLint heightPX)
 Draws the background as 2D rectangle with OpenGL buffers. More...
 
void renderInScene (const SLMat4f &wm, const SLVec3f &LT, const SLVec3f &LB, const SLVec3f &RT, const SLVec3f &RB)
 Draws the background as a quad on the far clipping plane. More...
 
SLCol4f colorAtPos (SLfloat x, SLfloat y, SLfloat width, SLfloat height)
 Returns the interpolated color at the pixel position p[x,y] used in raytracing. More...
 
void rebuild ()
 
void colors (const SLCol4f &uniformColor)
 Sets a uniform background color. More...
 
void colors (const SLCol4f &topColor, const SLCol4f &bottomColor)
 Sets a gradient top-down background color. More...
 
void colors (const SLCol4f &topLeftColor, const SLCol4f &bottomLeftColor, const SLCol4f &topRightColor, const SLCol4f &bottomRightColor)
 Sets a gradient background color with a color per corner. More...
 
void texture (SLGLTexture *backgroundTexture, bool fixAspectRatio=false)
 If flag _repeatBlurred is true the texture is not distorted if its size does not fit to screen aspect ratio. Instead it is repeated. More...
 
SLVCol4f colors ()
 
SLCol4f avgColor ()
 
SLbool isUniform () const
 
SLGLTexturetexture ()
 
const SLRectfrect () const
 
- Public Member Functions inherited from SLObject
 SLObject (const SLstring &Name="", const SLstring &url="")
 
virtual ~SLObject ()
 
void name (const SLstring &Name)
 
void url (const SLstring &url)
 
const SLstringname () const
 
const SLstringurl () const
 

Private Attributes

SLbool _isUniform
 Flag if background has uniform color. More...
 
SLVCol4f _colors
 Vector of 4 corner colors {TL,BL,TR,BR}. More...
 
SLCol4f _avgColor
 Average color of all 4 corner colors. More...
 
SLGLTexture_texture
 Pointer to a background texture. More...
 
SLGLTexture_textureError
 Pointer to a error texture if background texture is not available. More...
 
SLint _resX
 Background resolution in x-dir. More...
 
SLint _resY
 Background resolution in y-dir. More...
 
SLRectf _rect
 Background rect (it may be different to viewport size) More...
 
SLGLVertexArray _vao
 OpenGL Vertex Array Object for drawing. More...
 
SLGLProgram_textureOnlyProgram = nullptr
 
SLGLProgram_colorAttributeProgram = nullptr
 
bool _deletePrograms = false
 
bool _fixAspectRatio = false
 if true, the background is centered and stretched to the screen boarders while keeping the textures aspect ratio More...
 

Additional Inherited Members

- Protected Attributes inherited from SLObject
SLstring _name
 name of an object More...
 
SLstring _url
 uniform resource locator More...
 

Detailed Description

Defines a 2D-Background for the OpenGL framebuffer background.

The background can either be defined with a texture or with 4 colors for the corners of the frame buffer. For a uniform background color the color at index 0 of the _colors vector is taken. Every instance of SLCamera has a background that is displayed on the far clipping plane if the camera is not the active one. The OpenGL rendering is done in SLSceneView::draw3DGL for the active camera or in SLCamera::drawMeshes for inactive ones.

Constructor & Destructor Documentation

◆ SLBackground() [1/2]

SLBackground::SLBackground ( SLstring  shaderDir)

The constructor initializes to a uniform BLACK background color.

◆ SLBackground() [2/2]

SLBackground::SLBackground ( SLGLProgram textureOnlyProgram,
SLGLProgram colorAttributeProgram 
)

The constructor initializes to a uniform gray background color.

◆ ~SLBackground()

SLBackground::~SLBackground ( )

Member Function Documentation

◆ avgColor()

SLCol4f SLBackground::avgColor ( )
inline

◆ colorAtPos()

SLCol4f SLBackground::colorAtPos ( SLfloat  x,
SLfloat  y,
SLfloat  width,
SLfloat  height 
)

Returns the interpolated color at the pixel position p[x,y] used in raytracing.

Returns the interpolated color at the pixel position p[x,y] for ray tracing. x is expected to be between 0 and width of the RT-frame. y is expected to be between 0 and height of the RT-frame. width is the width of the RT-frame height is the height of the RT-frame

C w B +--—+ | p /| | * / | h | / | | / | |/ | 0 +--—+ A 0

◆ colors() [1/4]

SLVCol4f SLBackground::colors ( )
inline

◆ colors() [2/4]

void SLBackground::colors ( const SLCol4f topColor,
const SLCol4f bottomColor 
)

Sets a gradient top-down background color.

◆ colors() [3/4]

void SLBackground::colors ( const SLCol4f topLeftColor,
const SLCol4f bottomLeftColor,
const SLCol4f topRightColor,
const SLCol4f bottomRightColor 
)

Sets a gradient background color with a color per corner.

◆ colors() [4/4]

void SLBackground::colors ( const SLCol4f uniformColor)

Sets a uniform background color.

◆ isUniform()

SLbool SLBackground::isUniform ( ) const
inline

◆ rebuild()

void SLBackground::rebuild ( )
inline

◆ rect()

const SLRectf & SLBackground::rect ( ) const
inline

◆ render()

void SLBackground::render ( SLint  widthPX,
SLint  heightPX 
)

Draws the background as 2D rectangle with OpenGL buffers.

Draws the background as a flat 2D rectangle with a height and a width on two triangles with zero in the bottom left corner:
w +--—+ | /| | / | h | / | | / | |/ | 0 +--—+ 0

We render the quad as a triangle strip:
0 2 +--—+ | /| | / | | / | | / | |/ | +--—+ 1 3

◆ renderInScene()

void SLBackground::renderInScene ( const SLMat4f wm,
const SLVec3f LT,
const SLVec3f LB,
const SLVec3f RT,
const SLVec3f RB 
)

Draws the background as a quad on the far clipping plane.

We render the quad as a triangle strip:
LT RT +--—+ | /| | / | | / | | / | |/ | +--—+ LB RB

◆ texture() [1/2]

SLGLTexture * SLBackground::texture ( )
inline

◆ texture() [2/2]

void SLBackground::texture ( SLGLTexture backgroundTexture,
bool  fixAspectRatio = false 
)

If flag _repeatBlurred is true the texture is not distorted if its size does not fit to screen aspect ratio. Instead it is repeated.

Sets the background texture.

Member Data Documentation

◆ _avgColor

SLCol4f SLBackground::_avgColor
private

Average color of all 4 corner colors.

◆ _colorAttributeProgram

SLGLProgram* SLBackground::_colorAttributeProgram = nullptr
private

◆ _colors

SLVCol4f SLBackground::_colors
private

Vector of 4 corner colors {TL,BL,TR,BR}.

◆ _deletePrograms

bool SLBackground::_deletePrograms = false
private

◆ _fixAspectRatio

bool SLBackground::_fixAspectRatio = false
private

if true, the background is centered and stretched to the screen boarders while keeping the textures aspect ratio

◆ _isUniform

SLbool SLBackground::_isUniform
private

Flag if background has uniform color.

◆ _rect

SLRectf SLBackground::_rect
private

Background rect (it may be different to viewport size)

◆ _resX

SLint SLBackground::_resX
private

Background resolution in x-dir.

◆ _resY

SLint SLBackground::_resY
private

Background resolution in y-dir.

◆ _texture

SLGLTexture* SLBackground::_texture
private

Pointer to a background texture.

◆ _textureError

SLGLTexture* SLBackground::_textureError
private

Pointer to a error texture if background texture is not available.

◆ _textureOnlyProgram

SLGLProgram* SLBackground::_textureOnlyProgram = nullptr
private

◆ _vao

SLGLVertexArray SLBackground::_vao
private

OpenGL Vertex Array Object for drawing.


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