davek20
May 4th, 2008, 04:41 PM
Hey guys. I'm having some troubles setting up a vertex buffer objects (VBO) in OpenGL. At first I thought it had to something with how I was creating them, but now I'm starting to lean towards a driver issue (possibly). I'm using Ubuntu 8.04, my video card is a nVidia 7600GT and I am using the proprietary drivers.
At first the problem was with glDrawElements() since that was crashing my program. After a little investigation, that wasn't the overall problem. So basically what is happening is that my calls to glGenBuffers(1,&varName) are ALWAYS setting varName to 0, no matter how many times I call it (I even did an array assignment with glGenBuffers(10, varName) and all 10 elements were still 0). So in the code below, BOTH vertex_buf and index_buf are 0. Here is my create VBO code:
void CreateVBO(){
//create the vertices
vertices = new GLfloat[3 * 3];
vertices[0] = -5.0f; vertices[1] = -5.0f; vertices[2] = 40.0f; //vertex 1
vertices[3] = -5.0f; vertices[4] = 5.0f; vertices[5] = 40.0f; //vertex 2
vertices[6] = 5.0f; vertices[7] = -5.0f; vertices[8] = 40.0f; //vertex 3
// generate a new VBO and get the associated ID
glGenBuffers(1, &vertex_buf);
//HERE VERTEX_BUF IS 0!!!!
// bind VBO in order to use
glBindBuffer(GL_ARRAY_BUFFER, vertex_buf);
// upload data to VBO
glBufferData(GL_ARRAY_BUFFER, 3 * 3 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);
//create the indices
indices = new GLushort[3];
indices[0] = 0; indices[1] = 1; indices[2] = 2;
// generate a new VBO for the indices
glGenBuffers(1, &index_buf);
//HERE INDEX_BUF IS 0!!!!
// bind VBO in order to use
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buf);
// upload index data to VBO
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3 * sizeof(GLushort), indices, GL_STATIC_DRAW);
}
Also, here is some output from glxinfo:
direct rendering: Yes
OpenGL renderer string: GeForce 7600 GT/PCI/SSE2
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.3
OpenGL version string: 2.1.2 NVIDIA 169.12
Does anyone have an idea on what is wrong and how to fix it?
At first the problem was with glDrawElements() since that was crashing my program. After a little investigation, that wasn't the overall problem. So basically what is happening is that my calls to glGenBuffers(1,&varName) are ALWAYS setting varName to 0, no matter how many times I call it (I even did an array assignment with glGenBuffers(10, varName) and all 10 elements were still 0). So in the code below, BOTH vertex_buf and index_buf are 0. Here is my create VBO code:
void CreateVBO(){
//create the vertices
vertices = new GLfloat[3 * 3];
vertices[0] = -5.0f; vertices[1] = -5.0f; vertices[2] = 40.0f; //vertex 1
vertices[3] = -5.0f; vertices[4] = 5.0f; vertices[5] = 40.0f; //vertex 2
vertices[6] = 5.0f; vertices[7] = -5.0f; vertices[8] = 40.0f; //vertex 3
// generate a new VBO and get the associated ID
glGenBuffers(1, &vertex_buf);
//HERE VERTEX_BUF IS 0!!!!
// bind VBO in order to use
glBindBuffer(GL_ARRAY_BUFFER, vertex_buf);
// upload data to VBO
glBufferData(GL_ARRAY_BUFFER, 3 * 3 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);
//create the indices
indices = new GLushort[3];
indices[0] = 0; indices[1] = 1; indices[2] = 2;
// generate a new VBO for the indices
glGenBuffers(1, &index_buf);
//HERE INDEX_BUF IS 0!!!!
// bind VBO in order to use
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buf);
// upload index data to VBO
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3 * sizeof(GLushort), indices, GL_STATIC_DRAW);
}
Also, here is some output from glxinfo:
direct rendering: Yes
OpenGL renderer string: GeForce 7600 GT/PCI/SSE2
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.3
OpenGL version string: 2.1.2 NVIDIA 169.12
Does anyone have an idea on what is wrong and how to fix it?