I have a problem with drawing resized 2D images on top of an OpenGL view. Images tend to get a 1 pixel border filled with junk data of various colors. I could easily recreate the problem in the Juce Demo (OpenGLDemo.cpp) like so:
// put this class anywhere
class GlitchImage : public Component {
public:
GlitchImage(int width, int height) : im(Image::RGB, 100, 100, true) {
setSize(width, height);
Graphics g(im);
g.setColour(Colour(.5f, .5f, .5f, .5f));
g.fillRect(50, 50, 1000, 10);
}
void paint(Graphics& g) {
g.drawImageTransformed(im, AffineTransform::scale(2.0, 2.0));
}
Image im;
};
// put this class anywhere
class GlitchImage : public Component {
public:
GlitchImage(int width, int height) : im(Image::RGB, 100, 100, true) {
setSize(width, height);
Graphics g(im);
g.setColour(Colour(.5f, .5f, .5f, .5f));
g.fillRect(50, 50, 1000, 10);
}
void paint(Graphics& g) {
g.drawImageTransformed(im, AffineTransform::scale(2.0, 2.0));
}
Image im;
};
// now put these two lines at the bottom of the DemoControlsOverlay constructor:
GlitchImage *GI = new GlitchImage(500, 500); // leak...
addAndMakeVisible(GI);</pre>
The numbers don't really matter, I just put them in at random.
Here's a screenshot of what it looks like on my mac (this is retina but it's similar on my old non-retina):
Some observations:
- The same happens for opaque images, although transparency makes it easier to spot
- It's the same with images loaded from file
- It tends to be bottom row and rightmost column of pixels that are tainted, although colors tend to change on each run
- On some runs it looks fine, but most times the glitch is there
- The same happens with rotations, skews etc.
- It doesn't seem to happen for images with size 2^N, which leads one to think it has something to do with OpenGL textures...