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);
  glLinkProgram(program);
  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,
  };

 glVertexAttribPointer(
    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
  );
  
  glGenBuffers(1,&vbo_triangle);
  glBindBuffer(GL_ARRAY_BUFFER, vbo_triangle);
  glBufferData(GL_ARRAY_BUFFER,sizeof(triangle_vertices),
	       triangle_vertices, GL_STATIC_DRAW);
  
[b]
  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;
  }[/b]

// Enable alpha
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_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

glEnableVertexAttribArray(attribute_coord2d);

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

glEnableVertexAttribArray(attribute_coord2d);[/QUOTE]

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.