mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
New method OpenGLContext::getRenderingScale(). Updated the GL demo to use this method of getting the display scale.
This commit is contained in:
parent
295265fb28
commit
2651911b87
3 changed files with 26 additions and 16 deletions
|
|
@ -109,7 +109,9 @@ public:
|
|||
OpenGLHelpers::clear (Colours::darkgrey.withAlpha (1.0f));
|
||||
|
||||
updateTextureImage(); // this will update our dynamically-changing texture image.
|
||||
drawBackground2DStuff(); // draws some 2D content to demonstrate the OpenGLGraphicsContext class
|
||||
|
||||
const float scale = (float) openGLContext.getRenderingScale();
|
||||
drawBackground2DStuff (scale); // draws some 2D content to demonstrate the OpenGLGraphicsContext class
|
||||
|
||||
// Having used the juce 2D renderer, it will have messed-up a whole load of GL state, so
|
||||
// we'll put back any important settings before doing our normal GL 3D drawing..
|
||||
|
|
@ -120,8 +122,9 @@ public:
|
|||
glEnable (GL_TEXTURE_2D);
|
||||
|
||||
#if JUCE_USE_OPENGL_FIXED_FUNCTION
|
||||
OpenGLHelpers::prepareFor2D (getContextWidth(), getContextHeight());
|
||||
OpenGLHelpers::setPerspective (45.0, getContextWidth() / (double) getContextHeight(), 0.1, 100.0);
|
||||
OpenGLHelpers::prepareFor2D (roundToInt (scale * getWidth()),
|
||||
roundToInt (scale * getHeight()));
|
||||
OpenGLHelpers::setPerspective (45.0, getWidth() / (double) getHeight(), 0.1, 100.0);
|
||||
|
||||
glTranslatef (0.0f, 0.0f, -5.0f);
|
||||
draggableOrientation.applyToOpenGLMatrix();
|
||||
|
|
@ -163,23 +166,23 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void drawBackground2DStuff()
|
||||
void drawBackground2DStuff (float scale)
|
||||
{
|
||||
// Create an OpenGLGraphicsContext that will draw into this GL window..
|
||||
ScopedPointer<LowLevelGraphicsContext> glRenderer (createOpenGLGraphicsContext (openGLContext,
|
||||
getContextWidth(),
|
||||
getContextHeight()));
|
||||
roundToInt (scale * getWidth()),
|
||||
roundToInt (scale * getHeight())));
|
||||
|
||||
if (glRenderer != nullptr)
|
||||
{
|
||||
Graphics g (glRenderer);
|
||||
g.addTransform (AffineTransform::scale ((float) getScale()));
|
||||
g.addTransform (AffineTransform::scale (scale));
|
||||
|
||||
// This stuff just creates a spinning star shape and fills it..
|
||||
Path p;
|
||||
const float scale = getHeight() * 0.4f;
|
||||
p.addStar (Point<float> (getWidth() * 0.7f, getHeight() * 0.4f), 7,
|
||||
scale * (float) sizeSlider.getValue(), scale,
|
||||
getHeight() * 0.4f * (float) sizeSlider.getValue(),
|
||||
getHeight() * 0.4f,
|
||||
rotation / 50.0f);
|
||||
|
||||
g.setGradientFill (ColourGradient (Colours::green.withRotatedHue (fabsf (::sinf (rotation / 300.0f))),
|
||||
|
|
@ -190,10 +193,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
double getScale() const { return Desktop::getInstance().getDisplays().getDisplayContaining (getScreenBounds().getCentre()).scale; }
|
||||
int getContextWidth() const { return roundToInt (getScale() * getWidth()); }
|
||||
int getContextHeight() const { return roundToInt (getScale() * getHeight()); }
|
||||
|
||||
void timerCallback()
|
||||
{
|
||||
rotation += (float) speedSlider.getValue();
|
||||
|
|
|
|||
|
|
@ -164,6 +164,7 @@ public:
|
|||
if (context.renderer != nullptr)
|
||||
{
|
||||
glViewport (0, 0, viewportArea.getWidth(), viewportArea.getHeight());
|
||||
context.currentRenderScale = scale;
|
||||
context.renderer->renderOpenGL();
|
||||
clearGLError();
|
||||
}
|
||||
|
|
@ -527,8 +528,8 @@ private:
|
|||
|
||||
//==============================================================================
|
||||
OpenGLContext::OpenGLContext()
|
||||
: nativeContext (nullptr), renderer (nullptr), contextToShareWith (nullptr),
|
||||
renderComponents (true), useMultisampling (false)
|
||||
: nativeContext (nullptr), renderer (nullptr), currentRenderScale (1.0),
|
||||
contextToShareWith (nullptr), renderComponents (true), useMultisampling (false)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -200,6 +200,16 @@ public:
|
|||
*/
|
||||
int getSwapInterval() const;
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the scale factor used by the display that is being rendered.
|
||||
|
||||
The scale is that of the display - see Desktop::Displays::Display::scale
|
||||
|
||||
Note that this should only be called during an OpenGLRenderer::renderOpenGL()
|
||||
callback - at other times the value it returns is undefined.
|
||||
*/
|
||||
double getRenderingScale() const noexcept { return currentRenderScale; }
|
||||
|
||||
//==============================================================================
|
||||
/** Returns an OS-dependent handle to some kind of underlting OS-provided GL context.
|
||||
|
||||
|
|
@ -209,7 +219,6 @@ public:
|
|||
*/
|
||||
void* getRawContext() const noexcept;
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/** Draws the currently selected texture into this context at its original size.
|
||||
|
||||
|
|
@ -240,6 +249,7 @@ private:
|
|||
class Attachment;
|
||||
NativeContext* nativeContext;
|
||||
OpenGLRenderer* renderer;
|
||||
double currentRenderScale;
|
||||
ScopedPointer<Attachment> attachment;
|
||||
OpenGLPixelFormat pixelFormat;
|
||||
void* contextToShareWith;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue