Matrix palettes for vertex skinning

I am trying to use matrix palettes for vertex skinning

I have two cuboids adjacent to each other. One of the cuboid is rotated, which results in a gap between the cuboids (like bending an arm).

Now i would like to use matrix palettes for skinning. Is it achieved by the below code?

I do not know how to decide the elements of the matrix and also how to assign a set of matrices to a particular vertex. Since all the vertices do not need skinning and only the vertices which are adjacent to each other need skinning ( in my case 4 vertices, 2 from each cuboid) .

//VBO’s are used to upload the vertices and texture

GLfloat weights[] = {0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f };
GLfloat matrix[4][16] = {…};

glEnable(GL_MATRIX_PALETTE_OES);
glMatrixMode(GL_MATRIX_PALETTE_OES);

glCurrentPaletteMatrixOES(0);
glLoadMatrixf(matrix[0]);

glCurrentPaletteMatrixOES(1);
glLoadMatrixf(matrix[1]);

glCurrentPaletteMatrixOES(2);
glLoadMatrixf(matrix[2]);

glCurrentPaletteMatrixOES(3);
glLoadMatrixf(matrix[3]);

glEnableClientState(GL_MATRIX_INDEX_ARRAY_OES);
glEnableClientState(GL_WEIGHT_ARRAY_OES);

glWeightPointerOES (1, GL_FLOAT, 0, weights);

glMatrixIndexPointerOES (1, GL_UNSIGNED_BYTE, sizeof(GLfloat) * 16, matrix);

glMatrixMode(GL_MODELVIEW);
//Draw and move the objects
Thank you.

you’re doing it wrong!
But i agree, their example is not very clear. try this:

glEnable(GL_MATRIX_PALETTE_OES);	
glMatrixMode(GL_MATRIX_PALETTE_OES);
	
glEnableClientState(GL_MATRIX_INDEX_ARRAY_OES);
glEnableClientState(GL_WEIGHT_ARRAY_OES);
	
//matrix 0: no transformation	
glCurrentPaletteMatrixOES(0);
glLoadPaletteFromModelViewMatrixOES();
	
glCurrentPaletteMatrixOES(1);
glLoadPaletteFromModelViewMatrixOES();
glTranslatef( 0, 200, 0 );

//my weights: 1.0, 0.0,   0.9, 0.1,   0.8, 0.2,   etc...
glWeightPointerOES(2, GL_FLOAT, 0, pWeights );
//these are indices: 0,1,   0,1,   0,1,    0,1 etc..
glMatrixIndexPointerOES(2, GL_UNSIGNED_BYTE, 0, pMatrices );
	
glVertexPointer(3, GL_FLOAT, 0, pVertices);
glNormalPointer(GL_FLOAT, 0, pNormals);

glDrawArrays(GL_TRIANGLE_STRIP, 0, nVerts );	
glDisable(GL_MATRIX_PALETTE_OES);

don’t think it’s the best way to use matrix palettes but this should put you in the right direction.

Thank you very much for your reply.

But i am still struggling with the below API:

glMatrixIndexPointerOES (2, GL_UNSIGNED_BYTE, 0, pMatrices)

I read the man pages but still not clear with the meaning and usage of the same.

Can you please explain me how the elements/content of “pMatrices” calculated !!

pMatrices points to an array of indices, like

pMatrices = [0,1,  0,1,  0,1,  0,1,  0,1,  0,1,  0,1,  0,1,  0,1,  0,1 ]; //if there are 10 vertices in my shape

in this case each vertex is assigned the same 2 matrices, 0 and 1
and this let you setup the palette matrix 1:

glCurrentPaletteMatrixOES(1);
glLoadPaletteFromModelViewMatrixOES();
glRotatef( 70, 0, 0, 1);
glTranslatef( 0, 50, 0 );

alternatively you can use LoadMatrix() like in your example if you wish.

pWeights = [ 0.0, 1.0,  0.0, 1.0,  0.5, 0.5,  0.2, 0.8,  1.0, 0.0,  1.0, 0.0,  1.0, 0.0,  1.0, 0.0,  1.0, 0.0,  1.0, 0.0 ];

just try this code and you’ll get it i’m sure

Thank you very much for clearing my doubt.

I followed your suggestion, but now my code crashes after eglSwap.

Below is all the code i have written. Please help


  GLfloat   pWeights[] = {0.0, 1.0,  0.0, 1.0,  0.5, 0.5,  0.2, 0.8,  1.0, 0.0,  1.0, 0.0,  1.0, 0.0,  1.0, 0.0,  1.0, 0.0,  1.0, 0.0};
  GLuint pMatrices[] = {0,1,  0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1,  0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1};

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glGenBuffers(1, &buffer);
  glBindBuffer(GL_ARRAY_BUFFER, buffer);
  glBufferData(GL_ARRAY_BUFFER, 16 * (sizeof(GLfloat) * 5), object, GL_STATIC_DRAW);

  glEnableClientState(GL_VERTEX_ARRAY);
  glVertexPointer(3, GL_FLOAT, sizeof(GLfloat) * 5, 0);

  glMatrixMode(GL_TEXTURE);
  glLoadIdentity();

  glEnable(GL_TEXTURE_2D);
  glGenTextures(1, &texture);
  glBindTexture(GL_TEXTURE_2D, texture); 
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, bmp); 
  glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);  

  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat) * 5, sizeof(GLfloat) * 3);

  glClearColor(0.0f,0.0f,0.0f,1.0f);
  glClear(GL_COLOR_BUFFER_BIT);  

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glRotatef((GLfloat)(30), 0.0f, 1.0f, 0.0f);
  glRotatef((GLfloat)(20), 4.0f, 4.0f, 0.0f);  

  glEnable(GL_MATRIX_PALETTE_OES);   
  glMatrixMode(GL_MATRIX_PALETTE_OES);
  glEnableClientState(GL_MATRIX_INDEX_ARRAY_OES);
  glEnableClientState(GL_WEIGHT_ARRAY_OES);

  for( i = 0x00; ((i < 2) && (err_count == 0x00)); i++) {        
    glCurrentPaletteMatrixOES(i);
    glLoadPaletteFromModelViewMatrixOES ();

    glRotatef((GLfloat)(-i), 0.0f, 0.0f, 1.0f);
  }

  glWeightPointerOES (2, GL_FLOAT, 0, pWeights);

  glMatrixIndexPointerOES (2, GL_UNSIGNED_BYTE, 0, pMatrices);    


  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glRotatef((GLfloat)(30), 0.0f, 1.0f, 0.0f);
  glRotatef((GLfloat)(20), 4.0f, 4.0f, 0.0f);

  for( i = 0x00; i < 10; i++) {       

    glDrawElements(GL_TRIANGLES, 36,GL_UNSIGNED_BYTE, (GLvoid *)&indices[0]); 

    glPushMatrix();

    glEnable(GL_BLEND);
    glRotatef((GLfloat)(-i), 0.0f, 0.0f, 1.0f);

    glDrawElements(GL_TRIANGLES, 36,GL_UNSIGNED_BYTE, (GLvoid *)&indices[36]); 

    glDisable(GL_BLEND);
    glPopMatrix();

    eglSwapBuffers(g_egldisplay, g_eglsurface);    //Hangs after this call

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  }

try removing anything that’s unrelated to vertex skinning - my example is really simple just try it as it is
sorry if i don’t have time to debug your code!

Hey i’ve been playing around with this, but isn’t

glWeightPointerOES(2, GL_FLOAT, 0, pWeights );

supposed to have the “size” of the matrix holding the weight information as

glWeightPointerOES(weightspervertex, GL_FLOAT, sizeof(GLfloat)*weightspervertex, pWeights );

Seems to work on my side.

My bad thats meant for stride … !

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.