Game Development Reference
In-Depth Information
6.
Alternatively, apply an additional color from a texture:
uniform vec4 u_Color;
out vec4 out_FragColor;
in vec2 Coords;
uniform sampler2D Texture0;
void main()
{
out_FragColor = u_Color * texture( Texture0, Coords );
}
We use the clGLSLShaderProgram class from the previous recipes to set up shader
programs. It hides the syntax differences between OpenGL ES 2 and OpenGL 3, so we
can store only one version of each shader.
You may want to implement a similar wrapper for OpenGL ES
3 as an exercise.
How it works…
1.
The actual rendering code inside the canvas is very simple. Bind textures and the
shader program, set the values of uniforms, and draw the vertex array:
void clCanvas::TexturedRect2D(
float X1, float Y1,
float X2, float Y2,
const LVector4& Color,
const clPtr<clGLTexture>& Texture )
{
LGL3->glDisable( GL_DEPTH_TEST );
Texture->Bind(0);
FTexRectSP->Bind();
FTexRectSP->SetUniformNameVec4Array(
"u_Color", 1, Color );
FTexRectSP->SetUniformNameVec4Array(
"u_RectSize", 1, LVector4( X1, Y1, X2, Y2 ) );
LGL3->glBlendFunc(
GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
LGL3->glEnable( GL_BLEND );
FRectVA->Draw( false );
LGL3->glDisable( GL_BLEND );
}
 
Search WWH ::




Custom Search