Reputation: 331
I'm trying to write a class that renders models from .3ds files and I'm running into a really annoying issue. I have a map mapping from integers to vectors of doubles
map<int, vector<double> >
that I am using to map the vertices which have different material properties. After that I try to iterate through all of the keys and have OpenGL render them like so:
glPushMatrix();
glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
for(map<int, vector<double> >::iterator iter = myMaterialVertices.begin(); iter != myMaterialVertices.end(); iter++)
{
vector<double> test = iter->second;
glVertexPointer(3, GL_DOUBLE, 0, test.data());
//get the texture coords here
glDrawArrays(GL_TRIANGLES, 0, iter->second.size() / 3);
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glPopClientAttrib();
glPopMatrix();
Unfortunately this gives me an error on the glDrawArrays call every single time telling me that I am trying to read address 0. I interpreted this to mean there was a null pointer issue, so I put in the test vector to make sure the data was there. The vector gets loaded correctly but still gives the same error. What am I doing wrong?
Upvotes: 1
Views: 165
Reputation: 331
Since it was suggested in the comments I will put up an answer. The call to
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
causes OpenGL to expect a pointer to an array of texture coordinates. When none was specified it threw a null pointer exception (attempt to read 0x00000000). The lesson here being don't enable client states unless you plan on defining the appropriate pointer.
Upvotes: 1