Texturing a particle system using point sprites and shaders
In this recipe, we will learn how to apply a texture to all our particles using OpenGL point sprites and a GLSL Shader.
This method is optimized and allows for a large number of particles to be drawn at fast frame rates.
Getting ready
We will be using the particle system developed in the recipe Creating a particle system in 2D from Chapter 5, Building Particle Systems. So we will need to add the following files to your project:
Particle.h
ParticleSystem.h
We will also be loading an image to use as texture. The image's size must be a power of two, such as 256 x 256 or 512 x 512. Place the image inside the assets
folder and name it particle.png
.
How to do it...
We will create a GLSL shader and then enable OpenGL point sprites to draw textured particles.
Let's begin by creating the GLSL Shader. Create the following files:
shader.frag
shader.vert
Add them to the
assets
folder.Open the file
shader.frag
in your IDE of choice and declare auniform...