Commit 8f8b9883 authored by Edward Vigmond's avatar Edward Vigmond
Browse files

Orienter now works on Mac. The issue was that the glu calls were being

ignored in the constructor on the Mac because, as far as I can tell, GL
wasn't ready. 
parent e311f5ab
......@@ -19,7 +19,7 @@ COMMON_LIBS = -lpng -lpthread -lm -lz $(LIB_HDF5)
LIBS = -L$(HDF5API_ROOT)/lib $(FLTK_LD_FLAGS) $(COMMON_LIBS)
LDFLAGS =
CXXFLAGS = -I$(HDF5API_ROOT)/src $(FLTK_INC) $(COMMON_INC)
CXXFLAGS = -I$(HDF5API_ROOT)/src $(FLTK_INC) $(COMMON_INC)
CPPFLAGS = $(CFLAGS) -g
ifdef ENABLE_LOGGING
......
......@@ -6,50 +6,24 @@ void draw_arrow( GLUquadricObj* quado, GLfloat stick, GLfloat head,
Orienter::Orienter(int x, int y, int w, int h, const char *l )
: Fl_Gl_Tb_Window(x, y, w, h, l),_cp(2),_dl(0)
{
gluobj = gluNewQuadric();
gluQuadricDrawStyle( gluobj, GLU_FILL );
gluQuadricOrientation(gluobj, GLU_INSIDE);
cp(_cp);
redraw();
}
void
Orienter:: draw()
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable( GL_DEPTH_TEST );
glEnable(GL_NORMALIZE);
glEnable( GL_POINT_SMOOTH );
glEnable( GL_LINE_SMOOTH );
glEnable( GL_BLEND );
glShadeModel(GL_SMOOTH);
glDepthFunc( GL_LEQUAL );
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glViewport(0,0,w(),h());
glOrtho( -1.05, 1.05, -1.1, 1.1, -10, 10 );
glClearColor( 1, 1, 1, 1 );
glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
// rotate clipping plane only if the orienter was moved, and
// not if the model was rotated
if( !trackball.transformed ){
GLdouble *x = static_cast<ClipPlane*>(parent()->user_data())->plane(_cp);
Quaternion cp_norm(0, x[0], x[1], x[2]);
cp_norm.Normalize();
Quaternion new_norm= trackball.qSpin*cp_norm*trackball.qSpin.GetConjugate();
((ClipPlane *)(parent()->user_data()))->update_dir( new_norm.x,
new_norm.y, new_norm.z, _cp );
}
trackball.Rotation(_view); // adjust for model rotation
trackball.DoTransform();
// mae a displaylist the first time through
if(!_dl) {
_dl = glGenLists(1);
/** set up the graphics since it is not guaranteed that a valid OpenGL
* context will be available in the constructor
*/
void
Orienter:: init_graphics()
{
gluobj = gluNewQuadric();
gluQuadricDrawStyle( gluobj, GLU_FILL );
gluQuadricOrientation(gluobj, GLU_INSIDE);
gluQuadricNormals( gluobj, GLU_SMOOTH );
_dl = glGenLists(1);
glNewList(_dl, GL_COMPILE);
glPushAttrib(GL_ALL_ATTRIB_BITS);
#ifdef DRAW_SQUARE_PLANE
//draw clipping plane
glColor4f( 0, 1, 0, 0.2 );
......@@ -60,9 +34,8 @@ Orienter:: draw()
glVertex3f( 1, -1, 0 );
glEnd();
#else // draw sphere
glNewList(_dl, GL_COMPILE);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColor3f( 0, 0, 0 );
glColor4f( 0, 0, 0, 1 );
glBegin(GL_POLYGON);
for( float i=0; i<360; i+=5 )
glVertex3f( 0, cos(i*M_PI/180.), sin(i/180*M_PI) );
......@@ -95,18 +68,64 @@ Orienter:: draw()
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient0);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse0);
glLightfv(GL_LIGHT1, GL_SPECULAR, specular0);
glColor3f( 1, 0, 0 );
glTranslatef( 0, 0, -1 );
glColor4f( 1, 0, 1, 1 );
draw_arrow( gluobj, 1.6, 0.4, 0.1, 0.2 );
glPopAttrib();
glEndList();
}
void
Orienter:: draw()
{
if( !valid() ) {
valid( 1 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glLineWidth( 1. );
glPointSize( 10.0 );
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
glEnable( GL_DEPTH_TEST );
glEnable(GL_NORMALIZE);
glEnable( GL_POINT_SMOOTH );
glEnable( GL_LINE_SMOOTH );
glEnable( GL_BLEND );
glShadeModel(GL_SMOOTH);
glEnable( GL_MULTISAMPLE );
glDepthFunc( GL_LEQUAL );
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glViewport(0,0,w(),h());
glOrtho( -1.05, 1.05, -1.1, 1.1, -10, 10 );
glClearColor( 1, 1, 1, 1 );
}
glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
glPushMatrix();
// rotate clipping plane only if the orienter was moved, and
// not if the model was rotated
if( !trackball.transformed ){
GLdouble *x = static_cast<ClipPlane*>(parent()->user_data())->plane(_cp);
Quaternion cp_norm(0, x[0], x[1], x[2]);
cp_norm.Normalize();
Quaternion new_norm= trackball.qSpin*cp_norm*trackball.qSpin.GetConjugate();
((ClipPlane *)(parent()->user_data()))->update_dir( new_norm.x,
new_norm.y, new_norm.z, _cp );
}
trackball.Rotation(_view); // adjust for model rotation
trackball.DoTransform();
if(!_dl) {
init_graphics();
}
glCallList(_dl);
glPopMatrix();
trackball.Rotation(_view.GetConjugate()); // remove model rotation
glPopAttrib();
}
......
......@@ -18,7 +18,8 @@ class Orienter : public Fl_Gl_Tb_Window
GLUquadricObj* gluobj;
int _cp; //current clipping plane
Quaternion _view;
GLuint _dl;
GLuint _dl;
void init_graphics();
public:
Orienter(int x, int y, int w, int h, const char *l = 0);
virtual ~Orienter(){}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment