c++opengl-4gtkmm4

Continuously render Gtk::GLArea in gtkmm


I've followed a gtkmm4 + opengl example, the window loads and displays without any errors and renders one frame but then seems to ignore my queue_render() and queue_draw() calls as evidenced by the print statements in the console. I've set auto render to true as well.

#include <iostream>
#include <string>

#include <gtkmm.h>
#include <giomm/resource.h>
#define GLEW_STATIC
#include <gl/glew.h>

class TestWindow : public Gtk::Window {
protected:
    Gtk::GLArea mGlArea;

    void onRealize() {
        std::cout << "onRealize()" << std::endl;

        mGlArea.make_current();

        glewExperimental = true;
        if (glewInit() != GLEW_OK) {
            std::cout << "ERROR: Failed to initialize GLEW" << std::endl;
        }

        glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    }

    void onUnrealize() {

    }

    bool onRender(const Glib::RefPtr<Gdk::GLContext>& context) {
        std::cout << "onRender()" << std::endl;

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        mGlArea.queue_render();
        mGlArea.queue_draw();
        return true;
    }
public:
    TestWindow() {
        set_title("Window Title");
        set_child(mGlArea);
        mGlArea.set_auto_render(true);
        mGlArea.set_size_request(800, 600);

        mGlArea.set_required_version(4, 0);

        mGlArea.signal_realize().connect(sigc::mem_fun(*this, &TestWindow::onRealize));
        mGlArea.signal_unrealize().connect(sigc::mem_fun(*this, &TestWindow::onUnrealize), false);
        mGlArea.signal_render().connect(sigc::mem_fun(*this, &TestWindow::onRender), false);

        mGlArea.show();
    }
};

int main(int argc, char* argv[]) {
    auto app = Gtk::Application::create("test.gtkmm");

    return app->make_window_and_run<TestWindow>(argc, argv);
}

Solution

  • I'm currently working on an example. Gtk::GLArea doesn't have many options. For me its opening a 4.6 core profile context (with debug support). No idea yet how to configure this.

    Just cleaned up this example code. Working nicely now.

    Hello Triangle gtkmm4 OpenGL Gtk::GLArea example - GitLab link