Last active
October 25, 2016 20:01
-
-
Save alfaleader/84e30a23c4d0e5ea9041ff76f1d3e43a to your computer and use it in GitHub Desktop.
JUCE Component Spout Sender
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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()); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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