0
votes

So i cant get my shader to render with color. My shader works when i dont set the color using the attribute Color. my code for vertex is:

typedef struct
{
   GLKVector3 Position;         //Position
   GLKVector4 Color;        //32 Bit color
   GLKVector3 Normal;       //For Lighting
   GLKVector2 TexCoord;         //For Texturing
} Vertex;

I have given the colors for all vertices as [1,0,0,1] My vertex shader is this:

attribute vec3 Position;
attribute vec4 Color;
attribute vec3 Normal;
attribute vec2 TexCoord;
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
varying vec4 DestinationColor;
void main(void)
{
    gl_Position = ProjectionMatrix*ModelViewMatrix*vec4(Position,1);
    DestinationColor = Color;
}       

And my Fragment Shader is this:

precision mediump float;
varying lowp vec4 DestinationColor; 
void main (void)  
{     
     gl_FragColor =DestinationColor;
}    

And it Displays nothing.

It doesnt even work if i change the fragment shader to say gl_FragColor = vec4(1,0,0,1); Unless i uncomment the line in vertex shader setting the DestinationColor.

Please help i have been sitting on this for a while now

1
I can't see anything wrong with what you are doing. Are you checking the error log from your shader & program compilation?combinatorial
Yes it completes without errors and runs finebobjamin
Try using the very same declaration for the varying in both shaders (do not use different precision qualifiers in both shaders).derhass

1 Answers

0
votes

I found the answer to this problem but i can't access my old account for bobjamin so I am using this new one. The solution was fairly simple. Firstly i should mention that drhass' suggestion did help in that it allowed me to set a static color from the vertex shader and it would display however the problem was that the name Color must be a reserved keyword and its was causing problems.

The Answer was to change the attribute Color to SourceColor and everything worked fine!