I have a question about OpenGL 3.0, why am I unable to draw anything when my array of vertices in initialized as
float * vertices;
int size = 100; // size of the vertices array
float * vertices = (float *) malloc (size*sizeof(float));
I have allocated memory, and initialized all the values in the array to 0.0, but it looks like my vertex buffer reads only the first element of the vertices array. Whereas when I initialize the array like this :
float vertices[size];
all the vertices are read and rendered as expected.
Here is how I specify my vertex buffer, and pass data to the buffer :
unsigned int VBO;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW);
GLint posAttrib = glGetAttribLocation(ourShader.ID, "aPos");
// iterpreting data from buffer
glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 3* sizeof(float), (void*)0);
glEnableVertexAttribArray(0);