1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

More OpenGL work.

This commit is contained in:
jules 2011-10-10 18:30:51 +01:00
parent 61f5ca11ab
commit f31dca5f2f
30 changed files with 562 additions and 101 deletions

View file

@ -157,14 +157,14 @@ AffineTransform AffineTransform::scale (const float factorX, const float factorY
}
AffineTransform AffineTransform::scaled (const float factorX, const float factorY,
const float pivotX, const float pivotY) const noexcept
const float pivotX, const float pivotY) const noexcept
{
return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02 + pivotX * (1.0f - factorX),
factorY * mat10, factorY * mat11, factorY * mat12 + pivotY * (1.0f - factorY));
}
AffineTransform AffineTransform::scale (const float factorX, const float factorY,
const float pivotX, const float pivotY) noexcept
const float pivotX, const float pivotY) noexcept
{
return AffineTransform (factorX, 0, pivotX * (1.0f - factorX),
0, factorY, pivotY * (1.0f - factorY));
@ -186,6 +186,11 @@ AffineTransform AffineTransform::sheared (const float shearX, const float shearY
shearY * mat02 + mat12);
}
AffineTransform AffineTransform::verticalFlip (const float height) noexcept
{
return AffineTransform (1.0f, 0, 0, 0, -1.0f, height);
}
AffineTransform AffineTransform::inverted() const noexcept
{
double determinant = (mat00 * mat11 - mat10 * mat01);

View file

@ -185,6 +185,11 @@ public:
/** Returns a shear transform, centred around the origin (0, 0). */
static AffineTransform shear (float shearX, float shearY) noexcept;
/** Returns a transform that will flip co-ordinates vertically within a window of the given height.
This is handy for converting between upside-down coordinate systems such as OpenGL or CoreGraphics.
*/
static AffineTransform verticalFlip (float height) noexcept;
/** Returns a matrix which is the inverse operation of this one.
Some matrices don't have an inverse - in this case, the method will just return

View file

@ -116,7 +116,16 @@ public:
Image::SharedImage* clone()
{
return new SubsectionSharedImage (image->clone(), area);
Image newImage (format, area.getWidth(), area.getHeight(),
format != Image::RGB, image->getType());
{
Graphics g (newImage);
g.drawImageAt (Image (this), 0, 0);
}
newImage.getSharedImage()->incReferenceCount();
return newImage.getSharedImage();
}
private:

View file

@ -169,8 +169,7 @@ void CoreGraphicsContext::setOrigin (int x, int y)
void CoreGraphicsContext::addTransform (const AffineTransform& transform)
{
applyTransform (AffineTransform::scale (1.0f, -1.0f)
.translated (0, flipHeight)
applyTransform (AffineTransform::verticalFlip (flipHeight)
.followedBy (transform)
.translated (0, -flipHeight)
.scaled (1.0f, -1.0f));
@ -253,7 +252,7 @@ void CoreGraphicsContext::clipToImageAlpha (const Image& sourceImage, const Affi
CGImageRef image = CoreGraphicsImage::createImage (singleChannelImage, true, greyColourSpace, true);
flip();
AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
AffineTransform t (AffineTransform::verticalFlip (sourceImage.getHeight()).followedBy (transform));
applyTransform (t);
CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
@ -447,7 +446,7 @@ void CoreGraphicsContext::drawImage (const Image& sourceImage, const AffineTrans
CGContextSetAlpha (context, state->fillType.getOpacity());
flip();
applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, ih).followedBy (transform));
applyTransform (AffineTransform::verticalFlip (ih).followedBy (transform));
CGRect imageRect = CGRectMake (0, 0, iw, ih);
if (fillEntireClipAsTiles)