Passing vertex attributes to vertex shaders

So I’ve recently been messing around with GLSL and wrote a simple pair of vertex/fragment shaders as a test for vertex attributes. Here they are:

Vertex:

#version 330

layout (location = 0) in vec2 VertexPosition;
layout (location = 1) in vec3 VertexColor;

out vec3 Color;

void main(){
Color = VertexColor;
gl_Position = vec4(VertexPosition, 0.0, 1.0);

}

Fragment:

#version 330

out vec4 FragColor
in vec3 Color;

void main(){
FragColor = vec4(Color, 1.0);

}

I pass in the vertex attributes like this:

shader.bind();

glEnableVertexAttribArray(0);
//Map index 0 to the position buffer
glBindBuffer(GL_ARRAY_BUFFER, vboVertexBuffer);
glBindAttribLocation(shader.getProgram(), 0, “VertexPosition”); //not sure if this line’s necessary
glVertexAttribPointer(0, 2, GL_FLOAT, false, 2*4, 0);
glDisableVertexAttribArray(0);

glEnableVertexAttribArray(1);
//Map index 1 to the color buffer
glBindBuffer(GL_ARRAY_BUFFER, vboColorBuffer);
glBindAttribLocation(shader.getProgram(), 1, “VertexColor”);
glVertexAttribPointer(1, 3, GL_FLOAT, false, 3*4, 0);
glDisableVertexAttribArray(1);

shader.unbind();

shader.compile(); //links and validates the shader

I run it and get a black screen. What a wonderful thing GLSL is that it can produce such beautiful black screens xD. I have this colored triangle I rendered with VBO that renders without the shader, but not with the shader. Any ideas on why?

There is no need to use [icode]glBindAttribLocation()[/icode] if you are using layout in the shaders.

Compile the shader before binding the vertex attributes?
Post the rendering code as well.

I recommend to give a read to my articles.

http://goharsha.com/lwjgl-tutorial-series/encapsulating-shaders/
http://goharsha.com/lwjgl-tutorial-series/the-first-triangle/