Hi community
I need to add some Uniform variables to a fragment shader. I have started to create a new OpenGl project from Introjucer and, on the other hand, I followed the structure of OpenGL2D example in the demo app.
Further, I have used:
OpenGLShaderProgram* OpenGLGraphicsContextCustomShader::getProgram ( LowLevelGraphicsContext & )
inside of paint(Graphics& g) method in order to get a pointer to the shader program and so, to add the uniform variable, according to documentation explanation:
"This can be called when you're about to use fillRect, to set up any uniforms/textures that the program may require."
The paint() code excerpt is this:
void paint (Graphics& g) override { String str = file->loadFileAsString(); shader = new OpenGLGraphicsContextCustomShader(str); Result result(shader->checkCompilation(g.getInternalContext())); if (result.failed()) { String strErr = result.getErrorMessage(); shader = nullptr; } if (shader != nullptr) { OpenGLShaderProgram* pPgm = shader->getProgram(g.getInternalContext()); pPgm->setUniform("viewSize", (float)getWidth(), (float)getHeight()); shader->fillRect(g.getInternalContext(), getLocalBounds()); } }
At this point, the code gets a runtime error due to pPgm->setUniform() insertion.:
JUCE v4.1.0
***** GL_INVALID_OPERATION at c:\intlaas\00 sdks\juce\modules\juce_opengl\opengl\juce_openglgraphicscontext.cpp : 1293
JUCE Assertion failure in juce_opengl.cpp:153
Being the stack:
juce::checkGLError(const char *, const int) Line 153 C++
juce::OpenGLRendering::StateHelpers::CurrentShader::setShader(const juce::Rectangle<int> &, juce::OpenGLRendering::StateHelpers::ShaderQuadQueue &, juce::OpenGLRendering::ShaderPrograms::ShaderBase &) Line 1293 C++
juce::OpenGLRendering::StateHelpers::CurrentShader::setShader(juce::OpenGLRendering::Target &, juce::OpenGLRendering::StateHelpers::ShaderQuadQueue &, juce::OpenGLRendering::ShaderPrograms::ShaderBase &) Line 1305 C++
juce::OpenGLRendering::GLState::setShader(juce::OpenGLRendering::ShaderPrograms::ShaderBase &) Line 1369 C++
juce::OpenGLRendering::SavedState::fillRectWithCustomShader(juce::OpenGLRendering::ShaderPrograms::ShaderBase &, const juce::Rectangle<int> &) Line 1691 C++
juce::OpenGLRendering::ShaderContext::fillRectWithCustomShader(juce::OpenGLRendering::ShaderPrograms::ShaderBase &, const juce::Rectangle<int> &) Line 1724 C++
So, what am I doing wrong? Can I use Uniforms in a OpenGLAppComponent derived component? Have the uniform to be injected in another place or moment?
Thank you for your answers in advance,
Gabriel