I am working on a code where I need to set the color of my objects, in all vertices and I also draw text, using textures, where the text colors are indexed colors which are loaded in a table, using uniform vec4 array, in the shader.
The colors don't show up correctly, some are OK, many not.
Here is the code of my shaders :
Code: Select all
char vShaderStr[] =
"attribute vec3 vPosition;\n"
"attribute vec2 a_st;\n"
"attribute vec4 a_color;\n"
"attribute float a_colorindex;\n"
"uniform vec4 u_colorset[32];\n"
"uniform mat4 u_mvp;\n"
"varying vec2 v_frag_uv;\n"
"varying vec4 v_textcolor;\n"
"varying vec4 v_color;\n"
"void main()\n"
"{\n"
" v_frag_uv = a_st;\n"
" gl_Position = u_mvp * vec4(vPosition,1); \n"
" v_color = a_color;\n"
" int idx = int(a_colorindex);\n"
" v_textcolor = u_colorset[idx];\n"
"}\n";
char fShaderStr[] =
"uniform sampler2D texture_uniform;\n"
"uniform float textureFlag;\n"
"varying vec4 v_color;\n"
"varying vec4 v_textcolor;\n"
"varying vec2 v_frag_uv;\n"
"void main()\n"
"{\n"
" vec4 c1 = vec4(v_textcolor.xyz, v_textcolor * texture2D(texture_uniform, v_frag_uv).a);\n"
" vec4 c2 = v_color;\n"
" vec4 c;\n"
" if (textureFlag > 0.5) \n"
" c = c1;\n"
" else \n"
" c = c2;\n"
" gl_FragColor = c;\n"
"}\n";
All attributes are located using :
Code: Select all
m_vertexHandle = glGetAttribLocation ( state->programObject, "vPosition" );
m_colorHandle = glGetAttribLocation ( state->programObject, "a_color" );
m_colorIndexHandle = glGetAttribLocation ( state->programObject, "a_colorindex" );
m_colorTableHandle = glGetUniformLocation(state->programObject,"u_colorset");
m_texHandle = glGetAttribLocation ( state->programObject, "a_st" );
m_texflag = glGetUniformLocation(state->programObject,"textureFlag");
m_samplerHandle = glGetUniformLocation( state->programObject, "texture_uniform" );
colors[] = (r1,g1,b1,a1, ......, r32,g32,b32,a32);
Code: Select all
glUniform4fv(m_colorTableHandle, 128, colors);