Last active
December 6, 2019 21:44
-
-
Save gfokkema/a0c73de5c9df476b5b31057ebb63394f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <epoxy/gl.h> | |
#include <gtkmm/window.h> | |
#include <gtkmm/box.h> | |
#include <gtkmm/glarea.h> | |
#include <iostream> | |
class Example : public Gtk::Window | |
{ | |
public: | |
Example(); | |
~Example() override; | |
bool do_render(const Glib::RefPtr<Gdk::GLContext>&); | |
void do_realize(); | |
void do_unrealize(); | |
private: | |
Gtk::GLArea* m_glarea; | |
GLuint m_vao; | |
}; | |
Example::Example() | |
: m_glarea() | |
{ | |
set_default_size(600, 400); | |
set_border_width(10); | |
m_glarea = Gtk::make_managed<Gtk::GLArea>(); | |
m_glarea->set_required_version(4, 1); | |
m_glarea->signal_realize().connect(sigc::mem_fun(*this, &Example::do_realize)); | |
m_glarea->signal_unrealize().connect(sigc::mem_fun(*this, &Example::do_unrealize), false); | |
m_glarea->signal_render().connect(sigc::mem_fun(*this, &Example::do_render), false); | |
add(*m_glarea); | |
show_all(); | |
} | |
Example::~Example() | |
{ | |
printf("Destructor context: %p\n", reinterpret_cast<void*>(m_glarea->get_context().get())); | |
// m_glarea.make_current(); | |
} | |
bool | |
Example::do_render(const Glib::RefPtr<Gdk::GLContext>&) | |
{ | |
m_glarea->make_current(); | |
try { | |
m_glarea->throw_if_error(); | |
glClearColor(0.5, 0.5, 0.5, 1.0); | |
glClear(GL_COLOR_BUFFER_BIT); | |
glClearColor(0.5, 0.5, 0.5, 1.0); | |
glFlush(); | |
return true; | |
} catch (const Gdk::GLError& gle) { | |
std::cerr << "An error occurred in the render callback of the GLArea" << std::endl; | |
std::cerr << gle.domain() << "-" << gle.code() << "-" << gle.what() << std::endl; | |
return false; | |
} | |
} | |
void | |
Example::do_realize() | |
{ | |
printf("Realize context: %p\n", reinterpret_cast<void*>(m_glarea->get_context().get())); | |
m_glarea->make_current(); | |
try { | |
m_glarea->throw_if_error(); | |
glGenVertexArrays(1, &m_vao); | |
glBindVertexArray(m_vao); | |
} catch(const Gdk::GLError& gle) { | |
std::cerr << "An error occured making the context current during realize:" << std::endl; | |
std::cerr << gle.domain() << "-" << gle.code() << "-" << gle.what() << std::endl; | |
} | |
} | |
void | |
Example::do_unrealize() | |
{ | |
printf("Unrealize context: %p\n", reinterpret_cast<void*>(m_glarea->get_context().get())); | |
m_glarea->make_current(); | |
try { | |
m_glarea->throw_if_error(); | |
glDeleteBuffers(1, &m_vao); | |
} catch (const Gdk::GLError& gle) { | |
std::cerr << "An error occured making the context current during unrealize" << std::endl; | |
std::cerr << gle.domain() << "-" << gle.code() << "-" << gle.what() << std::endl; | |
} | |
} | |
int main(int argc, char *argv[]) | |
{ | |
auto app = Gtk::Application::create("org.gtkmm.Example"); | |
auto example = std::make_unique<Example>(); | |
return app->run(*example, argc, argv); | |
} |
Hi I saw your post on the mailing list. I found that the Error message goes away for me when you assign the window on the heap. ( Not the first time with gtkmm widgets when assigning on the stack I got issues, for example Gtk::Switch can even segfault I found, but as long as assign them dynamically it works.
So instead of
Example example;
Do
Example *example = new Example(); or use a smart pointer, but you get my drift.
....
delete example
then when I run it I no longer get the error message.
Cheers :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile with:
g++ $(pkg-config --cflags --libs gtkmm-3.0 epoxy) example.cpp