1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| //p3d est une structure contenant toutes les données (points , triangles, pixels)
/*dans main.c*/
//variable globale
p3d 3d;
GLuint * tabTexture;
CvCapture *input_video;
//fonction de rendu
void display(void)
{
...
//j'affiche une séquence
afficheSeq3D(3d,tabTexture,numseq);
glutSwapBuffers();
glFlush ();
glutPostRedisplay();
}
int main (int argc, char** argv)
{
...
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
input_video=cvCaptureFromFile("video.avi");
tabTexture=(GLuint *) malloc(sizeof(GLuint)*nbImage);
loadAllTextures(input_video,tabTexture, nbImage);
...
return (0);
}
/*dans texture.c*/
//variable globale
GLuint idTexture = 0;
void loadAllTextures(CvCapture *input_video, GLuint * tabTexture, int nbImage)
{
int i;
IplImage *frame = NULL;
glGenTextures(nbImage, tabTexture);
for(i=0;i<nbImage;i++)
{
cvSetCaptureProperty(input_video, CV_CAP_PROP_POS_FRAMES, i);
frame = cvQueryFrame(input_video);
tabTexture[i]=loadTexture(frame);
}
}
GLuint loadTexture(IplImage * frame)
{
int i,j, p=0;
GLubyte *tabTexturePixels;
CvScalar rgb;
idTexture++;
tabTexturePixels = (GLubyte *) malloc(sizeof(GLubyte)*frame->width * frame->height * 3);
for (i=0; i < frame->width; i++)
{
for (j=0; j < frame->height; j++)
{
rgb = cvGet2D(frame, j, i);
tabTexturePixels[p+0] = (GLubyte)rgb.val[2];
tabTexturePixels[p+1] = (GLubyte)rgb.val[1];
tabTexturePixels[p+2] = (GLubyte)rgb.val[0];
p += 3;
}
}
glBindTexture(GL_TEXTURE_2D, idTexture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexImage2D(GL_TEXTURE_2D, 0, 3, frame->width, frame->height, 0, GL_RGB, GL_UNSIGNED_BYTE, tabTexturePixels);
free(tabTexturePixels);
return idTexture;
}
/*dans affiche.c*/
void afficheSeq3D( p3d 3d, GLuint * tabTexture,int numSeq)
{
int i;
for(i=3d->debutSequence[numSeq];i<=3d->finSequence[numSeq];i++)
{
//j'affiche toutes les images de la séquence
afficheImage(3d,i,tabTexture);
}
}
void afficheImage(p3D 3d,int img, GLuint * tabTexture)
{
int i;
triangle *courant;
glBindTexture(GL_TEXTURE_2D,tabTexture[img]);
glBegin(GL_TRIANGLES);
courant=3d->triangle_list[img]->debut;
//pour chaque triangle de l'image img
for (i=0;i<3d->triangle_list[img]->taille;i++)
{
//glTexCoord2f(x du pixel correspondant au point 1 du triangle courant, et le y );
glTexCoord2f(3d->pixels[img][courant->p1*2],3d->pixels[img][courant->p1*2+1]);
//glVertex3f(x du point 1, y, z);
glVertex3f(3d->points[img][courant->p1*3],3d->points[img][courant->p1*3+1],3d->points[img][courant->p1*3+2]);
//de meme point 2
glTexCoord2f(3d->pixels[img][courant->p2*2],3d->pixels[img][courant->p2*2+1]);
glVertex3f(3d->points[img][courant->p2*3],3d->points[img][courant->p2*3+1],3d->points[img][courant->p2*3+2]);
//de meme point 3
glTexCoord2f(3d->pixels[img][courant->p3*2],3d->pixels[img][courant->p3*2+1]);
glVertex3f(3d->points[img][courant->p3*3],3d->points[img][courant->p3*3+1],3d->points[img][courant->p3*3+2]);
courant=courant->suiv;
}
glEnd();
//cette fonction s'occupe du déplacement dans l'espace
transformation(3d,img);
} |
Partager