more infrastructure

git-svn-id: svn://anubis/misc/sierpinski-gtk@247 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh 2010-10-21 17:22:24 +00:00
parent 2b5692498c
commit 04460dd52d
2 changed files with 44 additions and 14 deletions

View File

@ -16,13 +16,38 @@ SierpinskiDA::SierpinskiDA(const Glib::RefPtr<const Gdk::GL::Config> & config)
| Gdk::SCROLL_MASK);
}
bool SierpinskiDA::draw()
void SierpinskiDA::regenerate(int npts)
{
gl_begin();
glNewList(m_dl, GL_COMPILE);
glBegin(GL_QUADS);
glVertex3f(1, 0, 1);
glVertex3f(-1, 0, 1);
glVertex3f(-1, 0, -1);
glVertex3f(1, 0, -1);
glEnd();
glEndList();
gl_end();
}
bool SierpinskiDA::gl_begin()
{
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
if (!glwindow->gl_begin(get_gl_context()))
return glwindow->gl_begin(get_gl_context());
}
void SierpinskiDA::gl_end()
{
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
glwindow->gl_end();
}
bool SierpinskiDA::draw()
{
if (!gl_begin())
return false;
glClearColor(0.1, 0.6, 1.0, 1.0);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@ -32,11 +57,14 @@ bool SierpinskiDA::draw()
0, 0, 0,
0, 0, 1);
if (glwindow->is_double_buffered())
glwindow->swap_buffers();
glCallList(m_dl);
if (get_gl_window()->is_double_buffered())
get_gl_window()->swap_buffers();
else
glFlush();
gl_end();
return true;
}
@ -65,15 +93,15 @@ void SierpinskiDA::on_realize()
{
Gtk::GL::DrawingArea::on_realize();
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
glwindow->get_window()->set_cursor(Gdk::Cursor(Gdk::CROSSHAIR));
if (!glwindow->gl_begin(get_gl_context()))
if (gl_begin())
return;
glViewport(0, 0, get_width(), get_height());
m_dl = glGenLists(1);
glwindow->gl_end();
gl_end();
regenerate(10);
}
/*
@ -81,14 +109,12 @@ void SierpinskiDA::on_realize()
*/
bool SierpinskiDA::on_configure_event(GdkEventConfigure * event)
{
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
if (!glwindow->gl_begin(get_gl_context()))
if (gl_begin())
return false;
glViewport(0, 0, get_width(), get_height());
glwindow->gl_end();
gl_end();
return true;
}

View File

@ -8,14 +8,18 @@ class SierpinskiDA : public Gtk::GL::DrawingArea
{
public:
SierpinskiDA(const Glib::RefPtr<const Gdk::GL::Config> & config);
void regenerate(int npts);
protected:
int m_x, m_y;
int m_dl;
virtual bool draw();
virtual void on_realize();
virtual bool on_configure_event(GdkEventConfigure * event);
virtual bool on_expose_event(GdkEventExpose * event);
bool gl_begin();
void gl_end();
/* signal handlers */
virtual bool on_motion_notify_event(GdkEventMotion * event);