PDA

View Full Version : GLSL VBO colour not coming through



WickedP
07-30-2015, 08:34 PM
Hi folks,

I've got the following code regarding a draw and a custom shader:



// a bunch of uniforms are set here, they work fine

// I've tried things like this:
glBindBuffer(GL_ARRAY_BUFFER,My_VBO[i].first[1]);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof (float)*3,0);

// and this:
int loc = glGetAttribLocation(Shader_id,"Colour_In");
glEnableVertexAttribArray(loc);
glVertexAttribPointer(loc,3,GL_FLOAT,GL_FALSE,0,0) ;

// and other variations, including some argument variations


and the stripped down shader (non-colour related objects/code removed):



#version 440

layout(location = 0) in vec3 Colour_In;
out vec4 Colour;

void main()
{
Colour = vec4(Colour_In,1.0);
}


The short of it is I only get a black rendered plane. I'm confident the colour data is good, I can print some of it's values before making it a VBO. I think it drew fine under the fixed pipeline before trying to make my own shader as well. Other than that, no errors are reported anywhere that I can find. Where am/could I be going wrong here?

Kind regards,

WP.

GClements
07-31-2015, 12:05 AM
The first set of calls specifies the data for attribute zero. The second set specifies the data for the Colour_In attribute. Your shader then specifies (via "layout(location=0)")that Colour_In is attribute zero. Also, both attribute arrays read from offset zero of the same buffer.

Or maybe you've omitted substantial information from your post? In which case, don't do that. If the code is too large to post in its entirety, simplify it to a minimal version which still exhibits the problem.

WickedP
07-31-2015, 06:03 AM
Hi GClements,

this is the complete for loop I'm using to draw with:



glUseProgram(Shader_id);
glUniformMatrix4fv(glGetUniformLocation(Shader_id,"SetMatrix"),1,GL_FALSE,&workingMatrix[0][0]);

for(int i = 1; i <= My_VBO.size()-1;)
{
glUniform1f(glGetUniformLocation(Shader_id,"Colour_Type"),(float)My_VBO_Data[i].Colour_Type);
glUniform1f(glGetUniformLocation(Shader_id,"Width"),(float)My_VBO_Data[i].Width);
glUniform1f(glGetUniformLocation(Shader_id,"Height"),(float)My_VBO_Data[i].Height);
glUniform1f(glGetUniformLocation(Shader_id,"Half_Width"),(float)(My_VBO_Data[i].Width / 2.0));
glUniform1f(glGetUniformLocation(Shader_id,"Half_Height"),(float)(My_VBO_Data[i].Height / 2.0));

glBindBuffer(GL_ARRAY_BUFFER,My_VBO[i].first[1]);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof (float)*3,0);

glDrawArrays(GL_POINTS,0,My_VBO_Data[i].Width * My_VBO_Data[i].Height);
glBindBuffer(GL_ARRAY_BUFFER,0);

i++;
}

glUseProgram(0);


I've removed a bunch of commented lines, variations etc that I had tried. Here's the shader in it's 'whole':



#version 440

layout(location = 0) in vec3 Colour_In; // data varies
uniform mat4 SetMatrix; // all good
uniform int Colour_Type; // all good, but not used
uniform float Width; // all good
uniform float Height; // all good
uniform float Half_Width; // all good
uniform float Half_Height; // all good

out vec4 Colour;

void main()
{
...position calculated here, not using vbo - completely shader driven...

Colour = vec4(Colour_In,1.0);
//Colour = vec4(0.0,1.0,0.0,1.0);
}

// just in case, fragment shader:

#version 440

in vec4 Colour;
out vec4 f_Colour;

void main()
{
f_Colour = Colour;
}


With regards to the 'data varies' comment, sometimes it comes out red, sometimes green, other times black (mostly). All vertexes are the same colour though, so there's never any variations in them. The colour data is the only VBO in use (or, that I'm trying to use!). Any further thoughts? Need more code (not sure what else I can post to be honest!)?

WP.

tkausl
07-31-2015, 07:01 AM
E: Can you post some more of your position-calculating code? Are you sure this part works?

WickedP
08-03-2015, 03:25 AM
Hi tkausl,

I can see the position code working - I can adjust it manually (I have a real-time shader text editor). It's just the colour not coming through.

Is it possible my card doesn't support v4.4? Or wouldn't the position draw (or any of it for that matter) be working if that were the case?

WP.

WickedP
08-05-2015, 04:44 AM
OK, I've managed to solve it. It was an issue with the way I was setting up the buffer object and the data. All good!

Thanks folks,

WP.