Pixel format conversion doesn’t appear to be working correctly when drawing Transformed OPAQUE managed images onto a vram image with a different pixel format.
I guess the software transforming is done in 32bpp, and is never converted back to the pixel format of the original image before being copied into the vram image.
I assume this is a known issue, and will be resolved in 1.5?
The code below demonstrates the problem.
The image drawn in the top left corner is the untransformed managed image - it draws correctly.
A transformed (rotated) version of the managed image should be flickering around random locations on the screen - it isn’t.
Changing the color depth to 32bpp, or changing the image pixel format to BITMASK/TRANSLUCENT solves the problem. (changing the color of the rectangle also fixes the problem… kinda, but only cos the lower order bits are used by both 16bpp and 32bpp pixel formats ;))
:-
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
public class Test extends Frame
{
static final int SCREEN_WIDTH = 640,SCREEN_HEIGHT = 480;
static final boolean FULLSCREEN = true;
boolean running = true;
public Test()
{
setUndecorated(true);
GraphicsConfiguration gc = getGraphicsConfiguration();
GraphicsDevice gd = gc.getDevice();
if(FULLSCREEN)
{
gd.setFullScreenWindow(this);
gd.setDisplayMode(new DisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,16,60));
// ^^ change this to 32bpp and the problem goes away
}
else
{
setSize(SCREEN_WIDTH,SCREEN_HEIGHT);
show();
}
try{Thread.sleep(2000);}catch(Exception e){} //to ensure the window is fully realised before proceeding.
BufferedImage image = gc.createCompatibleImage(50,50,Transparency.OPAQUE);
// ^^ change this to BITMASK or TRANSLUCENT, and the problem goes away
{
Graphics g2d = image.createGraphics();
g2d.setColor(Color.red);
// change this to blue, green, white, red etc etc to see which colors work.
g2d.fillRect(0,0,50,50);
g2d.dispose();
}
createBufferStrategy(2);
enableEvents(AWTEvent.KEY_EVENT_MASK);
while(running)
{
Graphics2D g2d = (Graphics2D)(getBufferStrategy().getDrawGraphics());
g2d.setColor(Color.black);
g2d.fillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
g2d.drawImage(image,0,0,null);
g2d.translate(Math.random()*(SCREEN_WIDTH-50),Math.random()*(SCREEN_HEIGHT-50));
g2d.rotate(Math.random()*Math.PI*2);
g2d.drawImage(image,-25,-25,null);
g2d.dispose();
g2d.dispose();
getBufferStrategy().show();
}
dispose();
}
public void processEvent(AWTEvent e)
{
if(((KeyEvent)e).getKeyCode()==KeyEvent.VK_ESCAPE) running = false;
}
public static void main(String argv[]) throws Exception
{
new Test();
}
}
p.s. drawString and lots of other Graphics[2D] methods also misbehave when using ‘odd’ bitdepths.