From 6ab808e73a472b6c5dad7ac1700dbafc3d3ed190 Mon Sep 17 00:00:00 2001 From: josh Date: Thu, 21 Oct 2010 19:36:30 +0000 Subject: [PATCH] GL graphics not displaying.... git-svn-id: svn://anubis/misc/sierpinski-gtk@248 bd8a9e45-a331-0410-811e-c64571078777 --- SierpinskiDA.cc | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/SierpinskiDA.cc b/SierpinskiDA.cc index 4745f8e..8afc38b 100644 --- a/SierpinskiDA.cc +++ b/SierpinskiDA.cc @@ -2,10 +2,14 @@ #include #include +#include + #include #include "SierpinskiDA.h" +using namespace std; + SierpinskiDA::SierpinskiDA(const Glib::RefPtr & config) : Gtk::GL::DrawingArea(config) { @@ -18,13 +22,23 @@ SierpinskiDA::SierpinskiDA(const Glib::RefPtr & config) void SierpinskiDA::regenerate(int npts) { +#define deg2rad(x) ((x)/180.0*M_PI) + const static float pts[][3] = { + {0, 0, sqrt(1 + sin(deg2rad(60))*sin(deg2rad(60))+1.5*1.5)}, + {0, 1, 0}, + {sin(deg2rad(60)), -cos(deg2rad(60)), 0}, + {-sin(deg2rad(60)), -cos(deg2rad(60)), 0} + }; + 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); + glBegin(GL_LINE_LOOP); + + for (int i = 0; i < 4; i++) + { + glVertex3fv(pts[i]); + } + glEnd(); glEndList(); gl_end(); @@ -51,6 +65,7 @@ bool SierpinskiDA::draw() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); + gluPerspective(60, get_width()/get_height(), 0.01, 1000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0, -2, 0, @@ -58,6 +73,14 @@ bool SierpinskiDA::draw() 0, 0, 1); glCallList(m_dl); + glBegin(GL_QUADS); + glColor3f(1, 1, 1); + glNormal3f(0, -1, 0); + glVertex3f(1, 0, 1); + glVertex3f(-1, 0, 1); + glVertex3f(-1, 0, -1); + glVertex3f(1, 0, -1); + glEnd(); if (get_gl_window()->is_double_buffered()) get_gl_window()->swap_buffers(); @@ -93,11 +116,16 @@ void SierpinskiDA::on_realize() { Gtk::GL::DrawingArea::on_realize(); - if (gl_begin()) + if (!gl_begin()) return; glViewport(0, 0, get_width(), get_height()); m_dl = glGenLists(1); +// glEnable(GL_LIGHTING); +// glEnable(GL_LIGHT0); +// float color[] = {1, 1, 1, 1}; +// glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color); + glColor3f(1, 1, 1); gl_end(); @@ -109,7 +137,7 @@ void SierpinskiDA::on_realize() */ bool SierpinskiDA::on_configure_event(GdkEventConfigure * event) { - if (gl_begin()) + if (!gl_begin()) return false; glViewport(0, 0, get_width(), get_height());