2D and 3D OpenGL at the same time


#1

I’ve been trying to draw 2D things and 3D things at the same time. The 2D things are child components of something attached to an OpenGLContext which is drawing 3D things in its `renderOpenGL’ method.

What happens though, is that Juce is also using OpenGL to render the 2D things. This is not a bad thing except that, due to OpenGL being state based, they sometimes step on each others’ toes.

The first problem, was that i needed to reset various OpenGL modes before the 2D drawing would work at all.

glDisable( GL_DEPTH_TEST ); glDisable( GL_CULL_FACE); glDisable( GL_DITHER);

This was simple enough, but then i ran into a problem that took me hours to track down to to with the use of texture units.

To cut a long story short, I eventually managed to get things to work by settings the active texture unit back to GL_TEXTURE0 after my own stuff.

In particular some of the 2D components worked fine, but those using, for example, GradientFill such as the Slider came out entirely black (although they functionally worked).

So my questions are;

should the above line be in Juce where it relies on this, is there any other state i need to put back or not mess with (although it does seem to work currently) and should i be somehow making Juce use its 2D code (rather than opengl) in the first place for its components.

Thanks for your pointers.

BTW, it did originally work on Windows, but failed on Android (iOS not tested yet). I hate these Android only problems!

– hugh.


#2

Hmm.

How about if you change this “0” to a “-1”, in juce_OpenGLGraphicsContext.cpp, line 734 ?

struct ActiveTextures { ActiveTextures (const OpenGLContext& c) noexcept : texturesEnabled (0), currentActiveTexture (-1), context (c) {}


#3

I’ve just updated to the tip which appears to have this change already. Yes it works! i can take out my hack now.

thanks,
– hugh.