Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JUCE Component Spout Sender
#include "JUCESpoutSender.h"
JUCESpoutSender::JUCESpoutSender() {
openGLContext.setComponentPaintingEnabled(true);
openGLContext.setRenderer(this);
openGLContext.setContinuousRepainting(false);
openGLContext.attachTo(*this);
//SPOUT
spoutSender = new SpoutSender();
strcpy_s(SenderName, "JUCE Spout Sender"); // we have to set a sender name first
}
JUCESpoutSender::~JUCESpoutSender(){
openGLContext.detach();
}
void JUCESpoutSender::newOpenGLContextCreated() {
//Image::Image ( PixelFormat format, int imageWidth, int imageHeight, bool clearImage, const ImageType & type )
spoutImage = Image(Image::ARGB, getWidth(), getHeight(), true, OpenGLImageType()); //create the openGL image
spoutSender->CreateSender(SenderName, getWidth(), getHeight());
}
void JUCESpoutSender::openGLContextClosing() {
spoutImage = Image::null;
}
void JUCESpoutSender::renderOpenGL() {
if (spoutImage.isValid())
{
Graphics g(spoutImage);
paintEntireComponent(g, false);
OpenGLFrameBuffer* tex1 = OpenGLImageType::getFrameBufferFrom(spoutImage);
spoutSender->SendTexture(tex1->getTextureID(), GL_TEXTURE_2D, getWidth(), getHeight());
}
}
void JUCESpoutSender::resized() {
spoutSender->UpdateSender(SenderName, getWidth(), getHeight());
}
#include "../JuceLibraryCode/JuceHeader.h"
#include "Spout\Spout.h"
#ifndef JUCESPOUTSENDER_H_INCLUDED
#define JUCESPOUTSENDER_H_INCLUDED
class JUCESpoutSender: public OpenGLRenderer, public Component {
public:
JUCESpoutSender();
~JUCESpoutSender();
void newOpenGLContextCreated() override;
void openGLContextClosing() override;
void renderOpenGL() override;
void resized() override;
private:
OpenGLContext openGLContext;
Image spoutImage;
ScopedPointer<SpoutSender> spoutSender;
char SenderName[256]; // sender name
};
#endif
@benkuper

This comment has been minimized.

Copy link

@benkuper benkuper commented Oct 25, 2016

Hi alfealeader,
i just saw your code and i'm trying to get Spout working inside Juce.
I'm actually part of the team that developped Spout (mainly plugins), but there's something i'm not getting.
This JuceSpoutSender class is meant to be any component or the main component ? Because i got an application that already has an openGL context and i don't know it my problem comes from here, but when i try to implement your class as a child component in my project, the "newOpenGLContextCreated" never gets called (none of the gl overrides gets called)

Is it because there cannot be more than one context ? Or is it something else ?
Do you have an idea ?

Thanks,
Ben

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.