Re: Getting OpenGL 4.5 working with GTKMM



So I found this example:

https://github.com/GNOME/gtkmm/blob/master/demos/gtk-demo/example_glarea.cc

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

So I found this:

https://github.com/anholt/libepoxy

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
setup:

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

When I run, it always says:

Error: Missing GL version

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

gl
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;

static
void on_button_clicked()
{
    if(pDialog)
        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);
    glClear(GL_COLOR_BUFFER_BIT);
    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();
    try
    {
        refBuilder->add_from_file("glarea.glade");
    }
    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);
    if(pDialog)
    {
        //Get the GtkBuilder-instantiated Button, and connect a signal
handler:
        Gtk::MenuItem* pButton = nullptr;
        refBuilder->get_widget("quitMenuItem", pButton);
        if(pButton)
        {
            pButton->signa
l_activate().connect( sigc::ptr_fun(on_button_clicked) );
        }

        Gtk::GLArea* glArea = nullptr;
        refBuilder->get_widget("glarea", glArea);
        if(glArea)
        {
            glArea->signal_render().connect(sigc::ptr_fun(glRender) );
        }
        app->run(*pDialog);
    }

    delete pDialog;

    return 0;
}

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list


Attachment: signature.asc
Description: OpenPGP digital signature



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