Colouring verticies vbos/shaders

Started by
13 comments, last by dpadam450 11 years, 10 months ago
Can you also add the other .bindAttrib() after the calls below in your draw? Is that where you put it before? Because you have to bind it every single frame unless you use this shader for everything. If at any point the current shader is switched to another shader, OR if it is unbound to not use a shader at all, you have to resend everything to set it up again?
shader.sendUniform("projection_matrix", projMatrix);
shader.sendUniform("modelview_matrix", modelMatrix);

Other than that I have no suggestions.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Advertisement
This shader is the only one being used yea, its nothing more than a demo to learn about GLSL... what a road block at step one sad.png

I'm curious is everyone else getting the flashing triangle if they run the app?

I tried to change to shaders abit. First I changed the frag shader


in vec4 in_colour;

out vec4 out_colour;

void main(void)
{
out_colour = in_colour;
}



to


in vec4 in_colour;

out vec4 out_colour;

void main(void)
{
out_colour = vec4(1.0, 1.0, 0.0, 1.0);
}



The output was then a yellow triangle (no flickering in the colour)

I then tried a second experiment with changing the vertex shader. (after i changed the fragment shader back)

from


uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;

in vec3 in_vertex;
in vec3 in_colour;

out vec4 out_colour;

void main(void)
{
gl_Position = projection_matrix * modelview_matrix * vec4(in_vertex, 1.0);
out_colour = vec4(in_colour, 1.0);
}


to


uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;

in vec3 in_vertex;
in vec3 in_colour;

out vec4 out_colour;

void main(void)
{
gl_Position = projection_matrix * modelview_matrix * vec4(in_vertex, 1.0);
out_colour = vec4(1.0, 1.0, 0.0, 1.0);
}


This resulted in the original colour flickering. Does this mean anything to you? Maybe I wrote the fragment shader wrong? Does it look right to you? Its like the fragment shader is changing the colour even though all I do is take the input for the output.
Your vertex shader outputs "out_colour", but your fragment shader gets in "in_colour". They should have the same name. And btw the plural of vertex is vertices.

Derp

Thank you, the naming issue was the problem. TY for all the help.
Two things that will help you:
Unless I #version 400, my GTS450 complains about this for the layout keyword. Try using that, if it works keep it.
[ >> ] 0(6) : error C0000: syntax error, unexpected '(', expecting "::" at token "("

Secondly, I modified your code:
This only takes into account errors from the vertex shader, but add it in for the fragment shader as well. It appears you aren't outputting
shader compile errors anywhere.
if (!compileShader(m_vertexShader) || !compileShader(m_fragmentShader))
{
std::string log;

GLchar *debug;
GLint debugLength;
glGetShaderiv( m_vertexShader.id, GL_INFO_LOG_LENGTH, &debugLength);

debug = new GLchar[debugLength];
glGetShaderInfoLog(m_vertexShader.id, debugLength, &debugLength, debug);

log.append(debug,0,debugLength);
std::cout << debug;

LOG->Send("Could not compile the shaders, they are invalid");
LOG->Send(debug);
return false;
}

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement