# HG changeset patch # User Dmitriy Morozov <dmitriy@mrzv.org> # Date 1248195451 25200 # Node ID bff3d7c294ff01c237f997bf51af92a2e8150210 # Parent 846354ed685345b7766db629ea53d377087dc32b Fixed lights and spheres according to Martin's instructions diff -r 846354ed6853 -r bff3d7c294ff CMakeLists.txt --- a/CMakeLists.txt Tue Jul 22 10:03:44 2008 -0400 +++ b/CMakeLists.txt Tue Jul 21 09:57:31 2009 -0700 @@ -3,15 +3,16 @@ # Set Qt4 and QGLViewer configuration find_package (Qt4 REQUIRED) -find_library (QGLViewer_LIBRARY - NAMES QGLViewer) +find_library (QGLViewer_LIBRARY NAMES QGLViewer) +find_library (glut_LIBRARY NAMES glut) + find_path (QGLViewer_INCLUDE_DIR QGLViewer/qglviewer.h) set (QT_USE_QTXML TRUE) set (QT_USE_QTOPENGL TRUE) include (${QT_USE_FILE}) -set (sources VEFViewer.cpp main.cpp sphere.cpp) +set (sources VEFViewer.cpp main.cpp) set (moc_hdrs VEFViewer.h) qt4_wrap_cpp (moc_srcs ${moc_hdrs}) set (uis viewerInterface.ui) @@ -22,7 +23,7 @@ PATHS ${Boost_LIBRARY_DIR}) add_executable (VEFViewer ${sources} ${moc_srcs} ${uis_h}) -target_link_libraries (VEFViewer ${QT_LIBRARIES} ${QGLViewer_LIBRARY} ${boost_program_options_LIBRARY}) +target_link_libraries (VEFViewer ${QT_LIBRARIES} ${QGLViewer_LIBRARY} ${boost_program_options_LIBRARY} ${glut_LIBRARY}) install (TARGETS VEFViewer RUNTIME DESTINATION bin) diff -r 846354ed6853 -r bff3d7c294ff VEFViewer.cpp --- a/VEFViewer.cpp Tue Jul 22 10:03:44 2008 -0400 +++ b/VEFViewer.cpp Tue Jul 21 09:57:31 2009 -0700 @@ -1,7 +1,8 @@ #include "VEFViewer.h" #include <QtDebug> #include <cstdio> -#include "sphere.h" +// #include "sphere.h" +#include <GL/glut.h> VEFViewer::VEFViewer(QWidget* parent): QGLViewer(parent) { @@ -29,10 +30,15 @@ //glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 3.0); // Basic settings - glShadeModel(GL_FLAT); + glShadeModel(GL_SMOOTH); + glEnable(GL_COLOR_MATERIAL); glEnable(GL_NORMALIZE); + glEnable(GL_LINE_SMOOTH); + glEnable(GL_POINT_SMOOTH); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glPointSize(2.0); + + glEnable(GL_CULL_FACE); } void VEFViewer::addFile(QString s) @@ -221,7 +227,11 @@ glColor3f(color_.redF(), color_.greenF(), color_.blueF()); if (!isSphere()) + { + glDisable(GL_LIGHTING); glCallList(display_list_); + glEnable(GL_LIGHTING); + } else glCallList(sphere_display_list_); @@ -234,7 +244,7 @@ {} QVerticesLWI::QVerticesLWI(QString fname, VEFViewer* v): - QDisplayListLWI(fname, QColor::fromRgbF(.5, .65, .65)), isSphere_(false), viewer_(v) + QDisplayListLWI(fname, QColor::fromRgbF(.66, 0, .5)), isSphere_(false), viewer_(v) { filename_ = fname; QFileInfo fi(filename_); @@ -275,9 +285,12 @@ glNewList(sphere_display_list_, GL_COMPILE); for (VertexContainer::const_iterator cur = vertices_.begin(); cur != vertices_.end(); ++cur) { - XYZ c; - c.x = cur->x; c.y = cur->y; c.z = cur->z; - CreateSphere(c, .01, 6); + // XYZ c; + // c.x = cur->x; c.y = cur->y; c.z = cur->z; + // CreateSphere(c, .25, 10); + glTranslatef(cur->x, cur->y, cur->z); + glutSolidSphere(.25, 10, 10); + glTranslatef(-cur->x, -cur->y, -cur->z); } glEnd(); glEndList(); diff -r 846354ed6853 -r bff3d7c294ff main.cpp --- a/main.cpp Tue Jul 22 10:03:44 2008 -0400 +++ b/main.cpp Tue Jul 21 09:57:31 2009 -0700 @@ -4,6 +4,7 @@ #include <boost/program_options.hpp> #include <vector> #include <string> +#include <GL/glut.h> class ViewerInterface: public QDialog, public Ui::Dialog { @@ -15,6 +16,8 @@ int main(int argc, char** argv) { + glutInit(&argc, argv); + // Parse program options std::vector<std::string> input_filenames; po::options_description hidden("Hidden options"); diff -r 846354ed6853 -r bff3d7c294ff sphere.cpp --- a/sphere.cpp Tue Jul 22 10:03:44 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -#include "sphere.h" -#include <cmath> - -void CreateSphere(XYZ c,double r,int n) -{ - int i,j; - double theta1,theta2,theta3; - XYZ e,p; - - if (r < 0) - r = -r; - if (n < 0) - n = -n; - if (n < 4 || r <= 0) { - glBegin(GL_POINTS); - glVertex3f(c.x,c.y,c.z); - glEnd(); - return; - } - - for (j=0;j<n/2;j++) { - theta1 = j * TWOPI / n - PID2; - theta2 = (j + 1) * TWOPI / n - PID2; - - glBegin(GL_QUAD_STRIP); - for (i=0;i<=n;i++) { - theta3 = i * TWOPI / n; - - e.x = cos(theta2) * cos(theta3); - e.y = sin(theta2); - e.z = cos(theta2) * sin(theta3); - p.x = c.x + r * e.x; - p.y = c.y + r * e.y; - p.z = c.z + r * e.z; - - glNormal3f(e.x,e.y,e.z); - glTexCoord2f(i/(double)n,2*(j+1)/(double)n); - glVertex3f(p.x,p.y,p.z); - - e.x = cos(theta1) * cos(theta3); - e.y = sin(theta1); - e.z = cos(theta1) * sin(theta3); - p.x = c.x + r * e.x; - p.y = c.y + r * e.y; - p.z = c.z + r * e.z; - - glNormal3f(e.x,e.y,e.z); - glTexCoord2f(i/(double)n,2*j/(double)n); - glVertex3f(p.x,p.y,p.z); - } - glEnd(); - } -} diff -r 846354ed6853 -r bff3d7c294ff sphere.h --- a/sphere.h Tue Jul 22 10:03:44 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -/* - Create a sphere centered at c, with radius r, and precision n - Draw a point for zero radius spheres - - Code by Paul Bourke <http://astronomy.swin.edu.au/~pbourke/opengl/sphere/> -*/ - -#include <GL/gl.h> - -const double TWOPI = 2*3.14; -const double PID2 = 3.14/2; - -struct XYZ -{ - XYZ(GLfloat xx = 0, GLfloat yy = 0, GLfloat zz = 0): - x(xx), y(yy), z(zz) - {} - - GLfloat x,y,z; -}; - -void CreateSphere(XYZ c,double r,int n);