Hello,
I’m using vertex arrays for rendering my triangles, but I get a segmentation fault when I call glDrawArrays.When I did a backtrace, I found that it came from the nvidia library.
I doubt that this is a bug of nvidia, but rather a bug in my code, but the problem is, I have no idea what it could be.
So I first checked out whether the pointers I gave to gl*Pointer really contain values. They did.
And that was the only thing I could come up that could cause a seg. fault.
Here’s my code:
glNewList(tmplist, GL_COMPILE);
vector<Face3DS>::iterator FaceIt;
for(FaceIt = MeshIt->Faces.begin();FaceIt < MeshIt->Faces.end();FaceIt++)
{
if(FaceIt->HasMaterial)
{
glMaterialfv(GL_FRONT, GL_DIFFUSE, FaceIt->MaterialDiffuse.data);
glMaterialfv(GL_FRONT, GL_SPECULAR, FaceIt->MaterialSpecular.data);
glMaterialfv(GL_FRONT, GL_AMBIENT, FaceIt->MaterialAmbient.data);
glMaterialf(GL_FRONT, GL_SHININESS, FaceIt->MaterialShininess);
if(FaceIt->HasTexture)
{
if(FaceIt->TexDatIt->TextureIndex >= 0)
{
glBindTexture(GL_TEXTURE_2D, FaceIt->TexDatIt->TextureIndex);
glTexCoordPointer(2, GL_FLOAT, 0, &(FaceIt->TextureCoordinates.data[0]));
}
}
}
cout << __FILE__ << " @ " << __LINE__ << endl << &FaceIt->Vertices.data[0] << ": " << FaceIt->Vertices.data[0] << endl;
glVertexPointer(3, GL_FLOAT, 0, &(FaceIt->Vertices.data[0]));
cout << __FILE__ << " @ " << __LINE__ << endl << &FaceIt->Normals.data[0] << ": " << FaceIt->Normals.data[0] << endl;
glNormalPointer(GL_FLOAT, 0, &(FaceIt->Normals.data[0]));
cout << __FILE__ << " @ " << __LINE__ << endl;
glDrawArrays(GL_POLYGON, 0, 3);
cout << __FILE__ << " @ " << __LINE__ << endl;
}
glEndList();
My Face3DS class:
// Global structures
struct PolygonData { float data[9]; };
struct PolygonTexCoord { float data[6]; };
struct MaterialColor { float data[3]; };
struct Matrix { float data[4][4]; };
[..]
class Face3DS
{
public:
Face3DS();
PolygonData Vertices;
PolygonData Normals;
PolygonTexCoord TextureCoordinates;
bool HasMaterial;
MaterialColor MaterialDiffuse;
MaterialColor MaterialSpecular;
MaterialColor MaterialAmbient;
GLfloat MaterialShininess;
bool HasTexture;
vector<TextureData>::iterator TexDatIt;
};
I really have no clue what it could be. I’v e tried several things: not giving the adress of the first element but of the array, and things like that. But it continues to give a segmentation fault.
Please help me, I really have no idea what to do.
Thanx in advance,
Hylke