Attach OpenGLContext directly to MainWindow


#1

Hello World! (First post, first usage of JUCE)

Just having my first stab at writing a JUCE application. What I’m trying to do is, for a very simple OpenGL renderer prototype, to attach the context directly to MainWindow (which is a Component after all), by doing:

mainWindow = new MainWindow(getApplicationName());

JUCEApplication::initialise() {
glContext = new OpenGLContext();
// glContext->setPixelFormat(OpenGLPixelFormat());
glContext->setComponentPaintingEnabled(false);
glContext->setRenderer(analysisRenderer);

glContext->attachTo(*mainWindow);

// glContext->setContinuousRepainting(true);
}

The MainWindow is setVisible(true), didn’t change anything in the generated code. AudioAnalysisRenderer::renderOpenGL is never called this way, does not change when setContinuousRepainting is set to true. Is this a problem with using the MainWindow as the component rendered to? In the end I would of course create a dedicated Component which contains the OpenGLRenderer anyways, just wondering wether this should not be working either way.

Aside, I suppose setPixelFormat is not mandatory and the default parameters will be used if not called? The docs state “This must be called BEFORE attaching your context to a target component!” which is a bit ambiguous, if the call is optional (which I assume) the docs could maybe be enhanced to state that there is actually a default. Setting the pixel format didn’t change the behaviour anyhow…

Having a first closer look at JUCE, after having heard only the best about it from a technical viewpoint, I must say that my first impression is really really good, keep up the good work Jules! In case I might find bugs or problems, what would be the preferred way of contributing?

Thanks and best regards,
Patric


#2

OUCH! Seems linebreaks get swallowed in the posts when plain text format is selected? Well here we go in HTML, sorry! :)


Hello World! (First post, first usage of JUCE)


Just having my first stab at writing a JUCE application. What I'm trying to do is, for a very simple OpenGL renderer prototype, to attach the context directly to MainWindow (which is a Component after all), by doing:

JUCEApplication::initialise() {
    mainWindow = new MainWindow(getApplicationName());

    glContext  = new OpenGLContext();
// glContext->setPixelFormat(OpenGLPixelFormat());
    glContext->setComponentPaintingEnabled(false);
    glContext->setRenderer(analysisRenderer);
    glContext->attachTo(*mainWindow);
// glContext->setContinuousRepainting(true);
}


The MainWindow is setVisible(true), didn't change anything in the generated code. AudioAnalysisRenderer::renderOpenGL is never called this way, does not change when setContinuousRepainting is set to true. Is this a problem with using the MainWindow as the component rendered to? In the end I would of course create a dedicated Component which contains the OpenGLRenderer anyways, just wondering wether this should not be working either way.


Aside, I suppose setPixelFormat is not mandatory and the default parameters will be used if not called? The docs state "This must be called BEFORE attaching your context to a target component!" which is a bit ambiguous, if the call is optional (which I assume) the docs could maybe be enhanced to state that there is actually a default. Setting the pixel format didn't change the behaviour anyhow..


Having a first closer look at JUCE, after having heard only the best about it from a technical viewpoint, I must say that my first impression is really really good, keep up the good work Jules! In case I *might* find bugs or problems, what would be the preferred way of contributing?


Thanks and best regards,
Patric
 


#3

Hi Patric, glad you like the library, and the forum is a good place to report bugs and other comments.

Not sure if there'd be a problem using the top-level window.. Wouldn't have expected that, but you could try attaching it to the content component to see if that helps..


#4

Ok rolled my own Component, attaching to that one and adding the Component to the DocumentWindow with setContentOwned works as expected. For me this was more out of interest anyways since it makes sense to implement the function in a dedicated Component anyways. You might want to investigate why it doesn't work with DocumentWindow in case you care about that, for me it's fine like that, maybe you just want to add a hint in the docs somewhere.. Thanks!


#5

Thanks - yes, I also want to add something to make it easier to enable the GL renderer for a whole window anyway. Will sort that out soon.