0
\$\begingroup\$

I am new to shaders, and I am trying to tint a texture to mark status of a enemy.

I am implementing shaders on OpenGL ES 2.0 (Mobile)

The problem is that with this shaders, I see the enemy without change (even if I assign de fragcolor to (1.0, 0 , 0 ,1.0), the real code is commented).

Vertex shader

uniform mat4 u_MVPMatrix;       // A constant representing the combined model/view/projection matrix.                  
uniform mat4 u_MVMatrix;        // A constant representing the combined model/view matrix.              


attribute vec4 a_Position;      // Per-vertex position information we will pass in.                             
attribute vec3 a_Normal;        // Per-vertex normal information we will pass in.      
attribute vec2 a_TexCoordinate; // Per-vertex texture coordinate information we will pass in.       

varying vec3 v_Position;        // This will be passed into the fragment shader.                            
varying vec3 v_Normal;          // This will be passed into the fragment shader.  
varying vec2 v_TexCoordinate;   // This will be passed into the fragment shader.            

// The entry point for our vertex shader.  
void main()                                                     
{                                                         
    // Transform the vertex into eye space.     
    v_Position = vec3(u_MVMatrix * a_Position);                 

    // Pass through the texture coordinate.
    v_TexCoordinate = a_TexCoordinate;                                   

    // Transform the normal's orientation into eye space.
    v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0));

    // gl_Position is a special variable used to store the final position.
    // Multiply the vertex by the matrix to get the final point in normalized screen coordinates.
    gl_Position = u_MVPMatrix * a_Position;                               
}    

Fragment shader

precision mediump float;        // Set the default precision to medium. We don't need as high of a 
                                // precision in the fragment shader.
uniform sampler2D u_Texture;    // The input texture.

varying vec3 v_Position;        // Interpolated position for this fragment.
varying vec3 v_Normal;          // Interpolated normal for this fragment.
varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.

// The entry point for our fragment shader.
void main()                         
{                              

    vec4 texVal = texture2D(u_Texture, v_TexCoordinate);
    gl_FragColor = (1.0, 0 , 0 ,1.0);//vec4(texVal.rgb, texVal.a)*(1.0, 0 , 0 ,1.0);

}    
\$\endgroup\$
4
  • 2
    \$\begingroup\$ Do you have a way to verify that your shader is compiling correctly? Perhaps there is a syntax error with your shader program and the fixed function pipeline is being run instead of the shader. \$\endgroup\$
    – Shadow503
    Jan 19, 2016 at 15:44
  • \$\begingroup\$ They compile without problems, maybe if I dont pass the correct parameters it just use the fixed pipeline? \$\endgroup\$
    – D4rWiNS
    Jan 19, 2016 at 15:51
  • \$\begingroup\$ @D4WiNS Can you try adding "vec4" to the gl_FragColor line? \$\endgroup\$
    – Shadow503
    Jan 19, 2016 at 15:59
  • \$\begingroup\$ I'm voting to close this question as off-topic because it came out to be a simple mistake. \$\endgroup\$
    – Kromster
    Jan 20, 2016 at 8:34

1 Answer 1

3
\$\begingroup\$

The problem was there

 gl_FragColor = (1.0, 0 , 0 ,1.0);//vec4(texVal.rgb, texVal.a)*(1.0, 0 , 0 ,1.0);

it miss the vec4 name

 gl_FragColor = vec4(1.0, 0 , 0 ,1.0);//vec4(texVal.rgb, texVal.a)*vec4(1.0, 0 , 0 ,1.0);
\$\endgroup\$
2
  • \$\begingroup\$ Looks like you found it! :) \$\endgroup\$
    – Shadow503
    Jan 19, 2016 at 16:00
  • 1
    \$\begingroup\$ Yes! you help me anyway since I was also loading the wrong shaders! :P \$\endgroup\$
    – D4rWiNS
    Jan 19, 2016 at 16:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .