try
{
double[] matrixArray = new double[16];
// Define the modelview transformation for rendering
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPushMatrix();
gl.glLoadIdentity();
Matrix modelview = dc.getView().getModelviewMatrix();
// Load the modelview matrix
modelview.toArray(matrixArray, 0, false);
gl.glLoadMatrixd(matrixArray, 0);
// Set up the texture transformation
gl.glMatrixMode(GL.GL_TEXTURE);
gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glPushMatrix();
gl.glLoadIdentity();
if (this.bind(dc))
{
// Set parameters telling OpenGL how to handle the texture
GL gl = dc.getGL();
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
float[] sCoeffArray = {1f, 0f, 0f, 0f};
float[] tCoeffArray = {0f, 1f, 0f, 0f};
gl.glTexGenfv(GL.GL_S, GL.GL_EYE_PLANE, sCoeffArray, 0);
gl.glTexGenfv(GL.GL_T, GL.GL_EYE_PLANE, tCoeffArray, 0);
gl.glEnable(GL.GL_TEXTURE_GEN_S);
gl.glEnable(GL.GL_TEXTURE_GEN_T);
gl.glEnable(GL.GL_TEXTURE_2D);
double hScale = .5;
double vScale = .5;
double hShift = .5;
double vShift = .5;
// Translate and scale to map NDC coordinates into texture coordinates (s,t).
gl.glTranslated(hShift, vShift, 0.0);
gl.glScaled(hScale, vScale, 1.0);
// Projective transform to map from eye coordinates to NDC coordinates
glu.gluPerspective(45.0, 1.0, 100000, 300000);
// Modelview transform to place the coordinate system at the eye position
// and with the negative z axis through the model origin.
glu.gluLookAt(cameraX, cameraY, cameraZ,
centerX, centerY, centerZ,
0, 1, 0);
}
// Now render the geometry
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
Matrix projection = dc.getView().getProjectionMatrix();
projection.toArray(matrixArray, 0, false);
gl.glLoadMatrixd(matrixArray, 0);
// Plane tanget to the surface
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL.GL_DOUBLE, 0, verts.rewind());
gl.glDrawArrays(GL.GL_QUADS, 0, 4);
// Line from camera to plane center point
gl.glLineWidth(2.0f);
gl.glColor3f(1f, 1f, 1f);
gl.glBegin(GL.GL_LINES);
gl.glVertex3d(cameraX, cameraY, cameraZ); // origin of the line
gl.glVertex3d(centerX, centerY, centerZ); // ending point of the line
gl.glEnd();
}
finally
{
gl.glDisable(GL.GL_TEXTURE_GEN_S);
gl.glDisable(GL.GL_TEXTURE_GEN_T);
gl.glMatrixMode(GL.GL_TEXTURE);
gl.glPopMatrix();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPopMatrix();
gl.glFlush();
}