PDA

View Full Version : problem with glBufferData



bug343
05-23-2013, 11:39 PM
I am writing a hello world that draws a simple triangle and trying out VAO.





GLuint vbo;
GLuint vao;

.....

//initialize vertex data
const GLfloat vertices[] = {
0.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 1.0, 0.0
};



glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, 36, vertices, GL_STATIC_DRAW); //becomes unresponsive at this point


Am I doing something absurdly wrong here for glBufferData to fail? I use cout statements after each of the gl calls to figure out where it fails and it failed at glbufferData. But as far as my beginner senses tell me I can see nothing wrong with it.

Your help is appreciated. Previously I used the old method (not VAO) so I am new to this.

tonyo_au
05-24-2013, 02:16 AM
check for an opengl error prior to this code with glGetError();

bug343
05-24-2013, 01:42 PM
glGetError returns 0 when called before that snippet. The terminal does not respond so I cannot see what glGetError returns.

But, the following seems to work:



GLfloat vertices[9];
vertices[0] = 1.0;
vertices[1] = 2.0;
vertices[2] = 3.0;
vertices[3] = 4.0;
vertices[4] = 5.0;
vertices[5] = 6.0;
vertices[6] = 7.0;
vertices[7] = 8.0;
vertices[8] = 9.0;
....
....

glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);


As far as I know the arrays I made are equal and the third parameter to glBufferData which is the pointer to the start of the array is passed similarly. It seems like using the array initializer feature of C++ does not work for my implementation with VC2010.

Any clues why?

tonyo_au
05-24-2013, 10:26 PM
You have an error elsewhere in your program. I pasted your code into a test program and it worked fine. I suggest you have a some sort of array overrun.

bug343
05-24-2013, 11:40 PM
You have an error elsewhere in your program. I pasted your code into a test program and it worked fine. I suggest you have a some sort of array overrun.

Thankyou for the replies