# How to specify colour in a single 32 bit value

I'm writing my first game using OpenGL 2 ES (for Android), and I've currently got a particle engine and some player sprites running successfully. I'm using 4 floats for the colour of each particle which seems like total overkill. It makes sense that I should be able to use a single 32 bit int (or perhaps a single float) to hold the colours (perhaps in RGBA format) which would presumably save a lot of unnecessary loading/copying/processing, but I'm struggling to understand how I could do this.

I guess that I would need to change the shaders to take the relevant format, and also i'd need to change the way I load the color shader attribute. My fragment shader has:

varying vec4 v_Color;
gl_FragColor = v_Color * texture2D(u_TextureUnit, gl_PointCoord);


and the attribute (passed into the fragment shader from the vertex shader) is set up with:

glVertexAttribPointer(aColourLocation, COLOUR_COMPONENT_COUNT, GL_FLOAT, false, BYTES_PER_VERTEX, floatBuffer);


I've searched the documentation for what I should change vec4 and GL_FLOAT to, and what/how I'd multiply the colour with the texture, and have tried a few things but with no success.

• You are looking in the wrong place you should set the draw buffer to a 8 bit format, all the rest happens automatically – ratchet freak Sep 19 '14 at 12:22
• @ratchetfreak Not sure what i'd do to the shader/attrib setup. What types do I use? How do I do the colour multiply? – user5196 Sep 19 '14 at 12:32
• this might help opengl.org/wiki/Image_Format – Aralox Sep 19 '14 at 13:01
• @Aralox Thanks, that seems relevant. Seems that what I want would be GL_RGBA8UI. Sadly, it doesn't look like this is available on OpenGL ES 2.0 for Android: developer.android.com/reference/android/opengl/… Or am I misreading that? Should I be worried about trying to use 4 bytes instead of 16 to specify the colour of each particle? – user5196 Sep 19 '14 at 20:10