0

I have a fragment shader, it has structs and a uniform of those structs. When I tried to compile them, OpenGL gave me this error:

0(30) : error C0000: syntax error, unexpected identifier, expecting '{' at token "lights_a"
0(31) : error C0000: syntax error, unexpected identifier, expecting '{' at token "material"

I don't know what the problem is here. I have been searching for the problem... I looked at line 30 and 31, I did everything I could imagine, but without success.

Here is the code:

#version 330 core
struct LightBase
{
    int renderit;

    vec4 ambient_light;
    vec4 specular_light;
    vec4 diffuse_light;

    float radius;

    vec3 light_position;
    vec3 light_direction;

    int light_type;
};

struct MaterialBase
{
    vec4 ambient_affect;
    vec4 specular_affect;
    vec4 diffuse_affect;
    float shining;

    float mirror;

    int light_affect;
};

in vec3 VertexPos;
in vec3 Normal;
uniform int light_quantity;
uniform LightBase lights_a[50];
uniform MaterialBase material;
uniform float usingTex;
uniform sampler2D texturemap;
in vec2 UVs;
in vec4 Colors;
out vec4 color;

void main() {

    vec4 texture_u = texture(texturemap,UVs).rgba * usingTex;
    vec4 color_u = Colors * (1.0f-usingTex);

    vec4 final_color = color_u+texture_u;
    // Light
    for(int i=0;i<light_quantity;i++) {
        if(lights_a[i].renderit==1) {
            if(lights_a[i].light_type==1) {

                float attenuation = max(0.0,1.0-dot(lights_a[i].light_direction,lights_a[i].light_direction));

                vec3 L = normalize(lights_a[i].light_direction);
                vec3 N = normalize(Normal);
                vec3 V = normalize(-VertexPos);
                vec3 R = normalize(-reflect(L,N));

                float nDotL = max(0.0,dot(N,L));
                float rDotV = max(0.0,dot(R,V));

                float ambient_result = lights_a[i].ambient_light * material.ambient_affect * attenuation;
                float diffuse_result = lights_a[i].diffuse_light * material.diffuse_affect * nDotL * attenuation;
                float specular_result = lights_a[i].specular_light * material.specular_affect * pow(rDotV,material.shining) * attenuation;

                vec4 this_colour = (ambient_result + diffuse_result + specular_result) * final_color;
                    final_color = this_colour;
            }
    }
    }


    color = final_color;
}

What's wrong about the code?

0

1 Answer 1

3

I don't see an error when I compile your code -- only a couple of warnings:

0(62) : error C7011: implicit cast from "vec4" to "float"
0(63) : error C7011: implicit cast from "vec4" to "float"
0(64) : error C7011: implicit cast from "vec4" to "float"

I can almost reproduce the error you see by commenting out the declarations of struct LightBase and struct MaterialBase -- except they show up on lines 33 and 34. which are the lines with the noted tokens lights_a and material

This leads me to believe that your problem is that you're not actually compiling the program you think you are. Perhaps you're reading it from a file into memory, but the memory gets corrupted somehow before you call glShaderSource...

Sign up to request clarification or add additional context in comments.

3 Comments

I'll check the data located in the memory (it's a const char*).
The data is fine, and the structs are not commented.... This should not be happening, this is weird...
Yes, I found the error... Actually the data was damaged... It seems right, but it wasn't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.