SLProject
4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
|
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.
Definition at line 28 of file SLBackground.h.
SLBackground::SLBackground | ( | SLstring | shaderDir | ) |
The constructor initializes to a uniform BLACK background color.
Definition at line 17 of file SLBackground.cpp.
SLBackground::SLBackground | ( | SLGLProgram * | textureOnlyProgram, |
SLGLProgram * | colorAttributeProgram | ||
) |
The constructor initializes to a uniform gray background color.
Definition at line 42 of file SLBackground.cpp.
SLBackground::~SLBackground | ( | ) |
Definition at line 61 of file SLBackground.cpp.
|
inline |
Definition at line 56 of file SLBackground.h.
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
Definition at line 331 of file SLBackground.cpp.
|
inline |
Definition at line 55 of file SLBackground.h.
Sets a gradient top-down background color.
Definition at line 84 of file SLBackground.cpp.
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.
Definition at line 98 of file SLBackground.cpp.
|
inline |
Definition at line 57 of file SLBackground.h.
|
inline |
Definition at line 42 of file SLBackground.h.
|
inline |
Definition at line 59 of file SLBackground.h.
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
Definition at line 148 of file SLBackground.cpp.
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
Definition at line 258 of file SLBackground.cpp.
|
inline |
Definition at line 58 of file SLBackground.h.
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.
Definition at line 114 of file SLBackground.cpp.
|
private |
Average color of all 4 corner colors.
Definition at line 64 of file SLBackground.h.
|
private |
Definition at line 73 of file SLBackground.h.
|
private |
Vector of 4 corner colors {TL,BL,TR,BR}.
Definition at line 63 of file SLBackground.h.
|
private |
Definition at line 74 of file SLBackground.h.
|
private |
if true, the background is centered and stretched to the screen boarders while keeping the textures aspect ratio
Definition at line 76 of file SLBackground.h.
|
private |
Flag if background has uniform color.
Definition at line 62 of file SLBackground.h.
|
private |
Background rect (it may be different to viewport size)
Definition at line 69 of file SLBackground.h.
|
private |
Background resolution in x-dir.
Definition at line 67 of file SLBackground.h.
|
private |
Background resolution in y-dir.
Definition at line 68 of file SLBackground.h.
|
private |
Pointer to a background texture.
Definition at line 65 of file SLBackground.h.
|
private |
Pointer to a error texture if background texture is not available.
Definition at line 66 of file SLBackground.h.
|
private |
Definition at line 72 of file SLBackground.h.
|
private |
OpenGL Vertex Array Object for drawing.
Definition at line 70 of file SLBackground.h.