Game Development Reference
In-Depth Information
Creating a canvas for immediate rendering
In the previous recipes, we learned how to make abstractions for main OpenGL entities: vertex
buffers, shader programs, and textures. This basis is enough to render many sophisticated
effects using OpenGL. However, there are a lot of tiny rendering tasks where you need to
render only one triangle or a rectangle with a single texture, or render a fullscreen quad with a
speciic shader to apply some image-space effect. In this case, the code for managing buffers,
shaders, and textures may become a serious burden. Let's organize a place for such a helper
code, that is, a canvas that will help us to render simple things in a single line of code.
Getting ready
This recipe uses the clGLSLShaderProgram , clGLTexture , and clGLVertexArray
classes described in the previous recipes to hide the differences between OpenGL ES 2 and
OpenGL 3. Read them carefully before proceeding.
How to do it…
1. We irst deine a clCanvas class as follows:
class clCanvas
{
public:
clCanvas();
virtual ~clCanvas() {};
void Rect2D( float X1, float Y1,
float X2, float Y2, const LVector4& Color );
void TexturedRect2D( float X1, float Y1,
float X2, float Y2,
const LVector4& Color,
const clPtr<clGLTexture>& Texture );
clPtr<clGLVertexArray> GetFullscreenRect() const
{ return FRectVA; }
2.
We store some OpenGL-related entities right here:
private:
clPtr<clVertexAttribs> FRect;
clPtr<clGLVertexArray> FRectVA;
clPtr<clGLSLShaderProgram> FRectSP;
clPtr<clGLSLShaderProgram> FTexRectSP;
};
 
Search WWH ::




Custom Search