SLProject 4.0.000
|
Defines a 2D-Background for the OpenGL framebuffer background. More...
#include <SLBackground.h>
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 <, 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 |
SLGLTexture * | texture () |
const SLRectf & | rect () 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 SLstring & | name () const |
const SLstring & | url () 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... | |
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.
SLBackground::SLBackground | ( | SLstring | shaderDir | ) |
The constructor initializes to a uniform BLACK background color.
SLBackground::SLBackground | ( | SLGLProgram * | textureOnlyProgram, |
SLGLProgram * | colorAttributeProgram | ||
) |
The constructor initializes to a uniform gray background color.
SLBackground::~SLBackground | ( | ) |
|
inline |
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
|
inline |
Sets a gradient top-down background color.
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.
void SLBackground::colors | ( | const SLCol4f & | uniformColor | ) |
Sets a uniform background color.
|
inline |
|
inline |
|
inline |
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
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
|
inline |
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.
|
private |
Average color of all 4 corner colors.
|
private |
|
private |
Vector of 4 corner colors {TL,BL,TR,BR}.
|
private |
|
private |
if true, the background is centered and stretched to the screen boarders while keeping the textures aspect ratio
|
private |
Flag if background has uniform color.
|
private |
Background rect (it may be different to viewport size)
|
private |
Background resolution in x-dir.
|
private |
Background resolution in y-dir.
|
private |
Pointer to a background texture.
|
private |
Pointer to a error texture if background texture is not available.
|
private |
|
private |
OpenGL Vertex Array Object for drawing.