Error with shaders - OpenGL

Started by
19 comments, last by sn0k3 8 years, 7 months ago

@Gooey My wrong.. :D I've pasted it wrong..

It should be:

    std::string vertSourceString = FileUtils::read_file(m_VertPath);
    const char* vertSource = vertSourceString.c_str();
        glShaderSource(vertex, 1, &vertSource, NULL);

But I've posted this:

        std::string vertSourceString = FileUtils::read_file(m_VertPath);
        std::string fragSourceString = FileUtils::read_file(m_FragPath);

        const char* vertSource = FileUtils::read_file(m_VertPath).c_str();
        const char* fragSource = FileUtils::read_file(m_FragPath).c_str();

        glShaderSource(vertex, 1, vertSourceString.c_str(), NULL);

So other thing, when I put cout to print the fragSource of FragSourceString

       std::cout << "Fragment source file: " << fragSource << std::endl;

this prints the content of the shader..

Advertisement

Other error:

Fragment shader failed to compile with the following errors:
ERROR: 0:11: error(#143) Undeclared identifier: gl_Position
WARNING: 0:11: warning(#402) Implicit truncation of vector from size: 4 to size:
1
ERROR: error(#273) 1 compilation errors. No code generated

Any ideas why?

They sound simple enough put your frag shader code here.
A hint though gl_Position cant be used in frag shader only vertex i believe by the sound of it you are trying to pass a float out instead of a vec4

Hello guys!

When I compile there is an error, which says:

Failed to compile shader!
Vertex shader failed to compile with the following errors:
ERROR: 0:1: error(#132) Syntax error: "<" parse error
ERROR: error(#273) 1 compilation errors. No code generated

Here you go my vertex shader:


#version 330 core

layout (location = 0) in vec4 position;

uniform mat4 pr_matrix = mat4(1.0);
uniform mat4 vw_matrix = mat4(1.0);
uniform mat4 ml_matrix = mat4(1.0);

void main()
{
    gl_Position = position;
}

Any ideas?

It is valid GLSL code to initialize the uniforms within the shader? Never mind. I really need to Google how to use this Google thing...

Frag shader:

#version 330 core

layout (location = 0) out vec4 color;


void main()
{
    color = vec4(1.0, 1.0, 1.0, 1.0);
}

The vert shader is up.

i think you need to look up how the shaders work try changing your layout(location = 0) out vec4 position to out vec4 color;

I changed it, but still the same error!

so your shaders look like this?

vertex shader


#version 330 core

layout (location = 0) in vec4 position;

uniform mat4 pr_matrix = mat4(1.0);
uniform mat4 vw_matrix = mat4(1.0);
uniform mat4 ml_matrix = mat4(1.0);

void main()
{
gl_Position = position;
}

frag shader


#version 330 core

out vec4 color;


void main()
{
color = vec4(1.0, 1.0, 1.0, 1.0);
}

Same error.

but is that what your shaders look like? or have you got something different and what same error gl_Position?

This topic is closed to new replies.

Advertisement