themadmax | Bijour tout le monde !
Je tente la compilation de ce code :
Code :
- // Simple vertex weighting demo
- // d'après: Matt Craighead, 3D Software Engineer, NVIDIA Corporation
- // Email: mcraighead at nvidia dot com
- #include <stdio.h>
- #include <math.h>
- #include <gl/glut.h>
- #include <windows.h>
- #define M_PI 3.1415926
- /* EXT_vertex_weighting */
- #ifndef GL_EXT_vertex_weighting
- #define GL_VERTEX_WEIGHTING_EXT 0x8509
- #define GL_MODELVIEW0_EXT GL_MODELVIEW
- #define GL_MODELVIEW1_EXT 0x850A
- typedef void (APIENTRY * PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight);
- typedef void (APIENTRY * PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight);
- #endif
- PFNGLVERTEXWEIGHTFEXTPROC glVertexWeightfEXT;
- // Display lists for the arm
- int armLists[2];
- int wireframe = 0;
- int stepWeight = 0;
- // Constants for the "arm" geometry
- const int tesselate[2] = {24, 12};
- const float length = 4.0;
- const float radius = 0.4;
- // For animation
- float time = 0.0;
- DWORD dwStartTime;
- // This is a nice cubic weighting function that seems to work well empirically
- // for the geomtry in question.
- float WeightFunction(float x)
- {
- if (x < 0.4) return 1.0;
- if (x > 0.6) return 0.0;
- return (x-0.6)*(x-0.6)*(250*x-75);
- }
- // This weight function gives no transition at all. It can be used to emulate
- // other simpler animation methods without actually having to write extra code
- // where I need to disable vertex weighting, etc.
- float StepWeightFunction(float x)
- {
- if (x < 0.5) return 1.0;
- else return 0.0;
- }
- // This function draws the geometry for a tapered cone with vertex weights
- void DrawArm(int step)
- {
- float weight;
- for (int i = 0; i < tesselate[0]; i++)
- {
- glBegin(GL_TRIANGLE_STRIP);
- for (int j = 0; j <= tesselate[1]; j++)
- {
- float x, y, current_radius;
- y = 2*M_PI * (float)j / (float)tesselate[1];
- x = (float)i / (float)tesselate[0];
- current_radius = radius*(1.2-x*0.4);
- weight = (step == 0 ? WeightFunction(x) : StepWeightFunction(x));
-
- glColor3f(0,0,1);
- glVertexWeightfEXT(weight);
- glNormal3f(0.4, sin(y), cos(y));
- glVertex3f(length*(x-0.5), current_radius*sin(y), current_radius*cos(y));
- x = (float)(i+1) / (float)tesselate[0];
- current_radius = radius*(1.2-x*0.4);
- weight = (step == 0 ? WeightFunction(x) : StepWeightFunction(x));
- glColor3f(1,0,0);
- glVertexWeightfEXT(weight);
- glNormal3f(0.4, sin(y), cos(y));
- glVertex3f(length*(x-0.5), current_radius*sin(y), current_radius*cos(y));
- }
- glEnd();
- }
- }
- // Set up state, build display lists
- void init(void)
- {
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_VERTEX_WEIGHTING_EXT);
- // Vertex weighting always needs normalized normals, since they become
- // unnormalized during the blending step even if they were before.
- glEnable(GL_NORMALIZE);
- // Build two arm display list
- armLists[0] = glGenLists(2);
- armLists[1] = armLists[0]+1;
- glNewList(armLists[0], GL_COMPILE);
- DrawArm(0);
- glEndList();
- glNewList(armLists[1], GL_COMPILE);
- DrawArm(1);
- glEndList();
- }
- // Window reshape handler
- void reshape(int w, int h)
- {
- glViewport(0, 0, (GLsizei)w, (GLsizei)h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(60.0, (GLdouble)w/(GLdouble)h, 1.0, 100.0);
- }
- // Keyboard handler
- void keyboard(unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 's' :
- stepWeight = 1 - stepWeight;
- break;
- case 'w' :
- wireframe = 1 - wireframe;
- break;
- case 27 :
- exit(0);
- break;
- default:
- break;
- }
- glutPostRedisplay();
- }
- // Draw one arm
- void DrawOne(int step)
- {
- float matrix[16];
- static int armList[2];
- glPushMatrix();
- // Set up the second matrix with the right rotation
- glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
- glMatrixMode(GL_MODELVIEW1_EXT);
- glLoadMatrixf(matrix);
- //Animation
- glRotatef(90.0*sin(2.0*time), 0, 0, 1);
-
- glMatrixMode(GL_MODELVIEW0_EXT);
- // Call the display list for the arm
- glCallList(armLists[step]);
- glPopMatrix();
- }
- // Display handler
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- time = (float)(GetTickCount() - dwStartTime) / 1000.0;
- glMatrixMode(GL_MODELVIEW0_EXT);
- glLoadIdentity();
- glTranslatef(0, 0, -8);
- // Set state based on program mode
- glPolygonMode(GL_FRONT_AND_BACK, wireframe ? GL_LINE : GL_FILL);
- glPushMatrix();
- glScalef(1.5, 1.5, 1.5);
- DrawOne(stepWeight);
- glPopMatrix();
- glutSwapBuffers();
- }
- void idle(void)
- {
- glutPostRedisplay();
- }
- int main(int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutInitWindowSize(640, 480);
- glutCreateWindow("matriw skinning" );
- glVertexWeightfEXT = (PFNGLVERTEXWEIGHTFEXTPROC)wglGetProcAddress("glVertexWeightfEXT" );
- dwStartTime = GetTickCount();
-
- //== Couleur du fond ==
- glClearColor(1.0, 1.0, 1.0, 0.0);
- init();
- glutReshapeFunc(reshape);
- glutKeyboardFunc(keyboard);
- glutDisplayFunc(display);
- glutIdleFunc(idle);
-
- glutMainLoop();
- return 0;
- }
|
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.
|