Viewport & OpengLComponent Issue



I’m trying to explore an OpenGL 2D drawing in a Viewport.

But I dont manage to correctly concept this.

First, I created a global.class, which addAndMakeVisible both a Viewport instance and an OpenGLComponent instance. I ve set the viewport-viewed component as OpenGLComponent instance.
It ruled, I mean, both Components were visibles, and my OpenGL one was 2D-move controlled by the Viewport one.
Of course, they are both on the same visualisation level : I mean there is no hierarchy betwenn OpenGL comp and Viewport comp.

Ok Then I created Viewer.class, which derivates from Viewport, and set the viewed component as my OpenGLComponent instance.
I instanciated the Viewer.class in my global.class, hoping this time my OpenGL will be inside my Viewport.

But i dont see anything.

Thanks for help.


By “i dont see anything” I mean : OpenGL & Viewport sliders are not visible.


Have you checked that you’ve got the JUCE_OPENGL flag enabled in juce_Config? And that you can build and run the juce demo with its opengl test successfully? If so, you’ve probably just done something simple like forgotten to setVisible or give the components a sensible size and position, or something.


Well, my openGl options is ok (1),
i tried to make my own code and to make this made by Jucer,
i got it, which seems to me ok :


This is an automatically generated file created by the Jucer!

Creation date: 25 Sep 2008 2:53:20 pm

Be careful when adding custom code to these files, as only the code within
the “//[xyz]” and “//[/xyz]” sections will be retained when the file is loaded
and re-saved.

Jucer version: 1.11

The Jucer is part of the JUCE library - "Jules’ Utility Class Extensions"
Copyright 2004-6 by Raw Material Software ltd.


//[Headers] You can add your own extra header files here…

#include “myComp.h”

//[MiscUserDefs] You can add your own user definitions and misc code here…

myComp::myComp ()
: viewport (0)
addAndMakeVisible (viewport = new Viewport (T(“SeqWindow”)));
viewport->setViewedComponent (new myOpenGLComp());


setSize (200, 200);

//[Constructor] You can add your own custom stuff here..


//[Destructor_pre]. You can add your own custom destruction code here…

deleteAndZero (viewport);

//[Destructor]. You can add your own custom destruction code here..


void myComp::paint (Graphics& g)
//[UserPrePaint] Add your own custom painting code here…

g.fillAll (Colours::white);

//[UserPaint] Add your own custom painting code here..


void myComp::resized()
viewport->setBounds (0, 0, proportionOfWidth (1.0000f), proportionOfHeight (1.0000f));
//[UserResized] Add your own custom resize handling here…

//[MiscUserCode] You can add your own definitions of your custom methods or any other code here…

#if 0
/* – Jucer information section –

This is where the Jucer puts all of its metadata, so don't change anything in here!


<JUCER_COMPONENT documentType=“Component” className=“myComp” componentName="“
parentClasses=“public Component” constructorParams=”" variableInitialisers=""
snapPixels=“8” snapActive=“1” snapShown=“1” overlayOpacity="0.330000013"
fixedSize=“0” initialWidth=“200” initialHeight=“200”>




however nothing appears but a coloured square, like the colour specified in the paint method.

If i do the same withour viewport and by putting direclyt my openGl comp inside the tab, the openGl comp appears.[/quote]


Well, then you’re obviously not setting up the viewport correctly. Check all your component bounds, and you’ll probably just find something that’s got (0, 0) size.


thanks, it rules now.

I get something probably easy to fix but out of wish :
my openGl comp is overriding all, thus when I scroll my viewport, my OpenGL drawing gets over my arounded components…

Can you help please ?


Yes, well that’s because the opengl has to be drawn as a heavyweight window, but the rest of the juce comps are lightweight - so they can’t be drawn over the top. It’s the same with other embedded windows, and you get the same thing in any other UI libraries that use lightweight comps.


Ok. By the way, my OpenGLComponent is not windowed, but takes place amongst many components and subcomponents.
But I guess it’s the same concept.

Much thanks.