Juce/c++ newbie question


#1

okay, so to show my total lack of knowledge of either subject, i have what i think is a really simple question that has me somewhat befuddled.

i’m taking the opengl demo app and adding a simple function to do alpha testing. i want to add a slider that controls my alpha test value (for those curious, alpha testing is a way to discard fragments based on an alpha threshhold test – useful for depth buffer sanity with alpha textures like the “juce box”).

so here’s the problem. opengl doesn’t mix well with juce. so i’m adding a slider component to the OpenGLDemo class instead of the DemoOpenGLCanvas class. works fine, draws appropriately, etc. the problem is, how do i get its value?

is this my lack of c++ knowledge (i’m a c programmer) or my lack of juce knowledge that’s the problem? in my renderOpenGL function, i would love to simply call a getValue() for my alphaSlider, but the alphaSlider is unknown to the DemoOpenGLCanvas class. it’s a member of the “parent” object, so it would seem that there’s gotta be a simple way to reference up one level or something… but that’s where my lack of c++ gets me.

i thought about going the route of listeners and such, but the same problem exists – no ability to reference alphaSlider from the DemoOpenGLCanvas class…

what am i doing wrong?


#2

nevermind. i’m an idiot.

i just added an additional public member called “alphaSlider” to the demoopenglcanvas class and then, after initializing the canvas and the alphaslider in the opengldemo class, i set that slider pointer to be pointing to the opengldemo’s instance of the alphaSlider.

is it safe to “addandmakevisibile()” a non-member? that is, could i do the following:

    canvas = new DemoOpenGLCanvas();
    addAndMakeVisible (canvas);
		
    canvas->alphaSlider = new Slider(T("alphaSlider"));
    addAndMakeVisible (canvas->alphaSlider);	

would that cause any issue with memory cleanup or anything? would that be the cleanest way to do what i’m wanting?


#3
    canvas = new DemoOpenGLCanvas();
// This should be in the constructor of canvas
    canvas->alphaSlider = new Slider(T("alphaSlider"));
    addAndMakeVisible (canvas->alphaSlider);  
// Okay back to the previous method
    addAndMakeVisible (canvas);

is okay too.


#4

would that work with an opengl context? wouldn’t addAndMakeVisibile() want to draw the slider in my opengl context (which doesn’t work)?


#5