Why is this GLSL Vertex Shader not compiling?

I am writing my own shader with OpenGL, and I do not understand why this shader will not compile. Can anyone else take a look at it?

What I pass as the top are 2 floats (separated as bytes) in this format:

Float 1:

Byte 1: Position X
Byte 2: Position Y
Byte 3: Position Z
Byte 4: Texture Coordinate X


Float 2:

Byte 1: Color R
Byte 2: Color G 
Byte 3: Color B
Byte 4: Texture Coordinate Y

And this is my shader:

in vec2 Data;
varying vec3 Color;
varying vec2 TextureCoords;

uniform mat4 projection_mat;
uniform mat4 view_mat;
uniform mat4 world_mat;

void main() 
{
    vec4 dataPosition = UnpackValues(Data.x);
    vec4 dataColor = UnpackValues(Data.y);

    vec4 position = dataPosition * vec4(1.0, 1.0, 1.0, 0.0);
    Color = dataColor.xyz;

    TextureCoords = vec2(dataPosition.w, dataColor.w)

    gl_Position = projection_mat * view_mat * world_mat * position;
}

vec4 UnpackValues(float value)
{
    return vec4(value % 255, (value >> 8) % 255, (value >> 16) % 255, value >> 24);
}

If you need more information, I would be happy to complete it.

+5
source share
1 answer

You need to declare UnpackValuesbefore you call it. GLSL is similar to C and C ++; names must have a declaration before they can be used.


BTW: , , . - ; GLSL 4.00 (, "", , ), . , ; .

GLSL C ++ ( ).

, OpenGL, . vec4, :

glVertexAttribPointer(X, 4, GL_UNSIGNED_BYTE, GL_TRUE, 8, *);
glVertexAttribPointer(Y, 4, GL_UNSIGNED_BYTE, GL_TRUE, 8, * + 4);

vec4 . glVertexAttrib I, OpenGL , , float.

+10

All Articles