/////// define some Nx argument //////
class MyCloth {
NxMeshData mReceiveBuffers;
NxScene *mScene;
NxCloth *mCloth;
NxClothMesh *mClothMesh;
GLfloat *mTexCoords;
NxU32 mNumTexCoords;
GLuint mTexId;
}
//this function written for draw the cloth
Code: Select all
void MyCloth::draw(bool shadows)
{
NxU32 numVertices = *mReceiveBuffers.numVerticesPtr;
NxU32 numTriangles = *mReceiveBuffers.numIndicesPtr / 3;
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, mReceiveBuffers.verticesPosBegin);
glNormalPointer(GL_FLOAT, 0, mReceiveBuffers.verticesNormalBegin);
if (mTexId) {
updateTextureCoordinates();
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, mTexCoords);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mTexId);
glColor4f(1.0f, 1.0f, 1.0f,1.0f);
}
glDrawElements(GL_TRIANGLES, 3*numTriangles, GL_UNSIGNED_INT, mReceiveBuffers.indicesBegin);
if (mTexId) {
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
}
if (shadows) {
const static float ShadowMat[]={ 1,0,0,0, 0,0,0,0, 0,0,1,0, 0,0,0,1 };
glPushMatrix();
glMultMatrixf(ShadowMat);
glDisable(GL_LIGHTING);
glColor4f(0.05f, 0.1f, 0.15f,1.0f);
glDrawElements(GL_TRIANGLES, 3*numTriangles, GL_UNSIGNED_INT, mReceiveBuffers.indicesBegin);
glColor4f(1.0f, 1.0f, 1.0f,1.0f);
glEnable(GL_LIGHTING);
glPopMatrix();
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}