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
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. – ThomasFace 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