Re: Getting OpenGL 4.5 working with GTKMM

So I found this example:

And it has #include <epoxy/gl.h> , and I thought, "what is that?"

So I found this:

And, gee, it just works!

I'm not sure if this is enough, becase epoxy_gl_version() returns 0,
but the glArea->get_required_version() returns 4.5. I'll pretend it
doesn't matter for now and bug someone (else?) later if I'm again at my
wit's end. 

On Sun, 2021-04-11 at 01:52 +0000, JLM via gtkmm-list wrote:
I am trying to make use of OpenGL 4.5 in a gtkGlArea. The code below
works. However, I have the OpenGL Programming Guide Ninth Edition, and
it uses this instead of glClearColor:

    static const float black[] = { 0.0, 0.0, 0.0, 0.0 };
    glClearBufferfv(GL_COLOR, 0, black);

When I try to use that, the compile doesn't find it:

gtkgl.cpp:32:5: error: 'glClearBufferfv' was not declared in this
scope; did you mean 'glReadBuffer'?
   32 |     glClearBufferfv(GL_COLOR, 0, black);

I also tried #include <GL/glext.h> but that didn't help.

So then I thought maybe I need to make use of GLEW. When I #include
<GL/glew.h>, that compiles at least. But, then I can't run GLEW's

    GLenum glewError = glewInit();
    if(glewError != GLEW_OK)
        std::cerr << "Error: " << glewGetErrorString(glewError) <<

When I run, it always says:

Error: Missing GL version

So then I found the gtkGlArea method, set_required_version, and set it:

Area->set_required_version(4, 5);

But that still didn't help. So then I thought maybe the GLEW init needs
to be in the on_realize() section, as I saw that this is where you put
OpenGL init stuff, but that still didn't work.

So, what do I need to #include? Should I make use of GLEW, or does
GTK(MM) do everything necessary to get OpenGL already? Are there any
tutorials or examples? Most everything I find is for OpenGL 3.3, but I
don't know how to align that with the book I've got.

Thanks for any help you can provide.

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

Gtk::Window* pDialog = nullptr;

void on_button_clicked()
        pDialog->hide(); //hide() will cause main::run() to end.

bool glRender(const Glib::RefPtr<Gdk::GLContext>&)
    glClearColor(1.0f, 0.3f, 0.3f, 1.0f);
    return true;

int main (int argc, char **argv)
    auto app = Gtk::App
lication::create(argc, argv, "org.test");

    //Load the GtkBuilder file and instantiate its widgets:
    auto refBuilder = Gtk::Builder::create();
    catch(const Glib::FileError& ex)
        std::cerr << "FileError: " << ex.what() << std::endl;
        return 1;
    catch(const Glib::MarkupError& ex)
        std::cerr << "MarkupError: " << ex.what() << std::endl;
        return 1;
    catch(const Gtk::BuilderError& ex)
        std::cerr << "BuilderError: " << ex.what() << std::endl;
        return 1;

    //Get the GtkBuilder-instantiated Dialog:
    refBuilder->get_widget("Window", pDialog);
        //Get the GtkBuilder-instantiated Button, and connect a signal
        Gtk::MenuItem* pButton = nullptr;
        refBuilder->get_widget("quitMenuItem", pButton);
l_activate().connect( sigc::ptr_fun(on_button_clicked) );

        Gtk::GLArea* glArea = nullptr;
        refBuilder->get_widget("glarea", glArea);
            glArea->signal_render().connect(sigc::ptr_fun(glRender) );

    delete pDialog;

    return 0;

gtkmm-list mailing list
gtkmm-list gnome org

Attachment: signature.asc
Description: OpenPGP digital signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]