Could not bind attribute

I’m now starting to learn Opengl tutorials from Wikibooks[OpenGL Programming - Wikibooks, open books for an open world]. In the tutorial 02[OpenGL Programming/Modern OpenGL Tutorial 02 - Wikibooks, open books for an open world]. They taught to use VBO’s. I did and the code compiles succesfully. but when I execute the program. the attribute “coord2d” from vertex shader is not able to bind with the “attribute_coord2d”. look at the bold faced code segment.

here is the code

GLuint program;
GLint attribute_coord2d;
GLint  link_ok = GL_FALSE; 
GLint vbo_triangle;

int init_resources(void)

  GLuint vs = create_shader("triangle_01.vs.glsl",GL_VERTEX_SHADER);
  GLuint fs = create_shader("triangle_01.fs.glsl",GL_FRAGMENT_SHADER);

  program = glCreateProgram();
  glAttachShader(program, vs);
  glAttachShader(program, fs);
  glGetProgramiv(program, GL_LINK_STATUS, &link_ok);
  if (!link_ok) {
    fprintf(stderr, "glLinkProgram:");
    return 0;

  GLfloat triangle_vertices[] = {
     0.0,  0.8,
    -0.8, -0.8,
     0.8, -0.8,

    attribute_coord2d, // attribute
    2,                 // number of elements per vertex, here (x,y)
    GL_FLOAT,          // the type of each element
    GL_FALSE,          // take our values as-is
    0,                 // no extra data between each position
    triangle_vertices  // pointer to the C array
  glBindBuffer(GL_ARRAY_BUFFER, vbo_triangle);
	       triangle_vertices, GL_STATIC_DRAW);
  const char* attribute_name = "coord2d";
  attribute_coord2d = glGetAttribLocation(program, attribute_name);
  if (attribute_coord2d == -1) {
    fprintf(stderr, "Could not bind attribute %s
", attribute_name);
    return 0;

// Enable alpha
  return 1;

and the vertex shader code is:

attribute vec2 coord2d;
void main(void) {
  gl_Position = vec4(coord2d, 0.0, 1.0);

You seem to be missing a call to


[QUOTE=tonyo_au;1245045]You seem to be missing a call to


I added this like immediately below the
glBindBuffer(GL_ARRAY_BUFFER, vbo_triangle);

but it doesn’t work either? where do I place it.

I do glVertexAttribPointer and glEnableVertexAttribArray after the bind. The bind say what object to apply these states to.