Gtk::GLArea, queue_draw and other widgets

Working with a Gtk::GLArea together with other widgets sometimes it happens that when calling queue_draw for the area, the other widgets become black and are not repainted until i move the mouse across. It seems to happen only once mostly when the app starts. Any clue?

Absent-mindedly, i put a draw request inside “on_resize” and this caused the issue.

That was not the cause of the issue. It worked for a while and then it showed again. So, in on_resize i called the base class implementation Gtk::GLArea::on_resize(width, height); it worked for a while and then it showed again. :thinking:

Which system is it? It would be great if you could post here a minimal reproducible example

Debian. I tried, but i cannot reproduce it with a minimal example. There’s a Gtk::Grid with a combo box and my GLArea derived widget. When i click on the area and i call queue_draw it seems that the combo gets invalidated or painted over but not redrawn until the mouse crosses it. It just happens the first time i click and then no more.

Sometimes the application used to start with the combo already black, perhaps calling GLArea::on_resize fixed this.

It would help to know some additional informations on the system, e.g:

  • The graphics card
  • The graphics card driver in use (whether MESA or proprietary)
  • The Window Manager
  • The display protocol (i.e. X11 or Wayland)

In addition to that you could test the GTK3 OpenGL demo. Install the gtk-3-examples package using apt then open the gtk3-demo application from a terminal. It lists various examples teaching how to use GTK for many different tasks. There should be an OpenGL demo that you can launch. Does that have graphical problems too?

And, if you don’t mind me asking, could you post a screenshot showing the graphic issue?

Card: Intel Corporation HD Graphics 530 (rev 06)
Kernel driver in use: i915

I commented out the rendering code and the Combo becomes black anyway. I also notice that if i drag the window, the Combo becomes black. In the screenshot you would see only a window with a black background because i removed the rendering code and the Combo which is above the GLArea turns to black.

I tried this example

it works.

Mmh…does the issue go away if you switch to software GL?

I’d test in other environments (perhaps inside a VM) to rule out a bug in the WM or graphics driver.

Software GL doesn’t help. With it, the Combo always pops up black from the beginning. I used Software GL with a minimal example where i cannot reproduce the bug and it’s Software GL itself that makes the Combo appear black.

Since GLArea doesn’t create its own window and draws on the container how can a container mix cairo graphics with open gl?
In any case, perhaps the clipping region is not set correctly at start up.

Because if i use queue_draw_area and include the Combo, the issue disappears.

This code seems to reproduce the issue:

Click on the red glarea and the combo becomes black.
Remove queue_draw() from on_resize and the issue goes away.
Also, the focus rectangle in the combo is not always drawn.

I don’t think that calling queue_draw inside on_resize is forbidden and my code might “indirectly” call it. So is this an issue?

#include <gtkmm.h>
#include <GL/gl.h>

class Area : public Gtk::GLArea
	void on_resize(int width, int height) override

	bool on_button_press_event(GdkEventButton* button_event) override
		return true;

	bool on_render(const Glib::RefPtr<Gdk::GLContext>& context) override
		glClearColor(1, 0, 0, 1);
		return true;


class MainWindow : public Gtk::Window 
	Gtk::VBox box;	
	Gtk::ComboBoxText combo;	
	Area area;


		set_size_request(400, 400);


		box.pack_start(combo, false, false);



int main(int argc, char **argv) 
    Glib::RefPtr<Gtk::Application> app = 
		Gtk::Application::create(argc, argv, "");

    MainWindow mw;

    return app->run(mw);

It works on my machine :stuck_out_tongue:

Don’t know why it’s showing artifacts for you :confused: . I tested on Mutter and XFCE4 on an up-to-date Arch Linux distribution.

It used to work until some hour ago. At some point it started to misbehave. I have no clue. Also, i cannot reproduce the “black when dragging the window” issue with it. I guess i have to stop thinking about it for a while, inspiration might come when you least expect it.

I replaced on_resize with on_size_allocate. So far, so good.

1 Like