Click here to Skip to main content
15,884,969 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I am using shaders in QT 5.2. I am following phong shading model.
When I compile my shading code, it is showing some errors like
VB
ERROR: 0:70: '<' : syntax error syntax error\n\n
ERROR: 0:35: '<' : syntax error syntax error\n\n
ERROR: 0:25: '<' : syntax error syntax error\n\n
ERROR: 0:24: '<' : syntax error syntax error\n\n

but my part color and background color are becoming dark purple.

can anyone help me in fixing this.

shaders code

vertex shader code
C#
void main()
{
   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
   float f1 = 1.0;
   vec4 eyePosition = gl_ModelViewMatrix * gl_Vertex;
   vec4 eyeLightPos = gl_LightSource[0].position;
   vec3 N = -normalize(gl_NormalMatrix *gl_Normal);
   vec3 L = -normalize(eyeLightPos.xyz - eyePosition.xyz );
   vec3 E = -normalize(eyePosition.xyz);
   vec3 H = normalize(L + E);
   float kd = max(dot(L, N), 0.0);
   float ks = pow(max(dot(N,H),0.0), gl_FrontMaterial.shininess);
    if(dot(L,N)<0.0) f1=0.0;
   vec4 ambient = gl_FrontLightProduct[0].ambient;
   vec4 diffuse = 2.0*kd * gl_FrontLightProduct[0].diffuse;
   vec4 specular = 2.0*f1 * ks * gl_FrontLightProduct[0].specular;
    gl_FrontColor = 2.0*(ambient + diffuse + specular);
}


fragment shader code

C#
void main(void)
{
    gl_FragColor =  gl_Color;
}



And InitializeGL()

C#
void DisplayControlBase::initializeGL()
{
    InitializeGLSettings();
    setFocus();
    setFocusPolicy(Qt::WheelFocus);
    GLchar vShaderFile[] = "myVertexShader.glsl";
    GLchar fShaderFile[] = "myFragmentShader.glsl";

    GLchar *vSource, *fSource;
    vSource = readShaderSource(vShaderFile);
    fSource = readShaderSource(fShaderFile);

    initializeOpenGLFunctions();

    GLuint myProgObj;

    myProgObj = glCreateProgram();
    GLuint vShader, fShader;
    vShader = glCreateShader(GL_VERTEX_SHADER);
    fShader = glCreateShader(GL_FRAGMENT_SHADER);
    glAttachShader(myProgObj, vShader);
    glAttachShader(myProgObj, fShader);
    glShaderSource(vShader, 1, (const GLchar**) &vSource, NULL);
    glShaderSource(fShader, 1, (const GLchar**) &fSource, NULL);

    glCompileShader(vShader);
    glCompileShader(fShader);
    GLint status;
    glGetShaderiv(fShader, GL_COMPILE_STATUS, &status);

    CheckError(status, fShader);
    glGetShaderiv(vShader, GL_COMPILE_STATUS, &status);
    CheckError(status, vShader);
    glLinkProgram(myProgObj);
    glUseProgram(myProgObj);
    glGetProgramiv(myProgObj, GL_LINK_STATUS, &status);
    CheckError(status, myProgObj);

}


C#
void DisplayControlBase::CheckError(GLint CompileStatus, GLuint Shader)
{
    if (!CompileStatus)
    {
        int iLength, iChars;
         glGetShaderiv(Shader, GL_INFO_LOG_LENGTH, &iLength);

        char* pInfoLog = new char[iLength];
        glGetShaderInfoLog(Shader, iLength, &iChars, pInfoLog);

        delete [] pInfoLog;
    }
}

C#
char* DisplayControlBase::readShaderSource(const char *shaderFile)
{
    FILE *fp = fopen(shaderFile, "r");
    char* buffer;
    long size;
    if( fp == NULL) return(NULL );
    fseek(fp, 0L, SEEK_END);
    size = ftell(fp);
    fseek(fp, 0L, SEEK_SET);
    buffer = (char*)malloc((size + 1)* sizeof(char));
    fread(buffer, 1, size, fp);
    buffer[size] = ' ';
    fclose(fp);
    return buffer;
}
Posted
Updated 6-Jun-14 0:40am
v2
Comments
Richard MacCutchan 6-Jun-14 6:07am    
Please indicate which lines the error messages refer to.
Madhan Mohan Reddy P 6-Jun-14 6:35am    
Hi MacCutchan,
Thanks for responding.
The error it is referring to shaders code.
It is referring to the last line of my shaders.
Actually in that line nothing is there. suppose my main() function ends in the line 35 with '}' it is showing error in the 36th line
Richard MacCutchan 6-Jun-14 8:56am    
The only possibility that I can see is
if(dot(L,N)<0.0) f1=0.0;
but I don't understand why it is a syntax error, and according to my count that is line 13. I suspect there is some information that you are not showing us. Try commenting that line and see what happens.
Madhan Mohan Reddy P 9-Jun-14 1:47am    
Hi MacCutchan,
Nothing is happening if I comment that line. Same error is coming.
I gave my entire code block.
Richard MacCutchan 9-Jun-14 3:51am    
You still have not told us where the error occurs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900