GL graphics not displaying....

git-svn-id: svn://anubis/misc/sierpinski-gtk@248 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh 2010-10-21 19:36:30 +00:00
parent 04460dd52d
commit 6ab808e73a

View File

@ -2,10 +2,14 @@
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
#include <iostream>
#include <gdkmm/cursor.h> #include <gdkmm/cursor.h>
#include "SierpinskiDA.h" #include "SierpinskiDA.h"
using namespace std;
SierpinskiDA::SierpinskiDA(const Glib::RefPtr<const Gdk::GL::Config> & config) SierpinskiDA::SierpinskiDA(const Glib::RefPtr<const Gdk::GL::Config> & config)
: Gtk::GL::DrawingArea(config) : Gtk::GL::DrawingArea(config)
{ {
@ -18,13 +22,23 @@ SierpinskiDA::SierpinskiDA(const Glib::RefPtr<const Gdk::GL::Config> & config)
void SierpinskiDA::regenerate(int npts) 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(); gl_begin();
glNewList(m_dl, GL_COMPILE); glNewList(m_dl, GL_COMPILE);
glBegin(GL_QUADS); glBegin(GL_LINE_LOOP);
glVertex3f(1, 0, 1);
glVertex3f(-1, 0, 1); for (int i = 0; i < 4; i++)
glVertex3f(-1, 0, -1); {
glVertex3f(1, 0, -1); glVertex3fv(pts[i]);
}
glEnd(); glEnd();
glEndList(); glEndList();
gl_end(); gl_end();
@ -51,6 +65,7 @@ bool SierpinskiDA::draw()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
gluPerspective(60, get_width()/get_height(), 0.01, 1000.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
gluLookAt(0, -2, 0, gluLookAt(0, -2, 0,
@ -58,6 +73,14 @@ bool SierpinskiDA::draw()
0, 0, 1); 0, 0, 1);
glCallList(m_dl); 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()) if (get_gl_window()->is_double_buffered())
get_gl_window()->swap_buffers(); get_gl_window()->swap_buffers();
@ -93,11 +116,16 @@ void SierpinskiDA::on_realize()
{ {
Gtk::GL::DrawingArea::on_realize(); Gtk::GL::DrawingArea::on_realize();
if (gl_begin()) if (!gl_begin())
return; return;
glViewport(0, 0, get_width(), get_height()); glViewport(0, 0, get_width(), get_height());
m_dl = glGenLists(1); 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(); gl_end();
@ -109,7 +137,7 @@ void SierpinskiDA::on_realize()
*/ */
bool SierpinskiDA::on_configure_event(GdkEventConfigure * event) bool SierpinskiDA::on_configure_event(GdkEventConfigure * event)
{ {
if (gl_begin()) if (!gl_begin())
return false; return false;
glViewport(0, 0, get_width(), get_height()); glViewport(0, 0, get_width(), get_height());