int format, int objectId,
byte[] imageYdown,
int winWidth, int winHeight) {
if (VERBOSE) System.err.println("JoglPipeline.texturemapping()");
GL2 gl = context(ctx).getGL().getGL2();
int glType = GL.GL_RGBA;
// Temporarily disable fragment and most 3D operations
gl.glPushAttrib(GL2.GL_ENABLE_BIT | GL2.GL_TEXTURE_BIT | GL.GL_DEPTH_BUFFER_BIT | GL2.GL_POLYGON_BIT);
disableAttribFor2D(gl);
// Reset the polygon mode
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2.GL_FILL);
gl.glDepthMask(false);
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
gl.glBindTexture(GL.GL_TEXTURE_2D, objectId);
// set up texture parameter
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL.GL_TEXTURE_2D);
// loaded identity modelview and projection matrix
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0.0, winWidth, 0.0, winHeight, 0.0, 0.0);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
if (gl.isExtensionAvailable("GL_EXT_abgr")) {
glType = GL2.GL_ABGR_EXT;
} else {
switch (format) {
case ImageComponentRetained.TYPE_BYTE_RGBA:
glType = GL.GL_RGBA;
break;
case ImageComponentRetained.TYPE_BYTE_RGB:
glType = GL.GL_RGB;
break;
}
}
gl.glPixelStorei(GL2.GL_UNPACK_ROW_LENGTH, rasWidth);
gl.glPixelStorei(GL2.GL_UNPACK_SKIP_PIXELS, minX);
gl.glPixelStorei(GL2.GL_UNPACK_SKIP_ROWS, minY);
gl.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, minX, minY,
maxX - minX, maxY - minY,
glType, GL.GL_UNSIGNED_BYTE,
ByteBuffer.wrap(imageYdown));
gl.glPixelStorei(GL2.GL_UNPACK_ROW_LENGTH, 0);
gl.glPixelStorei(GL2.GL_UNPACK_SKIP_PIXELS, 0);
gl.glPixelStorei(GL2.GL_UNPACK_SKIP_ROWS, 0);
float texMinU = (float) minX/ (float) texWidth;
float texMinV = (float) minY/ (float) texHeight;
float texMaxU = (float) maxX/ (float) texWidth;
float texMaxV = (float) maxY/ (float) texHeight;
float halfWidth = (float)winWidth/2.0f;
float halfHeight = (float)winHeight/2.0f;
float mapMinX = (float) (((px + minX)- halfWidth)/halfWidth);
float mapMinY = (float) ((halfHeight - (py + maxY))/halfHeight);
float mapMaxX = (float) ((px + maxX - halfWidth)/halfWidth);
float mapMaxY = (float) ((halfHeight - (py + minY))/halfHeight);
gl.glBegin(GL2.GL_QUADS);
gl.glTexCoord2f(texMinU, texMaxV); gl.glVertex2f(mapMinX,mapMinY);
gl.glTexCoord2f(texMaxU, texMaxV); gl.glVertex2f(mapMaxX,mapMinY);
gl.glTexCoord2f(texMaxU, texMinV); gl.glVertex2f(mapMaxX,mapMaxY);
gl.glTexCoord2f(texMinU, texMinV); gl.glVertex2f(mapMinX,mapMaxY);
gl.glEnd();
// Java 3D always clears the Z-buffer
gl.glDepthMask(true);
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
gl.glPopAttrib();
}