OpenGLComponent can't be made visible again


#1

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


#2

Can you please stop posting openGL errors for a while!

I’m in the middle of restructuring the whole context system, so all the code will change quite soon. And when I’ve got it all into the shape that I want it, I’m going to do plenty of testing of this kind of thing. Telling me about problems like this while I’m in the middle of working on it is just a distraction!


#3

Didn’t know you were deeply in the OpenGL code atm.

Can you give a rough estimate when you’re done with the restructuring?

Chris


#4

Soon! I just need to do some audio stuff for a few days, then back to sorting out GL…


#5

[quote=“jules”]
I’m in the middle of restructuring the whole context system, so all the code will change quite soon. And when I’ve got it all into the shape that I want it, I’m going to do plenty of testing of this kind of thing. Telling me about problems like this while I’m in the middle of working on it is just a distraction![/quote]

Hey Jules, just some relevant (I hope) data as you’re doing major GL changes - juce tip currently uses OpenGL 3.0 functions that are not available on OS X 10.5 powerpc (and maybe 10.5 intel as well).

Those seem to be only needed for components sharing rects with other components, and as I don’t use this functionality, a quick’n’dirty #if-ing of these calls out worked fine for me :slight_smile: - https://github.com/yairchu/juce/commit/a79d7610ea311e39136e2234da28eeb678498a82

Cheers!


#6

Ok, thanks for the heads-up on that!


#8

Hi, was it solved ? Cause I have the same issue…


#9

The GL code is completely different to what was there in 2012 - rather than reopening this thread, maybe post explaining your own problem and how we can reproduce it with the very latest version.