Well - hereās my shonky OpenGL to get that far in case itās useful. I have only about 50% of a clue what Iām doing at the moment, and no idea why my image appears where it does at the size it does
#pragma once
#include "../JuceLibraryCode/JuceHeader.h"
//==============================================================================
/*
This component lives inside our window, and this is where you should put all
your controls and content.
*/
class MainComponent : public Component, Timer, OpenGLRenderer
{
public:
MainComponent()
{
setSize (600, 400);
context.setRenderer(this);
context.setComponentPaintingEnabled(false);
context.setContinuousRepainting(true);
context.attachTo(*getTopLevelComponent());
startTimer(100);
}
void paint (Graphics&g) override
{
g.fillAll(Colours::blue);
}
void timerCallback() override
{
repaint();
}
void resized() override
{}
void newOpenGLContextCreated () override
{
shader = new OpenGLShaderProgram(context);
shader->addFragmentShader(shaderWotBlurs);
shader->link();
createTexture();
}
void renderOpenGL () override
{
OpenGLHelpers::clear (Colours::black);
glDisable(GL_LIGHTING);
glColor3f(1, 1, 1);
glEnable(GL_TEXTURE_2D);
texture.bind();
shader->use();
// Draw a textured quad
glBegin(GL_QUADS);
auto w = getWidth();
auto h = getHeight();
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(0, h); glVertex3f(0, h, 0);
glTexCoord2f(w, h); glVertex3f(w, h, 0);
glTexCoord2f(w, 0); glVertex3f(w, 0, 0);
glEnd();
}
void openGLContextClosing () override
{}
class CompToRenderWithOpenGL : public Component
{
public:
void paint (Graphics& g) override
{
g.fillAll(Colours::red);
g.setColour(Colours::white);
g.drawText("Hello world", 0, 0, 100, 20, Justification::centred, false);
}
};
void createTexture()
{
CompToRenderWithOpenGL comp;
Image im{ Image::ARGB, getWidth(), getHeight(), true };
comp.setSize(getWidth(), getHeight());
{
Graphics gi{ im };
MessageManagerLock lock;
comp.paintEntireComponent(gi, true);
}
texture.loadImage(im);
}
private:
OpenGLTexture texture;
ScopedPointer<OpenGLShaderProgram> shader;
OpenGLContext context;
String shaderWotBlurs =
"uniform sampler2D sampler0;"
"uniform vec2 tc_offset[9];"
"void main()"
"{"
" vec4 sample[9];"
" for (int i = 0; i < 9; ++i)"
" sample[i] = texture2D(sampler0, gl_TexCoord[0].st + tc_offset[i]);"
""
" gl_FragColor = (sample[0] + (2.0 * sample[1]) + sample[2] +"
" (2.0 * sample[3]) + sample[4] + 2.0 * sample[5] +"
" sample[6] + 2.0 * sample[7] + sample[8]) / 13.0;"
"}";
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};