OF inside a Qt window, issues with ofGLRenderer

Hi all,

I’m trying to get OF inside a Qt window. So far i got a lot of success :slight_smile: i can display of graphics in a QWidget and create Qt UIs to change parameters in of app.

So I created an ofAppQtWindow that pretty much mimics the ofAppGLFWWindow but substitutes GLFW calls for Qt calls.
Problem is when i try to setup the ofGLRenderer with :

	static_cast<ofGLRenderer*>(currentRenderer.get())->setup();

I get problems with the alpha blending that forces me to hack ofTypes like so:

		blendingMode		= OF_BLENDMODE_DISABLED;
		//blendingMode		= OF_BLENDMODE_ALPHA;

Any idea why is this? any better workaround?
Activating alphaBlending crashes for the same reason, and using antiAliasing seems to have no effect.

here is a screenshot:

3 Likes

it probably has to do with how you are initializing the frame buffer for the window, you might need to add alpha and multisampling bits to the buffer while setting it up. probably even depth too if that doesn’t happen by default

Thank you very much!
I will research a bit on how to do that.

So i managed to fix it by including the following lines (taken from ofAppGLFWWindow) just right before the setup call.

#ifndef TARGET_OPENGLES
static bool inited = false;
if (!inited) {
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
ofLogError(“ofAppRunner”) << "couldn’t init GLEW: " << glewGetErrorString(err);
return;
}
inited = true;
}
#endif

But I must be very confused because I-m not targeting embedded systems. Why is this macro taking effect? is it Qt that is opening a OpenGLES window?

the macro says ifndef, not ifdef so it only get’s executed if TARGET_OPENGLES is not defined

1 Like

@Jordi, QT widget integration sounds great, is this available somewhere? :grin:

1 Like

Thanks @arturo I didn’t read carefully… sorry for that.

@chuckleplant Yes i would love to share it! I will do a pull request soon. Its still in a very early stage, and there are so many things I don’t know how to handle yet, for example, when i resize the window, the openGL viewport has to be re-adjusted and i haven’t found the right place to do it. Also, Qt widgets need to be written in a separate class because of moc’ing… so the structure is a bit different from ofAppGLFWWindow, then the instructions in main.cpp also look different. Let me give it another shake and I will let you know.

I guess there are no license issues on sharing code that calls to Qt. Also It would be great if others could help me to polish this class :slight_smile:

BTW I have a question regarding ofEvents:
I saw that both GLUT and GLFW windows use this syntax to sent events to the current application:

instance->events().notifyMousePressed(instance->events().getMouseX(), instance->events().getMouseY(), event->button());

I’m wondering if the following is equivalent (and why)?

static ofMouseEventArgs mouseEventArgs;
mouseEventArgs.x = event->pos().x();
mouseEventArgs.y = event->pos().y();
mouseEventArgs.button = mousePressed;

ofNotifyEvent(ofEvents().mousePressed, mouseEventArgs);

The second would simplify things since it does not require a pointer to the current window. My guess is that the second sends the event to all ofApps, meaning that an event to one window would be sent to all windows open… but I’m not so sure about it…

1 Like

here it is! still a lot to do though…

I managed to fix the resize issue and laso i kept using ofEvents in the same way as in GLFW.

So far i use QOpenGlWidget. I also got it working with QMainWindow and QWidget but interface changes a bit.
Also I have to research a good way to insert Qt widgets inside the main window.

https://github.com/openframeworks/openFrameworks/pull/5602

as addon:

installation steps still to be done. only tested under Windows.

1 Like