32 shaderDir +
"TextureOnly.vert",
33 shaderDir +
"TextureOnly.frag");
36 shaderDir +
"ColorAttribute.vert",
37 shaderDir +
"Color.frag");
45 _textureOnlyProgram(textureOnlyProgram),
46 _colorAttributeProgram(colorAttributeProgram),
47 _deletePrograms(false)
91 _avgColor = (topColor + bottomColor) / 2.0f;
101 const SLCol4f& bottomRightColor)
104 _colors[1].set(bottomLeftColor);
106 _colors[3].set(bottomRightColor);
180 SLfloat backgroundW, backgroundH;
184 backgroundH = (float)
_resY;
190 backgroundW = (float)
_resX;
194 left = (
_resX - backgroundW) * 0.5f;
195 right = backgroundW + left;
196 bottom = (
_resY - backgroundH) * 0.5f;
197 top = backgroundH + bottom;
199 _rect.
set(left, bottom, backgroundW, backgroundH);
200 SL_LOG(
"SLBackground: width:%f height:%f left:%f bottom:%f",
rect().width,
rect().height,
rect().x,
rect().x);
203 _rect.
set(0, 0, (
float)widthPX, (
float)heightPX);
219 SLVVec2f T = {{0.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}};
288 SLVVec2f T = {{0.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}};
367 if (u > 0 && v > 0 && u + v <= 1)
static SLbool fixAspectRatio
Flag if wnd aspect ratio should be fixed.
vector< SLushort > SLVushort
@ AT_position
Vertex position as a 2, 3 or 4 component vectors.
@ AT_color
Vertex color as 3 or 4 component vector.
@ AT_uv1
Vertex 1st texture coordinate as 2 component vector.
vector< SLVec2f > SLVVec2f
SLVec2< SLfloat > SLVec2f
vector< SLVec3f > SLVVec3f
SLint _resY
Background resolution in y-dir.
SLCol4f _avgColor
Average color of all 4 corner colors.
SLGLProgram * _colorAttributeProgram
SLVCol4f _colors
Vector of 4 corner colors {TL,BL,TR,BR}.
SLBackground(SLstring shaderDir)
The constructor initializes to a uniform BLACK background color.
SLGLProgram * _textureOnlyProgram
SLGLTexture * _texture
Pointer to a background texture.
const SLRectf & rect() const
SLGLVertexArray _vao
OpenGL Vertex Array Object for drawing.
void render(SLint widthPX, SLint heightPX)
Draws the background as 2D rectangle with OpenGL buffers.
SLRectf _rect
Background rect (it may be different to viewport size)
SLCol4f colorAtPos(SLfloat x, SLfloat y, SLfloat width, SLfloat height)
Returns the interpolated color at the pixel position p[x,y] used in raytracing.
bool _fixAspectRatio
if true, the background is centered and stretched to the screen boarders while keeping the textures a...
SLGLTexture * _textureError
Pointer to a error texture if background texture is not available.
SLbool _isUniform
Flag if background has uniform color.
SLint _resX
Background resolution in x-dir.
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.
Generic Shader Program class inherited from SLGLProgram.
Encapsulation of an OpenGL shader program object.
SLint uniformMatrix4fv(const SLchar *name, SLsizei count, const SLfloat *value, GLboolean transpose=false) const
Passes a 4x4 float matrix values py pointer to the uniform variable "name".
SLint uniform1f(const SLchar *name, SLfloat v0) const
Passes the float value v0 to the uniform variable "name".
SLint uniform1i(const SLchar *name, SLint v0) const
Passes the int values v0 to the uniform variable "name".
Singleton class holding all OpenGL states.
SLMat4f modelMatrix
Init all states.
void multiSample(SLbool state)
static SLGLState * instance()
Public static instance getter for singleton pattern.
SLMat4f viewMatrix
matrix for the active cameras view transform
SLMat4f projectionMatrix
matrix for projection transform
void depthTest(SLbool state)
Texture object for OpenGL texturing.
void bindActive(SLuint texUnit=0)
SLCol4f getTexelf(SLfloat u, SLfloat v, SLuint imgIndex=0)
SLGLTexture::getTexelf returns a pixel color from u & v texture coordinates.
void clearAttribs()
Clears the attribute definition.
void drawElementsAs(SLGLPrimitiveType primitiveType, SLuint numIndexes=0, SLuint indexOffsetBytes=0)
Draws the VAO by element indices with a primitive type.
void setAttrib(SLGLAttributeType type, SLint elementSize, SLint location, void *dataPointer, SLGLBufferType dataType=BT_float)
Adds a vertex attribute with data pointer and an element size.
SLuint vaoID() const
Returns either the VAO id or the VBO id.
void setIndices(SLuint numIndicesElements, SLGLBufferType indexDataType, void *indexDataElements, SLuint numIndicesEdges=0, void *indexDataEdges=nullptr)
Adds the index array for indexed element drawing.
void generate(SLuint numVertices, SLGLBufferUsage usage=BU_static, SLbool outputInterleaved=true, SLuint divisor=0)
Generates the VA & VB objects for a NO. of vertices.
static SLfloat oneOverGamma()
void ortho(T l, T r, T b, T t, T n, T f)
Defines a orthographic projection matrix with a field of view angle.
void identity()
Sets the identity matrix.
Base class for all other classes.
void set(const T X, const T Y, const T WIDTH, const T HEIGHT)
SLVec2 barycentricCoords(SLVec2 A, SLVec2 B, SLVec2 C)
Calculate the barycentric coordinate uv of the point within a triangle ABC.