Let me see…
I’m doing this in the .h, part of this as described in the juce docs
[code] void newOpenGLContextCreated();
void showOnDestop (const Rectangle &screenSpace);
void visibilityChanged();
bool renderAndSwapBuffers() { return true; } // Override to prevent juce drawing
void renderOpenGL() { return; } // Overide juce
void render(SyncSourceTimeRecord inTime); // Override Mesh Screen
#if JUCE_LINUX
GLXContext renderContext;
Display* threadDisplayConnection;
Window embeddedWindow;
#endif[/code]
The Linux stuff is because if rendering on a thread in Linux, you need to make your own display connection.
Then as an example, (my stuff is left in):
[code]void ScreenComponent::newOpenGLContextCreated()
{
needsReshape = true;
}
void ScreenComponent::visibilityChanged()
{
if (isVisible())
{
needsReshape = true;
startThread(4);
}
else
signalThreadShouldExit(); //stopThread(2000);
}
void ScreenComponent::mouseMove(const MouseEvent& e)
{
if (e.x < 8 || e.x > getWidth() - 8)
setMouseCursor (MouseCursor::NoCursor);
else
setMouseCursor (MouseCursor::NormalCursor);
}
void ScreenComponent::resized()
{
stopThread(2000);
setVisible(false); // will stop thread, clear OpenGL
// Unlike a normal screen, we can dynamically resize
width = getWidth();
height = getHeight();
// now mark this is the total space
screenSize.setBounds(0, 0, width, height);
// now note that we can draw into the whole space
activeArea.setWidth(width);
activeArea.setHeight(height);
needsReshape = true;
setVisible(true);
}
void ScreenComponent::render(SyncSourceTimeRecord inTime)
{
ScopedLock l(getContextLock());
#if JUCE_LINUX
// on linux, we deal with the context ourselves, so threads are OK
if (threadDisplayConnection == 0)
{
String displayName = T(":0.0"); // force 0.0 for GUI!
threadDisplayConnection = XOpenDisplay (displayName);
}
if (renderContext == 0)
{
needsReshape = true;
// get the top level X Window - we're going to tag onto it
ComponentPeer* const peer = getTopLevelComponent()->getPeer();
if (threadDisplayConnection && isShowing() && peer != 0)
{
XSync (threadDisplayConnection, False);
GLint attribs[] = { GLX_RGBA,
GLX_DOUBLEBUFFER,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_ALPHA_SIZE, 8,
GLX_DEPTH_SIZE, 16,
None };
int numConfigs = 0;
int screen = DefaultScreen (threadDisplayConnection);
XVisualInfo* const bestVisual = glXChooseVisual (threadDisplayConnection, screen, attribs);
if (bestVisual == 0)
return;
renderContext = glXCreateContext (threadDisplayConnection, bestVisual,
(getShareContext() != 0) ? (GLXContext)(getShareContext()->getRawContext()) : 0,
GL_TRUE);
Window windowH = (Window) peer->getNativeHandle();
Colormap colourMap = XCreateColormap (threadDisplayConnection, windowH, bestVisual->visual, AllocNone);
XSetWindowAttributes swa;
swa.colormap = colourMap;
swa.border_pixel = 0;
swa.event_mask = ExposureMask | StructureNotifyMask;
embeddedWindow = XCreateWindow (threadDisplayConnection, windowH,
0, 0, 1, 1, 0,
bestVisual->depth,
InputOutput,
bestVisual->visual,
CWBorderPixel | CWColormap | CWEventMask,
&swa);
XSaveContext (threadDisplayConnection, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
XMapWindow (threadDisplayConnection, embeddedWindow);
XFreeColormap (threadDisplayConnection, colourMap);
XFree (bestVisual);
XSync (threadDisplayConnection, False);
if (renderContext != 0)
{
//updateContextPosition();
}
}
}
if (needsReshape && threadDisplayConnection && embeddedWindow)
{
int x = getX();
int y = getY();
ComponentPeer* const peer = getTopLevelComponent()->getPeer();
Component::relativePositionToOtherComponent (getTopLevelComponent(), x, y);
XMoveResizeWindow (threadDisplayConnection, embeddedWindow, x, y, jmax (1, width), jmax (1, height));
}
if (renderContext != 0 && glXMakeCurrent (threadDisplayConnection, embeddedWindow, renderContext) && XSync (threadDisplayConnection, False))
#else
if (makeCurrentContextActive()) // will create one if needed
#endif
{
if (needsReshape)
{
initOpenGL();
needsReshape = false;
}
MeshScreen::render(inTime);
#if JUCE_LINUX
glXSwapBuffers (threadDisplayConnection, embeddedWindow);
#else
swapBuffers();
#endif
}
}[/code]
You have to bear in mind you’re not on the main thread, as with most other juce drawing, but it does update as often as you get your thread to run.
Bruce