I have an array of particles that I'd like to draw at once using glDrawArrays, however I would also like to dynamically set the alpha of some particles while using a shader. I came up with a method of using GL_COLOR_ARRAY to send the alpha information per point to the shader. It works fine, however after calling glDisableClientState(GL_COLOR_ARRAY); on certain graphics cards the color array stays active and modifies everything else drawn. For example:
Here is where I draw my particles:
Here is the relevant part of my shader that takes the color array and uses that to change the alpha on individual particles:Code :glUseProgram(particleShader); glEnableClientState(GL_COLOR_ARRAY); glBindTexture(GL_TEXTURE_2D, particleTexture); glColorPointer(4, GL_FLOAT, 0, betweenPartColorArray); glTexCoordPointer(2, GL_FLOAT, 0,textureCoordsBetweenParticles); glVertexPointer(3, GL_FLOAT, 0, verticesBetweenParticles); glDrawArrays(GL_QUADS, 0, numberBetweenPartIndices); glDisableClientState(GL_COLOR_ARRAY); glUseProgram(0);
Vertex:
Fragment:Code :varying vec4 vertex_color; varying vec4 verpos; // had an error with verpos for whatever reason. If problems crop check into it void main(void){ vertex_color = gl_Color; gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0; verpos = gl_ModelViewMatrix*gl_Vertex; }
Code :varying vec4 vertex_color; uniform sampler2D sceneTex; void main (void) { vec4 finalColor = texture2D(sceneTex, gl_TexCoord[0].xy) ; gl_FragColor=finalColor; finalColor.a*=vertex_color.a; finalColor=clamp(finalColor, 0.0, 1.0); gl_FragColor=finalColor; }
The problem is (on certain computers) everything drawn after this gets tinted according to the color array even though glDisableClientState(GL_COLOR_ARRAY); is called. If I were to change the red component on the color array, everything drawn after the color array is disabled has a red tint.
Is there a way to make sure GL_COLOR_ARRAY is really disabled besides what I am doing here?
Also, is there a better method to send per vertex information to a shader. I mainly need to the shader to know which vertices I want alpha modified while leaving all of the particles in the array.
Thanks!



.
