Hi Jules,
it seems that an OpenGLComponent that has been set invisible, won’t appear again when setVisible(true) is called.
To demonstrate this, I created an application with a basic window that uses an OpenGLComponent child which can be set visible with a toggle button. After the OpenGLComponent has been made invisible it won’t show again.
This is the code I used (havn’t changed main.cpp):
MainWindow.cpp
/*
==============================================================================
This file was auto-generated!
It contains the basic outline for a simple desktop window.
==============================================================================
*/
#include "MainWindow.h"
//==============================================================================
MainAppWindow::MainAppWindow()
: DocumentWindow (JUCEApplication::getInstance()->getApplicationName(),
Colours::lightgrey,
DocumentWindow::allButtons)
{
centreWithSize (500, 400);
setContentNonOwned(&content, true);
setVisible (true);
}
MainAppWindow::~MainAppWindow()
{
clearContentComponent();
}
void MainAppWindow::closeButtonPressed()
{
JUCEApplication::getInstance()->systemRequestedQuit();
}
MainWindow.h:
/*
==============================================================================
This file was auto-generated!
It contains the basic outline for a simple desktop window.
==============================================================================
*/
#ifndef __MAINWINDOW_H_57A53197__
#define __MAINWINDOW_H_57A53197__
#include "../JuceLibraryCode/JuceHeader.h"
class Comp : public OpenGLComponent
{
public:
Comp()
: OpenGLComponent(OpenGLComponent::useBackgroundThread)
{
red = 0;
}
~Comp()
{
stopRenderThread();
}
void renderOpenGL()
{
red = 0.9f*red + 0.1f*Random::getSystemRandom().nextFloat();
glClearColor (red, 0.f, 0.f, 0.f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void newOpenGLContextCreated()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
private:
float red;
};
class Content : public Component, public Button::Listener
{
public:
Content()
{
addAndMakeVisible(&comp);
addAndMakeVisible(&tb);
tb.setButtonText("OpenGL Component Visible");
tb.setToggleState(true, false);
tb.addListener(this);
setSize(200, 200);
}
void paint(Graphics& g)
{
g.fillAll(Colours::lightgrey);
}
void resized()
{
comp.setBounds(10, 10, 100, 100);
tb.setBounds(10, 130, 180, 20);
}
void buttonClicked (Button* button)
{
comp.setVisible(tb.getToggleState());
}
private:
Comp comp;
ToggleButton tb;
};
//==============================================================================
class MainAppWindow : public DocumentWindow
{
public:
//==============================================================================
MainAppWindow();
~MainAppWindow();
void closeButtonPressed();
/* Note: Be careful when overriding DocumentWindow methods - the base class
uses a lot of them, so by overriding you might break its functionality.
It's best to do all your work in you content component instead, but if
you really have to override any DocumentWindow methods, make sure your
implementation calls the superclass's method.
*/
private:
Content content;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainAppWindow)
};
#endif // __MAINWINDOW_H_57A53197__
Edit: Visual Studio 2008 Windows 7/64-bit, quite current juce (last week; I tried to quickly use the current tip, but the Introjucer is quite persistent when it comes to not changing the modules path, e.g. no matter what path is given in “module source folder” it will save using the one it was generated with); Havn’t tried on OS X yet.
Chris