- IntBuffer buf = ByteBuffer.allocateDirect(9*4*4).order(ByteOrder.nativeOrder()).asIntBuffer();
- gl.glColor3f(0,0,0);
- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- double dist = Double.MAX_VALUE;
- if (clickPoint==null) closest = null;
- synchronized(this) {
- for(Mesh.T t : safeTriangles)
- t.glTriangle(gl, null);
- for(Mesh.Vertex v : tile.vertices()) {
- Point p = v.getPoint();
- gl.glColor3f(1,1,1);
- gl.glBegin(gl.GL_POINTS);
- p.glVertex(gl);
- gl.glEnd();
- gl.glFlush();
-
- Point projected = projection.times(p);
- int x = (int)projected.x;
- int y = (int)projected.y;
- gl.glReadPixels(x-1, y-1, 3, 3, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, buf);
-
- boolean vis = false;
- for(int j=0; j<9*4; j++) vis |= buf.get(j)!=0;
- v.visible = vis;
- if (vis) {
- gl.glColor3f(0,0,0);
- gl.glBegin(gl.GL_POINTS);
- p.glVertex(gl);
- gl.glEnd();
- y = glcanvas.getHeight()-y;
- if (clickPoint==null) {
- if (closest==null || (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey) < dist) {
- dist = (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey);
- closest = v;
- }
- }
- }
- }
- }
- gl.glShadeModel(GL.GL_SMOOTH);
- gl.glEnable(GL.GL_LIGHTING);
- gl.glDrawBuffer(GL.GL_FRONT);