Bonjour !
Après pas mal d'essais infructueux (ainsi que de recherches menant à la même finalité) Je viens ici afin de chercher conseil.

Je souhaite récupérer le Z rendu par mon picking en mode SELECT afin de le donner à gluUnProject. le but étant de savoir qui est cliqué et où exactement.

J'ai cette solution mais qui ne fonctionne pas.
Ici readpixel est utilisé, mais le but est de sortir le Z du picking.

En fait aussi bien avec readpixel que le picking j'ai des valeurs étrange.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
glPushAttrib(GL_ALL_ATTRIB_BITS);    /* on sauvegarde tous */
 
		//glDisable(GL_LIGHTING); //desactiver tout ce qui est inutile
		//#define BUFSIZE 512
		GLuint selectBuf[/*BUFSIZE*/512];
		GLint hits=0;
		GLint viewport[4];
 
		glGetIntegerv (GL_VIEWPORT, viewport);
 
		glSelectBuffer (/*BUFSIZE*/512, selectBuf);
		(void) glRenderMode (GL_SELECT);
 
		glInitNames();
		glPushName(0);
 
		glMatrixMode (GL_PROJECTION);
		glPushMatrix ();    /* push projection */
		glLoadIdentity ();
 
		/*  create 5x5 pixel picking region near cursor location	*/
		gluPickMatrix ((GLdouble) point.x, (GLdouble) (viewport[3] - point.y), 3.0, 3.0, viewport);
 
			glOrtho(xmin,xmax,ymin,ymax,orthoZmin,orthoZmax);
 
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();        /* push modelview */
		glLoadIdentity();
 
			manipulateurSouris();
			manipulateurClavier();
 
	float rendermode;
	glGetFloatv(GL_RENDER_MODE,&rendermode);
	if(rendermode == GL_SELECT)
	{
						glBegin(GL_QUADS);		//Création d'un plan invisible, permettant de se placer sur XY s'il n'y a pas d'objet.
						glVertex3i(-1000000,-1000000,0);
						glVertex3i(-1000000,1000000,0);
						glVertex3i(1000000,1000000,0);
						glVertex3i(1000000,-1000000,0);
						glEnd();
 
					pos = pDoc->m_usilst.GetHeadPosition();
					while ( pos != NULL)
					{
						m_oneusi = pDoc->m_usilst.GetNext(pos);
						glPushName ( (GLint)(m_oneusi) );
						m_oneusi->TracerGL();
						glPopName();
					}
 
		glPopName();
 
 
	}//Fin de l'affichage des usinages
 
	glPopMatrix();        /* pop modelview */
	glMatrixMode (GL_PROJECTION);    
 
 
		glFlush ();//On veut etre sur que tout est bien traité
		hits = glRenderMode (GL_RENDER);
 
		//processHits (hits, selectBuf, list); //On prend une définition plus simple |
		//processHits (hits, selectBuf);											 V
 
			//void processHits (GLint hits, GLuint buffer[])
			//{
 
			//GLuint buffer[]=selectBuf;
 
			unsigned int i, j;
			GLfloat z;
			GLuint names, *ptr;
			int cnt = 0;
 
			printf ("hits = %d\n", hits);
			ptr = (GLuint *) selectBuf;
			for (i = 0; i < hits; i++) {	/*  for each hit  */
				//names = *ptr;
				//printf (" number of names for this hit = %d\n", names); ptr++;
				//printf("  z1 is %g;", (float) *ptr/0x7fffffff); ptr++;
				//printf(" z2 is %g\n", (float) *ptr/0x7fffffff); ptr++;
				//printf ("   names are ");
				names = *ptr;
				ptr++;
				float z1 = (GLfloat)*ptr/0x7fffffff; ptr++;
				float z2 = (GLfloat)*ptr/0x7fffffff; ptr++;
				z=(z1+z2)/2;
				CGeometrie* elem;
				COneUsinage* usi;
				for (j = 0; j < names; j++) { /*  for each name */
					//printf ("%d ", *ptr);
					if(j==1) usi=(COneUsinage*)*ptr;
					else elem = (CGeometrie*)*ptr;
 
					ptr++;
				}
 
 
				CVector nearest (0,0,0);
				//Souris2VertexGL(point.x,point.y,&nearest.x,&nearest.y,&nearest.z); //IMPRECIS
 
						GLint viewport[4];
						GLdouble modelview[16];
						GLdouble projection[16];
						GLfloat winX, winY, winZ;
						//GLdouble posX, posY, posZ;
 
						glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
						glGetDoublev( GL_PROJECTION_MATRIX, projection );
						glGetIntegerv( GL_VIEWPORT, viewport );
 
						winX = (float)point.x;;
						winY = (float)viewport[3] - (float)point.y;
						//winZ = z;
						glReadPixels( point.x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
						gluUnProject( winX, winY, winZ, modelview, projection, viewport, &nearest.x, &nearest.y, &nearest.z); //Rempli les pos
				if(names && j>=2){
					elem->Closest_point(nearest,&nearest);
					tempo_list->AddTail(new ElPick(elem, nearest, usi/*this*/, cnt));
				}
				cnt++;
			}//Fin boucle hits
 
			//} //Fin processHits
 
 
		glPopMatrix ();        /* pop projection */	
		glPopAttrib();

Des idées ?

Merci
Quentin