Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7519647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:56:18+00:00 2026-05-30T01:56:18+00:00

I am writing a C++ application using GTK and OpenGL. I have a GTK

  • 0

I am writing a C++ application using GTK and OpenGL. I have a GTK builder which reads an XML file and builds itself. I need to add an “OpenGL window area” into it. How do I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:56:19+00:00Added an answer on May 30, 2026 at 1:56 am

    The way I do it (gtkmm / C++ code) is like this:

    #include <gtkmm.h>
    #include <gtkglmm.h>
    
    class GLWidget : public Gtk::GL::DrawingArea {
        public:
        GLWidget(Glib::RefPtr<Gdk::GL::Config> glconfig)
            : Gtk::GL::DrawingArea(glconfig) {}
        ~GLWidget() {}
        virtual bool on_expose_event(GdkEventExpose* event);
    };
    
    bool GLWidget::on_expose_event(GdkEventExpose* event)
    {
        Glib::RefPtr<Gdk::GL::Drawable> d = get_gl_drawable();
        d->gl_begin(get_gl_context());
    
        // make this as complex as you need
        glClear(GL_COLOR_BUFFER_BIT);
    
        d->swap_buffers();
        d->gl_end();
        return true;
    }
    
    int main(int argc, char **argv)
    {
        Gtk::Main kit(argc, argv);
        Gtk::GL::init(argc, argv);
    
        Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file("ui.glade");
    
        Gtk::Window* mainWindow;
        Gtk::Alignment* container;
    
        builder->get_widget("mainWindow", mainWindow);
        builder->get_widget("Box", container);
    
        if (mainWindow == NULL || container == NULL) {
            g_critical("Gtk Builder failed to load mainWindow and/or container !\n");
            return -1;
        }
    
        Glib::RefPtr<Gdk::GL::Config> glconfig;
    
        glconfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGBA | Gdk::GL::MODE_DOUBLE);
        if (!glconfig)
            glconfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGB);
        if (!glconfig) {
            g_critical("Cannot create OpenGL-capable config\n");
            return -1;
        }
    
        GLWidget drawingArea(glconfig);
    
        drawingArea.set_size_request(640, 480);
        drawingArea.show();
        container->add(drawingArea);
    
        kit.run(*mainWindow);
    
        return 0;
    

    I.e. I’m simply loading a UI that contains an empty container widget, get the handle to that by name, then create the GL-enabled drawing area in code and add it to the empty container. Supposedly, it’s possible to “load-time” substitute an ordinary Gtk DrawingArea for a GtkGL one (see this posting) but that method didn’t work for me; the above, programmatically creating it, always did.

    You need gtkglext / gtkglextmm for the GL Drawingarea widget.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been writing an application using ASP.Net MVC4, where the majority of the
I'm writing an application using WPF, and I need to make something that looks
I have problem concerning python packages and testing. I'm writing an application using wx
I am writing an application program using swing. I need to exit from the
I'm writing an application using the public Tumblr API, just for fun. I have
I am writing an application using Symfony. I have some reusable components that I
I'm writing an application using Seam 2.2.x which will be deployed on JBoss 5.1.
So I am writing an application using ajax getting from a xml based api.
I am writing one web application using PHP/CodeIginter. Now, I want to add a
I am writing an application using <Phonon/VideoWidget> . I'd like to have two windows.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.