I am trying to display a simple triangle with OpenGL (I am using freeglut3-dev and libglew1.6 on Ubuntu 12.04 and coding in NetBeans 7.2). The code compiles and links with no problems, but displays only a blank screen (with initialized colour) but only a single white point at the origin (instead of 3 points for each of the triangle vertices). My code is below:
#include <stdio.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include "math_3d.h"
GLuint VBO;
static void RenderSceneCB()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glutSwapBuffers();
}
static void InitializeGlutCallbacks()
{
glutDisplayFunc(RenderSceneCB);
}
static void CreateVertexBuffer()
{
Vector3f Vertices[3];
Vertices[0] = Vector3f(-1.0f, -1.0f, 0.0f);
Vertices[1] = Vector3f(1.0f, -1.0f, 0.0f);
Vertices[2] = Vector3f(0.0f, 1.0f, 0.0f);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(1024, 768);
glutInitWindowPosition(100, 100);
glutCreateWindow("Tutorial 03");
InitializeGlutCallbacks();
// Must be done after glut is initialized!
GLenum res = glewInit();
if (res != GLEW_OK) {
fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
return 1;
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
CreateVertexBuffer();
glutMainLoop();
return 0;
}
Here is a screenshot of what I see:

Here is a picture of what it should look like:

I am following this tutorial. Vector3f is just a structure with three data members: x, y, z.
Read the next chapter of the tutorial, it explains it all.
A vertex is simply a set of attributes, which are referenced by their number (0 in your case). This number however doesn’t tell the GL what the data are, and thus how to use them. With the old API you had specific vertex specification functions for each attribute;
glVertexPointer()was used to provide position attributes,glTexCoordPointer()texture coordinates, etc. Today it is up to you to use the attributes the way you want, through shaders, which are explained in the next chapter of your tutorial.