OpenGL Basics with JUCE


I am relatively new to JUCE and very new to OpenGL. First, let me explain what I am trying to do.

I am simply trying to create a 3-D shape, nothing fancy. I am using haydxn's starting point JUCE GUI application code:

which is just 4 files and when built, creates an empty top-level window. An instance of the MainComponent class is placed on the window. I am trying to develop this MainComponent class to render a 3-D shape on the window. The code that I currently have for the MainComponent class is below (it does not work!). It seems whatever way I try I get a different error. I am just looking for the simplest way to accomplish my goal. I could probably figure it out if I played with it long enough, however time is not a commodity! 

I would like to use either OpenGLHelpers::drawQuad3D() or OpenGLFrameBuffer::draw3D() as those seem particularly useful, but any way to get the job done works. If anyone has any suggestions I would GREATLY appreciate it!





#include "../JuceLibraryCode/JuceHeader.h"


class MainComponent  : public Component,

                       private OpenGLRenderer





    TooltipWindow tooltipWindow;


    OpenGLContext openGLContext;

    Image myImage;

    OpenGLFrameBuffer frameBuffer;




    MainComponent ()



        openGLContext.attachTo(*this); //attach an openGL context to this MainComponent




    ~MainComponent ()


        openGLContext.detach();  //detach the OpenGL conext from this MainComponent


        deleteAllChildren();    // This will remove all the contained components, and delete

        // the objects for you.



    void newOpenGLContextCreated() override



    int w = getWidth();

    int h = getHeight();

    myImage = Image(Image::ARGB, w, h, true, OpenGLImageType());




    void renderOpenGL() override



    frameBuffer.initialise(openGLContext, myImage);



    float x1 = 0.5; float y1 = 0.5; float z1 = 0;

    float x2 = 0.5; float y2 = -0.5; float z2 = 0;

    float x3 = -0.5; float y3 = 0.5; float z3 = 0;

    float x4 = -0.5; float y4 = -0.5; float z4 = 0;


    frameBuffer.draw3D (x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, Colours::red);




    void openGLContextClosing() override





    void resized ()





    void paint (Graphics& g)











Having a look at the GL demo in the juce demo app is probably the best place to start.

I've actually just deleted those old drawQuad3D methods - unfortunately for beginners, the old fashioned pre-shader way of working with GL is just not the way people do things any more. You can still use those methods via direct GL calls of course, but I don't think there's any need for juce to carry on support for those old calls, especially since they don't exist on mobile devices. 

I'm afraid that to write any kind of modern GL app you'll need to learn about shaders + uniforms, which is very powerful, but quite a learning curve!