nVidia drivers problem?

Hi,

I have a project which runs correctly in a laptop with ATI graphic card but when I try to compile on a PC with nVidia graphic card (with updated drivers) I have a segmentation fault when I call glDrawArrays().

The code is exactly the same (copy&paste from to laptop to PC).

Is there someone who understand this?

Thanks

Yes, you enabled an array, but didn’t specify a pointer for it.

Specifying the pointer:


    GLuint vertexs;
    GLuint normals;

    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    glGenBuffers(1,&vertexs);
    glBindBuffer(GL_ARRAY_BUFFER,vertexs);
    glBufferData(GL_ARRAY_BUFFER,sizeVertex*sizeof(GLfloat),vertexArray,GL_DYNAMIC_DRAW);
    glVertexPointer(3,GL_FLOAT,0,0);

    glGenBuffers(1,&normals);
    glBindBuffer(GL_ARRAY_BUFFER,normals);
    glBufferData(GL_ARRAY_BUFFER,sizeVertex*sizeof(GLfloat),normalArray,GL_DYNAMIC_DRAW);
    glNormalPointer(GL_FLOAT,0,0);

Drawing:


    glBindVertexArray(vao);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);

    glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,difus);
    glMaterialfv(GL_FRONT,GL_SPECULAR,especular);

    glDrawArrays(GL_TRIANGLES,0,sizeVertex/3);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);

Ah, the infamous VAO. Try removing it.

How?

Here’s the point. I have 6 six objects which do these calls (not specifying the pointers but the drawing). With VAO I don’t have problems with my ATI card.

The client state is part of the VAO. That doesn’t explain your problem (though knowing exactly where the segmentation fault is would help), but you should put the glEnableClientState call in the VAO itself if you’re going to use the VAO to preserve state.

As I said, I call this for 6 objects. When I draw the first one I don’t have troubles but the segmentation fault appears when I draw the second.


    glBindVertexArray(vao);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);

    glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,difus);
    glMaterialfv(GL_FRONT,GL_SPECULAR,especular);

    glDrawArrays(GL_TRIANGLES,0,sizeVertex/3); //Segmentation fault calling this function

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);

I’m sorry but I think I don’t understand what you’re trying to told me Alfonse about glEnableClientState.

In your initialization, you create a VAO and bind it. Then, you call gl*Pointer calls, which set attribute state in the VAO. Therefore, the VAO contains the state set by those calls.

The VAO also contains state set by glEnable/DisableClientState. So if you made your glEnableClientState calls in your initialization routine, they would be stored in the VAO, and you would not need to set them again later.

As I said, this isn’t your problem, but it is something you should be doing.