2
votes

I'm trying to draw a grid face and rotate it in various directions responding to mouse input, my code include enable GL_DEPTH_TEST, GL_NORMALIZE, I draw the grid face by glEnableClientState(GL_VERTEX_ARRAY), glEnableClientState(GL_NORMAL_ARRAY).

GL_VERTEX_ARRAY draw had tested,but when I enable GL_CULL_FACE, rotation can't see the back face,This is front and back face .

This is the code to init OpenGL:

 def initializeGL(self):
    glEnable(GL_DEPTH_TEST)   # Depth testing must be turned on
    glEnable(GL_LIGHTING)     # Enable lighting calculations
    glEnable(GL_LIGHT0)      # Turn on light #0.

    glEnable(GL_NORMALIZE)

    # Setup polygon drawing
    glShadeModel(GL_SMOOTH)
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glEnable(GL_CULL_FACE)   # question sentence
    glCullFace(GL_BACK)

    # Clear to black
    glClearColor(0.0, 0.2, 0.3, 1.0)

The is the function of draw:

 def drawTriangles(data):
    # data shape like (n,3,3), only the triangles vertex data
    N = np.cross(data[:, 0, :] - data[:, 1, :], data[:, 0, :] - data[:, 2, :])
    N = N / np.linalg.norm(N)
    N = N.reshape([-1, 1, 3])
    N = np.hstack([N, N, N]).reshape([-1, 3])
    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_NORMAL_ARRAY)
    glVertexPointer(3, GL_DOUBLE, 0, data)
    #specify the normal vector for every triangle, N shape like (n,3)
    glNormalPointer(GL_FLOAT, 0, N)
    glDrawArrays(GL_TRIANGLES, 0, data.shape[0] * data.shape[1])
    glDisableClientState(GL_VERTEX_ARRAY)
    glDisableClientState(GL_NORMAL_ARRAY)

other information: I use PyOpenGL+PyQt

1
That's exactly what GL_CULL_FACE is for! If you don't want to cull back faces, why are you enabling backface culling? It's meant for closed meshes, where you don't want to waste time rendering the inside because it will never be visible.Thomas
oh, I thought that GL_CULL_FACE make opengl not render the face I can't see, It isn't ? rightAbao Zhang
I think I konw your means , It 's meant for closed meshes, as you say ,thank you :smile:Abao Zhang
No, "front" and "back" depend only on the face, not on the direction you're looking from. They are determined from the face's winding order: the side where vertices are enumerated counter-clockwise is considered "front" and the other side is the "back". If you're looking at the "back" of the face, and you've enabled backface culling, the face won't be rendered.Thomas
@AbaoZhang Read about Face Culling. Faces are culled dependent on the winding order of the triangle primitives in clipspace. Note, in your case you want to "see" all the primitives regardless of the direction of view.Rabbid76

1 Answers

4
votes

but when I enable GL_CULL_FACE,rotation can't see the back face,This is front and back face.

That's the whole purpose of face culling: Suppressing the rendering of a particular side of a primitive. If you want to see both sides, you must disable face culling.