Hello, I’ve been using OpenGL for well over a year now. I’m fairly comfortable with it, and I’ve always been able to diagnose issues myself, but this one just has me completely lost. While writing some very basic code my program continuously crashes while executing glDrawArrays under certain circumstances. Here are a few basic examples. In this scenario I’m just trying to draw a single point for debug proposes. This point is a VBO defined as follows:
float data[3] = {1.0F, 1.0F, 1.0F};
glGenBuffers(1, &vboSquare);
glBindBuffer(GL_ARRAY_BUFFER, vboSquare);
glBufferData(GL_ARRAY_BUFFER, 3*sizeof(float), &data, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
Very basic. This point is nothing more than three floats. Now here is where things get strange. My render code is as follows:
glUseProgram(GL->shaderPassthrough);
float data[16];
glGetFloatv(GL_MODELVIEW_MATRIX, data);
glUniformMatrix4fv(glGetUniformLocation(GL->shaderPassthrough, "inModelViewMatrix"), 1, GL_FALSE, &data[0]);
glBindBuffer(GL_ARRAY_BUFFER, vboSquare);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_POINTS, 0, 1);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glUseProgram(0);
This code crashes (by which I mean I get the windows “This program has stopped responding, would you like to blah blah blah” message and then the program closes). I pinpointed the cause of the crash to be the final argument in glDrawArrays(…). For whatever reason the code refuses to work unless the last argument (the vertex count) is at least 257. What is even more bizarre is that if I were to delete the glVertexAttribPointer(…) line then the vertex count can be as low as 129 without crashing.
I’ve created multiple programs using code almost identical to this, in fact to save time this program is nothing more than a duplicated project of another program that works 100% as intended. The shaders are the same, the vertex attribute pointers are all set up the same. Everything is identical, yet in this program glDrawArrays(…) won’t let me draw small VBOs.
If anyone has any information regarding this please share as I’m pulling the last bit of my hair out trying to do the most simple of tasks.