Re: Segmentation fault with GtkGlExtmm



Hello everybody out there!

	Eventually I have solved it. Indeed, it was a stupid mistake: a
misplaced brace in constructor of GlDrawingArea which leads not to give
OpenGL capability to the widget. At the end of the message, a version of
“src/window.cpp” which works well. I have also improved code quality.

	Regards.

							Yoann

#include <glibmm/error.h>
#include <cstdlib>

#include "window.hpp"

/* -- GlDrawingArea default constructor. --------------------------- */
Interface::GlDrawingArea::GlDrawingArea (): Gtk::DrawingArea () {
  /* OpenGL configuration. */
  Glib::RefPtr<Gdk::GL::Config> configuration;

  /* Try setting in double buffering mode. */
  configuration = Gdk::GL::Config::create(Gdk::GL::MODE_RGBA   |
                                          Gdk::GL::MODE_DEPTH  |
                                          Gdk::GL::MODE_DOUBLE);
  if (!configuration) {
    g_warning("Impossible to set OpenGL in double buffer mode, try
single buffer.\n");
    /* Try setting in single buffer mode. */
    configuration = Gdk::GL::Config::create(Gdk::GL::MODE_RGBA  |
                                            Gdk::GL::MODE_DEPTH);
    if (!configuration) {
      g_critical("Impossible to configure OpenGL.\n");
      std::exit(-2);
    }
  }

  /* Give OpenGL capability to the widget. */
  set_gl_capability(configuration);
}

/* -- GlDrawingArea destructor. --------------------------------------- */
Interface::GlDrawingArea::~GlDrawingArea () {
}

/* -- When exposing GlDrawingArea. ------------------------- */
bool Interface::GlDrawingArea::on_expose_event (GdkEventExpose* event) {
  /* OpenGL window. */
  Glib::RefPtr<Gdk::GL::Window> glWindow = get_gl_window();

  if (glWindow) {
    if (!create_gl_context()) {
      g_critical("Impossible to get OpenGL context.\n");
      std::exit(-3);
    }
    glWindow->gl_begin(get_gl_context());

    glClear(GL_COLOR_BUFFER_BIT);

    /* Main OpenGL rendering. */

    glWindow->gl_end();
    glWindow->swap_buffers();
  }
  else {
    g_critical("Impossible to create an OpenGL context.\n");
  }

  return true;
}

/* -- Window default constructor. ------------------------------ */
Interface::Window::Window (): Gtk::Window (), glArea () {
  set_title("Tutorial 1");
  set_default_size(200, 200);
  set_border_width(2);

  add(glArea);

  show_all_children();
}

/* -- Window destructor. ------------------------------------------ */

Interface::Fenetre::~Fenetre () {
}



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