Hello All,

I was mostly using the old glBegin() method for a long time. Now, im learning to use modern ways of specifying vertices. Here is some sample code i found online. I modified a little:
What i tried to do is, in the same VBO, use color values also:

Code :
static const char* pVS = "                                                    \n\
#version 330                                                                  \n\
                                                                              \n\
layout (location = 0) in vec3 Position;                                       \n\
layout (location = 1) in vec3 Col;                                            \n\
out vec3 col_out;                                                             \n\
                                                                              \n\
void main()                                                                   \n\
{                                                                             \n\
    gl_Position = vec4(0.5 * Position.x, 0.5 * Position.y, Position.z, 1.0);  \n\
    col_out = Col;                                                            \n\
}";
 
static const char* pFS = "                                                    \n\
#version 330                                                                  \n\
                                                                              \n\
out vec4 FragColor;                                                           \n\
in vec3 col_out;                                                              \n\
                                                                              \n\
void main()                                                                   \n\
{                                                                             \n\
   FragColor = vec4(col_out, 1.0);                                            \n\
}";
 
 
typedef struct {
   Vector3f vert;
   Vector3f col;
} Vertex;
 
Vertex Vertices[3];
 
static void RenderSceneCB()
{
    glClear(GL_COLOR_BUFFER_BIT);
 
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
 
    glEnableVertexAttribArray(1);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), &(Vertices[0].col));
 
    glDrawArrays(GL_TRIANGLES, 0, 3);
 
    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);
 
    glutSwapBuffers();
}
 
 
static void InitializeGlutCallbacks()
{
    glutDisplayFunc(RenderSceneCB);
}
 
static void CreateVertexBuffer()
{     
 
    Vertices[0].vert = Vector3f(-1.0f, -1.0f, 0.0f);
    Vertices[0].col = Vector3f(1.0f, 0.0f, 0.0f);
 
    Vertices[1].vert = Vector3f(1.0f, -1.0f, 0.0f);
    Vertices[1].col  = Vector3f(1.0f, 0.0f, 0.0f);
 
    Vertices[2].vert = Vector3f(0.0f, 1.0f, 0.0f);
    Vertices[2].col  = Vector3f(1.0f, 0.0f, 0.0f);
 
     glGenBuffers(1, &VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
}


Here is the essential part. But i get a blank screen. Can anyone please let me know what i'm doing wrong?

Thanks in advance!