Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3024 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  OpenGL Matrix Skinning

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

OpenGL Matrix Skinning

n°1037653
themadmax
Posté le 06-04-2005 à 16:06:59  profilanswer
 

Bijour tout le monde !
Je tente la compilation de ce code :

Code :
  1. // Simple vertex weighting demo
  2. // d'après: Matt Craighead, 3D Software Engineer, NVIDIA Corporation
  3. // Email: mcraighead at nvidia dot com
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <gl/glut.h>
  7. #include <windows.h>
  8. #define M_PI 3.1415926
  9. /* EXT_vertex_weighting */
  10. #ifndef GL_EXT_vertex_weighting
  11. #define GL_VERTEX_WEIGHTING_EXT           0x8509
  12. #define GL_MODELVIEW0_EXT                 GL_MODELVIEW
  13. #define GL_MODELVIEW1_EXT                 0x850A
  14. typedef void (APIENTRY * PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight);
  15. typedef void (APIENTRY * PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight);
  16. #endif
  17. PFNGLVERTEXWEIGHTFEXTPROC glVertexWeightfEXT;
  18. // Display lists for the arm
  19. int armLists[2];
  20. int wireframe = 0;
  21. int stepWeight = 0;
  22. // Constants for the "arm" geometry
  23. const int tesselate[2] = {24, 12};
  24. const float length = 4.0;
  25. const float radius = 0.4;
  26. // For animation
  27. float time = 0.0;
  28. DWORD dwStartTime;
  29. // This is a nice cubic weighting function that seems to work well empirically
  30. // for the geomtry in question.
  31. float WeightFunction(float x)
  32. {
  33.   if (x < 0.4) return 1.0;
  34.   if (x > 0.6) return 0.0;
  35.   return (x-0.6)*(x-0.6)*(250*x-75);
  36. }
  37. // This weight function gives no transition at all.  It can be used to emulate
  38. // other simpler animation methods without actually having to write extra code
  39. // where I need to disable vertex weighting, etc.
  40. float StepWeightFunction(float x)
  41. {
  42.   if (x < 0.5) return 1.0;
  43.   else return 0.0;
  44. }
  45. // This function draws the geometry for a tapered cone with vertex weights
  46. void DrawArm(int step)
  47. {
  48.   float weight;
  49.   for (int i = 0; i < tesselate[0]; i++)
  50.   {
  51.     glBegin(GL_TRIANGLE_STRIP);
  52.     for (int j = 0; j <= tesselate[1]; j++)
  53. {
  54.       float x, y, current_radius;
  55.       y = 2*M_PI * (float)j / (float)tesselate[1];
  56.       x = (float)i / (float)tesselate[0];
  57.       current_radius = radius*(1.2-x*0.4);
  58.       weight = (step == 0 ? WeightFunction(x) : StepWeightFunction(x));
  59.      
  60.   glColor3f(0,0,1);
  61.       glVertexWeightfEXT(weight);
  62.       glNormal3f(0.4, sin(y), cos(y));
  63.       glVertex3f(length*(x-0.5), current_radius*sin(y), current_radius*cos(y));
  64.       x = (float)(i+1) / (float)tesselate[0];
  65.       current_radius = radius*(1.2-x*0.4);
  66.       weight = (step == 0 ? WeightFunction(x) : StepWeightFunction(x));
  67.   glColor3f(1,0,0);
  68.       glVertexWeightfEXT(weight);
  69.       glNormal3f(0.4, sin(y), cos(y));
  70.       glVertex3f(length*(x-0.5), current_radius*sin(y), current_radius*cos(y));
  71.     }
  72.     glEnd();
  73.   }
  74. }
  75. // Set up state, build display lists
  76. void init(void)
  77. {
  78.     glEnable(GL_DEPTH_TEST);
  79.   glEnable(GL_VERTEX_WEIGHTING_EXT);
  80.   // Vertex weighting always needs normalized normals, since they become
  81.   // unnormalized during the blending step even if they were before.
  82.   glEnable(GL_NORMALIZE);
  83.      // Build two arm display list
  84.     armLists[0] = glGenLists(2);
  85.     armLists[1] = armLists[0]+1;
  86.     glNewList(armLists[0], GL_COMPILE);
  87.     DrawArm(0);
  88.     glEndList();
  89.     glNewList(armLists[1], GL_COMPILE);
  90.     DrawArm(1);
  91.     glEndList();
  92. }
  93. // Window reshape handler
  94. void reshape(int w, int h)
  95. {
  96.   glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  97.   glMatrixMode(GL_PROJECTION);
  98.   glLoadIdentity();
  99.   gluPerspective(60.0, (GLdouble)w/(GLdouble)h, 1.0, 100.0);
  100. }
  101. // Keyboard handler
  102. void keyboard(unsigned char key, int x, int y)
  103. {
  104.     switch (key)
  105. {
  106.        case 's' :
  107.     stepWeight = 1 - stepWeight;
  108.     break;
  109.        case 'w' :
  110.     wireframe = 1 - wireframe;
  111.     break;
  112.        case 27 :
  113.     exit(0);
  114.     break;
  115.        default:
  116.          break;
  117.   }
  118.   glutPostRedisplay();
  119. }
  120. // Draw one arm
  121. void DrawOne(int step)
  122. {
  123.   float matrix[16];
  124.   static int armList[2];
  125.   glPushMatrix();
  126.   // Set up the second matrix with the right rotation
  127.   glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
  128.   glMatrixMode(GL_MODELVIEW1_EXT);
  129.   glLoadMatrixf(matrix);
  130.   //Animation
  131.   glRotatef(90.0*sin(2.0*time), 0, 0, 1);
  132.  
  133.   glMatrixMode(GL_MODELVIEW0_EXT);
  134.   // Call the display list for the arm  
  135.   glCallList(armLists[step]);
  136.   glPopMatrix();
  137. }
  138. // Display handler
  139. void display(void)
  140. {
  141.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  142.   time = (float)(GetTickCount() - dwStartTime) / 1000.0;
  143.   glMatrixMode(GL_MODELVIEW0_EXT);
  144.   glLoadIdentity();
  145.   glTranslatef(0, 0, -8);
  146.   // Set state based on program mode
  147.   glPolygonMode(GL_FRONT_AND_BACK, wireframe ? GL_LINE : GL_FILL);
  148.     glPushMatrix();
  149.     glScalef(1.5, 1.5, 1.5);
  150.     DrawOne(stepWeight);
  151.     glPopMatrix();
  152.    glutSwapBuffers();
  153. }
  154. void idle(void)
  155. {
  156.   glutPostRedisplay();
  157. }
  158. int main(int argc, char **argv)
  159. {
  160.   glutInit(&argc, argv);
  161.   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  162.   glutInitWindowSize(640, 480);
  163.   glutCreateWindow("matriw skinning" );
  164.   glVertexWeightfEXT = (PFNGLVERTEXWEIGHTFEXTPROC)wglGetProcAddress("glVertexWeightfEXT" );
  165.   dwStartTime = GetTickCount();
  166.  
  167.   //== Couleur du fond ==
  168. glClearColor(1.0, 1.0, 1.0, 0.0);
  169.   init();
  170.   glutReshapeFunc(reshape);
  171.   glutKeyboardFunc(keyboard);
  172.   glutDisplayFunc(display);
  173.   glutIdleFunc(idle);
  174.  
  175.   glutMainLoop();
  176.   return 0;
  177. }


Mais la focntion 'glVertexWeightfEXT' dans la fonction 'DrawArm(int step)' leve une erreur. L'initialisation 'glVertexWeightfEXT = (PFNGLVERTEXWEIGHTFEXTPROC)wglGetProcAddress("glVertexWeightfEXT" );' n'a pas l'air de fonctionner.
si vous avez la moindre idée Merci d'avance.

mood
Publicité
Posté le 06-04-2005 à 16:06:59  profilanswer
 

n°1037849
retrox
Posté le 06-04-2005 à 17:52:42  profilanswer
 

J'imagine que le probleme ne vient pas à la compilation mais à l'execution.
Le code suppose que l'extension EXT_vertex_weighting est supportée. Si ce n'est pas le cas, le pointeur retourné par wglGetProcAddress n'est pas valide. Normalement il faut d'abord verifier si une extension est dispo en cherchant dans l'extension string (glGetString(GL_EXTENSIONS)).
 
De toutes façons cette extension est obsolete. Seul NVIDIA la supportait il y a quelques années, mais ce n'est plus le cas (depuis fin 2002). Elle n'apparait plus dans les drivers depuis cette date. Tout se fait maintenant en vertex shader (ARB_vertex_program ou GLSL).


Message édité par retrox le 06-04-2005 à 17:53:10
n°1038061
themadmax
Posté le 06-04-2005 à 20:06:21  profilanswer
 

Merci pour cette reponce je cour voir (ARB_vertex_program ou GLSL).


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  OpenGL Matrix Skinning

 

Sujets relatifs
[OpenGL] faire un pacman...MESA (opengl)
Comment marche Occlusion Queries sur opengl avec mac os[OpenGl] Lumiere dans une piece
opengl, rectangle contour / couleur de remplissagedebutant Opengl glrecti et glColor3f
[AciveX et VC++] Texturing OpenGL[opengl] Recuperation d'infos sur une camera.
OpenGL -> Comment réaliser du Shadow mapping?frame opengl
Plus de sujets relatifs à : OpenGL Matrix Skinning


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR