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
|
void pickSquares(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
glPushAttrib(GL_ALL_ATTRIB_BITS); // on sauvegarde tous
GLuint selectBuf[1024];
GLint hits=0;
GLint viewport[4];
glGetIntegerv (GL_VIEWPORT, viewport);
glSelectBuffer (1024, selectBuf);
(void) glRenderMode (GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), 2.0, 2.0, viewport);
gluPerspective(60,(float)W_fenetre/(float)H_fenetre,0.1,100);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(translatx,translaty,translatz);
element.afficher_pick(); //On affiche tout les elements
glPopMatrix();
glMatrixMode (GL_PROJECTION);
glPopMatrix ();
hits = glRenderMode (GL_RENDER);
print2d("\nNombre d'elements : "); //fonction qui ecrit sur la scene
print2d(hits);
print2d("\n");
glPopAttrib();
processHits (hits, selectBuf);
glutPostRedisplay();
}
}
void processHits ( int hits, unsigned int buffer[] )
{
print2d("Contenue de buffer : \n"); //fonction qui ecrit sur la scene
for (int i = 0; i< sizeof(buffer); i++)
{
print2d(buffer[i]);
print2d("\n");
}
}
void afficher_pick(void)
{
int tmp;
int id;
glPushName(id);
for (tmp=0;tmp<cube.size();tmp++)
{
glLoadName(id);
cube[tmp].afficher(); //Cree un cube
id++;
}
} |
Partager