PDA

View Full Version : Arrays...



Hylke Donker
01-22-2006, 08:46 AM
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, &amp;(FaceIt->TextureCoordinates.data[0]));
}
}
}
cout << __FILE__ << " @ " << __LINE__ << endl << &amp;FaceIt->Vertices.data[0] << ": " << FaceIt->Vertices.data[0] << endl;
glVertexPointer(3, GL_FLOAT, 0, &amp;(FaceIt->Vertices.data[0]));
cout << __FILE__ << " @ " << __LINE__ << endl << &amp;FaceIt->Normals.data[0] << ": " << FaceIt->Normals.data[0] << endl;
glNormalPointer(GL_FLOAT, 0, &amp;(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

RigidBody
01-22-2006, 09:25 AM
i don't see glEnableClientState in your code. this could cause a problem since you seem to have textured and non-textured polygons. i think it should look like


if(FaceIt->HasTexture) {

if(FaceIt->TexDatIt->TextureIndex >= 0) {
glBindTexture(GL_TEXTURE_2D, FaceIt->TexDatIt->TextureIndex);
glTexCoordPointer(2, GL_FLOAT, 0, &amp;(FaceIt->TextureCoordinates.data[0]));
glEnableClientState(GL_TEXTURE_COORD_ARRAY); }

else {
glDisableClientState(GL_TEXTURE_COORD_ARRAY); } }

jide
01-22-2006, 09:32 AM
On my computer using texture coordinate pointers without having enabled that pointer state result in segmentation fault. This is not the case for vertex, normal and colors.

Hylke Donker
01-22-2006, 09:32 AM
Originally posted by RigidBody:
i don't see glEnableClientState in your code. this could cause a problem since you seem to have textured and non-textured polygons. i think it should look like


if(FaceIt->HasTexture) {

if(FaceIt->TexDatIt->TextureIndex >= 0) {
glBindTexture(GL_TEXTURE_2D, FaceIt->TexDatIt->TextureIndex);
glTexCoordPointer(2, GL_FLOAT, 0, &amp;(FaceIt->TextureCoordinates.data[0]));
glEnableClientState(GL_TEXTURE_COORD_ARRAY); }

else {
glDisableClientState(GL_TEXTURE_COORD_ARRAY); } }Somewhere in my initialation I've enabled GL_TEXTURE_COORD_ARRAY, GL_VERTEX_ARRAY and GL_NORMAL_ARRAY.
Btw, if you keep changing those modes, isn't that causing a performance hit?Or does that not count in display lists?

jide
01-22-2006, 09:35 AM
Also I recommand you not to do it this way. Whether use display list or whether use vertex arrays. It appears that on nvidia cards, there's almost no differencies for static models between those 2 ways.

RigidBody
01-22-2006, 09:38 AM
when you call glDrawArrays, array pointers are expected for everything that you have enabled with glEnableClientState (vertices, normals, texture coordinates, vertex colors). you say you have enabled GL_TEXTURE_COORD_ARRAY all the time, but with your code it is possible that no texture coordinate pointer is specified. this could be the problem.

Hylke Donker
01-22-2006, 09:54 AM
It appeared to be that GL_TEXTURE_COORD_ARRAY, was only enabled when the list got generated. I already figured that it would be sucha dumb problem :p
Thank y'all very much.
Hylke