Juce OpenGL Component with Microsoft Driver

Hi all,
I am having a problem with JUCE openGL component with microsoft generic drivers on windows. It looks like juce opengl component doesnot repaint, when the user machine has generic drivers by microsoft which implement opengl v1.1.
The same opengl code works fine when we use MFC/Win32 for windowing insted of JUCE.
Has anyone experienced such problems before?
Any Idea as to why this may be happening?


Is it the same in the juce demo’s opengl page? That works ok on every machine I’ve tried it on.

Yes. OpenGL Component does not repaint.

Do they have microsoft drivers?
Also I compiled the Mesa 3D opengl binaries (from http://www.mesa3d.org) and put them in the juce demo folder and bingo! it started working fine.

Any Idea as to what may be going wrong?

Yogesh Kini[/quote]

Haven’t the faintest idea what’s going wrong, sorry! Any opengl experts out there?

maybe it’s because of the pixel format : in juce_Win32_Windowing.cpp line 2875

try to change the size of depth buffer to 16 instead of 32 (line 2887)

if not working try to force the generic driver with PFD_GENERIC_FORMAT in the first structure’s member to see what windows says about it.

you may look at the pixel format index returned by ChoosePixelFormat() and by using the nv pixel format utility you should obtain more information about it.

Hi all,
Well there definitely seems to problem with OpenGL component, when using generic microsoft drivers . Problem is regenerating the bug is difficult.
You got to iterate through all pixel formats using DescribePixelFormat and choose a PixelFormat that has PFD_GENERIC_FORMAT flag set.

Now when using this pixel format you create a juce OpenGL component , it appears hollow and does not repaint.

Lots of my customers seem to have old drivers by Microsoft and are reluctant to upgrade to the latest drivers.

I am attaching a patched version of juce and juce-Demo. Changes made only to the juce_Win32_Windowing.cpp.

I would be obliged if someone would look into the code and give me pointers as to what could fix the problem.

Changes made are

[code]int totalformats = DescribePixelFormat(oc->dc,1,sizeof(PIXELFORMATDESCRIPTOR),&pfd);
int selectedFormat = -1;
while(totalformats > 0)
if((pfd.dwFlags & PFD_DRAW_TO_WINDOW) &&
(pfd.dwFlags & PFD_SUPPORT_OPENGL)&&
(pfd.dwFlags & PFD_DOUBLEBUFFER)&&
(pfd.dwFlags & PFD_GENERIC_FORMAT)&& // Make sure it is Microsoft Generic Driver
(pfd.iPixelType == PFD_TYPE_RGBA) &&
(pfd.cColorBits == 32) &&
(pfd.cDepthBits == 16)
selectedFormat = totalformats;
break; //We got our format ,so break.

jassert(selectedFormat != -1) //oops! no matching format

//Finally Dont use "ChoosePixelFormat" instead use our format selected above.	
SetPixelFormat (oc->dc, /*ChoosePixelFormat (oc->dc, &pfd)*/ selectedFormat, &pfd);[/code]

Link : http://www.sharebigfile.com/file/116643/juce-with-ogl-problem-zip.html
Many Thanks,
Yogesh Kini

Well I had a quick go and the SetPixelFormat call was failing - probably because the format wasn’t supported. If I changed the depth from 16 to 32 it did actually work, though very slowly and clunkily…

Hello there,

I have just downloaded juce and have compiled the demo. I to cannot get the OpenGLDemo component to show. There is no re-draw. All the suggestions that have been made on this thread I’ve tried, still no luck.

I’m writing a VST instrument that will require 3D graphics. I am very keen to start working with juce (so far it’s the best system I have investigated for my needs) but I really need OpenGL or DirectX. Ideally it would be OpenGL so I can make the VST cross-platform.

My development system is fairly old (about 3-4 years old, A P4 2GHz machine) but the graphics card on it is relevant and fairly new. Plus, I have been able to compile numerous OpenGL applications on my system thus far. I’m using VS2005.

Please help! Thanks…


Hello Jules,
Thanks for taking time and looking through.
SetPixelFormat seems to succeed in my case. It is returning ‘true’.
But still no OGL component.
Also tried changing depth to 32 from 16. it didnt seem to work for me :frowning:

BTW when I call GetLastError() it returns 8 and not 0.
This happens in the beginning of the function “juce_createOpenGLContext” as well… Could this be the reason for the Component not comming up?


Strange. The code that chooses the format is basic opengl stuff, I can’t see what else you could do there to handle these bizarre drivers. Anyone know of any example workaround code from games, etc that handle it better?

Ok, just a thought - this hack to replace the SetPixelFormat section will try different colour depths if the first attempt fails. Worth a try on your system to see if it helps:

zerostruct (pfd);
pfd.nSize = sizeof (pfd);
pfd.nVersion = 1;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 32;
pfd.iLayerType = PFD_MAIN_PLANE;

int format = ChoosePixelFormat (oc->dc, &pfd);

if (format == 0 || ! SetPixelFormat (oc->dc, format, &pfd))
    // try some less ambitious formats if it fails..
    pfd.cColorBits = 24;
    format = ChoosePixelFormat (oc->dc, &pfd);

    if (format == 0 || ! SetPixelFormat (oc->dc, format, &pfd))
        pfd.cDepthBits = 16;
        format = ChoosePixelFormat (oc->dc, &pfd);

        if (format == 0 || ! SetPixelFormat (oc->dc, format, &pfd))
            pfd.cColorBits = 32;
            format = ChoosePixelFormat (oc->dc, &pfd);

            if (format == 0 || ! SetPixelFormat (oc->dc, format, &pfd))
                jassertfalse // can't find a suitable pixel format that works for opengl

Hi Jules,

I tried this code, still no luck. Is there any way I can upgrade my system with new drivers possibly? There was a comment about generic MS drivers being used. Perhaps I need to change them, but I’m not sure how to update those if I can (I went to the OpenGL site but there’s no obvious location for this).

I thought that installing VS2005 would have given me the most up to date OpenGL stuff (I’m linking to the libs in the 2005 directory, I belive). I still have 2003 on my system though. Could that be conflicting? Is it possible I am linking with it? I suppose I should remove 2003 from my system to see…


It’s nothing to do with your visual studio installation, I guess it’s just some graphics drivers being awkward.

I had a look on all the openGL tutorial sites, and the code they use is exactly the same as what I’ve used, so don’t think it’s a problem with the juce code.

If you step through the code snippet above, what actually happens? Do all the SetPixelFormat calls fail? Any numbers or clues?


I haven’t stepped through it yet (I woke up, dropped the code in to see if if would work then ran out the door to get to work :slight_smile: ). I will try tonight and see what I get.

There is a VST instrument called BrushStrokes from a gentleman named Niall Moody (http://www.niallmoody.com) which uses OpenGL. I have been able to compile and run it on my system. There is code there that creates a gl context similar to what you are doing; I will look at the code and see if I can integrate into juce. If it works I will let you know ASAP :slight_smile:

Thanks again,

NiallM is a member round here actually.

I just updated my NVidia drivers to the latest and all is well in the world now. Sorry to post on here before trying something as obvious as this…


Hi Jules,petey-g ,
Juce OpenGL Component works great when you got the latest drivers.
The problem is when you are NOT having the right drivers or when you force the PDF_GENERIC_FORMAT in pixelformatdescriptor.
We tried everything, and at-last wrote our own OpenGL Component and
integrated it into JUCE. This new component now works fine. All we did was create a window with “CreateWindow” API and set it as a child to the Main Application widow(which is a JUCE dialog window). Directed the OpenGL drawing to this component.

Also Jules any idea why GetLastError() returning a error at begining of
"juce_createOpenGLContext"? I guess this error is root of all the evil. :frowning:

Yogesh Kini

…but that’s exactly the same thing that my opengl stuff does - creates a window and embeds it, and draws to that window. There must be some subtle difference between your window’s settings and mine that’s throwing windows into a spin. Got any code you could post me so I can look for it?


Now that I have a gl window, I am having difficulties drawing other components over it. Is this also a known problem with openGL and juce? For example, I am creating a very simple component in jucer, then in the class OpenGLDemo (found at the end of OpenGLDemo.cpp) I add it:

class OpenGLDemo : public Component
DemoOpenGLCanvas* canvas;
NewJucerComponent *comp;

setName (T(“OpenGL”));

    canvas = new DemoOpenGLCanvas();
    addAndMakeVisible (canvas);

    comp = new NewJucerComponent();
    addAndMakeVisible (comp);

The new component is always drawing behind the GL component. I would like to draw it to the front; I want to be able to use other components to draw 2D information above the GL window (font’s, cursors etc.) Is this possible? If so, how can I do this?

Perhaps this problem is also related to the windows settings that are being used. Yogesh, it would be great to see the new code that makes the gl windows work without the update to the drivers if possible…


No, it’s not possible to put a juce component over an opengl component - the opengl lives inside its own custom window, and on windows XP even transparent windows don’t display correctly over opengl.