Hi,
I get a strange effect while rendering images in Java2D, that I can’t get rid off and that I can’t explain to myself. I’m building a viewport component that uses a VolatileImage as backbuffer and provides some scrolling functionality.
In my first implementation I used a large VolatileImage as backbuffer, which represented the scrollable world space. All images were rendered to the Graphics2D object of the backbuffer, using the “drawImage” method and world space coordinates. After the rendering was finished, only the visible part of the backbuffer was blitted to the screen, using the “drawImage” method with the “dx,dy,sx,sy” params and the coordinates of the view-rectangle, representing the viewport on top of the world space. That approach worked well.
Now I changed the implementation, because I wanted to get rid of that super size backbuffer, which just represented the world space coordinate system. I’m using now a backbuffer that has the same size as the viewport and before rendering the images, the coordinate system of the backbuffers Graphics2D object is translated to the world space, using the “translate” method. That means the scrolling is done now by offsetting the coordinate system of the backbuffer. Like this I can keep drawing the images, using their world coordinates. But I’m still having trouble with this solution. Everything gets drawn proper, but when the scrolling is performed, the whole rendered image looks a bit darker and also less “sharp”. I don’t know how to describe this better and I can’t provide a screenshot either, as this effect doesn’t show up in a screenshot. I already tried to make some screenshots, but I can’t see a difference in the images, which I don’t understand either. The effect also doesn’t occur while there’s is no scrolling taking place, even that I have moving objects on the screen and the same code is executed for rendering and blitting. That visual effect is just there, when the viewport is moving, which means that the “translate” method is called with incrementing/decrementing values. I have no clue where this comes from, but it looks to me a bit like some kind of visual optimization, that could be done by the rendering pipeline or graphics driver. Do you have an idea what this could be and how I could solve it? Maybe it’s just a problem with my system. ???
The code for the coordinate translation look like this:
final int xTranslation = viewRect.x;
final int yTranslation = viewRect.y;
// Translate the coordinate system of the Graphics2D object to world space
bufferGraphics.translate(-xTranslation, -yTranslation);
// Set the clipping to match the viewport area
bufferGraphics.setClip(xTranslation, yTranslation, viewRect.width, viewRect.height);
// Render images
bufferCallback.performRendering(targetGraphics);
// Translate the coordinate system of the Graphics2D object back
bufferGraphics.translate(xTranslation, yTranslation);
The blitting code looks like this:
// Blit the back buffer
componentGraphics.drawImage(bufferImage, 0, 0, null);
I will still try out the program on a different system and I will also try to get a screenshot or video that shows this effect. Maybe I could also get a Webstart version up running in a while, but the for the moment I can just provide the description and some code.
It would be nice, if you could help me out with this or if you have any ideas where I could keep looking for the source of the problem! Thanks already in advance for your help!
Greetings,
Eboreus