Permalink
Browse files

remove GLUT, use gtk for text rendering

  • Loading branch information...
1 parent f55c674 commit be07b4b92a421ba7021a1c636990d4aa0e0a8d5c @hurzl hurzl committed Nov 7, 2012
Showing with 109 additions and 48 deletions.
  1. +12 −8 configure.ac
  2. +3 −3 doc/manual.asciidoc
  3. +3 −2 src/gcode/gcode.cpp
  4. +4 −3 src/model.cpp
  5. +4 −4 src/platform.h
  6. +45 −6 src/render.cpp
  7. +9 −0 src/render.h
  8. +4 −3 src/shape.cpp
  9. +11 −10 src/slicer/geometry.cpp
  10. +3 −3 src/slicer/geometry.h
  11. +7 −3 src/slicer/layer.cpp
  12. +4 −3 src/slicer/poly.cpp
View
@@ -96,33 +96,37 @@ AC_SUBST(DISTCHECK_LIBREPRAP_FLAGS)
case "$host_os" in
mingw*)
- GL_LIBS="-lopengl32 -lglu32 -lglut32"
+ GL_LIBS="-lopengl32"
+# -lglu32 -lglut32"
EXTRA_LDFLAGS="-Wl,-subsystem,windows -shared-libgcc"
EXTRA_CFLAGS="-fexceptions -mthreads"
- AC_CHECK_HEADER(GL/glut.h, , AC_MSG_ERROR([cannot find headers for freeglut]))
+# AC_CHECK_HEADER(GL/glut.h, , AC_MSG_ERROR([cannot find headers for freeglut]))
WIN32_BUILD=yes
;;
freebsd*)
- GL_LIBS="-L/usr/local/lib -lGLU -lGL -lglut"
+ GL_LIBS="-L/usr/local/lib"
+# -lGLU -lGL -lglut"
EXTRA_LDFLAGS="-L/usr/local/lib"
CFLAGS="$CFLAGS -I/usr/local/include"
CXXFLAGS="$CXXFLAGS -I/usr/local/include"
CPPFLAGS="$CPPFLAGS -I/usr/local/include"
- AC_CHECK_HEADER(GL/glut.h, , AC_MSG_ERROR([cannot find headers for freeglut]))
+# AC_CHECK_HEADER(GL/glut.h, , AC_MSG_ERROR([cannot find headers for freeglut]))
;;
Darwin*)
- GL_LIBS="-L/usr/local/lib -lGLU -lOpenGL -lGLUT -lglut"
+ GL_LIBS="-L/usr/local/lib"
+# -lGLU -lOpenGL -lGLUT -lglut"
EXTRA_LDFLAGS="-L/usr/local/lib -L/opt/homebrew/lib"
CFLAGS="$CFLAGS -I/usr/local/include -I/opt/homebrew/include"
CXXFLAGS="$CXXFLAGS -I/usr/local/include -I/opt/homebrew/include"
CPPFLAGS="$CPPFLAGS -I/usr/local/include -I/opt/homebrew/include"
- AC_CHECK_HEADER(GLUT/glut.h, , AC_MSG_ERROR([cannot find headers for freeglut]))
+# AC_CHECK_HEADER(GLUT/glut.h, , AC_MSG_ERROR([cannot find headers for freeglut]))
;;
*)
- GL_LIBS="-L/usr/lib -lGLU -lGL -lglut"
+ GL_LIBS="-L/usr/lib"
+# -lGLU -lGL -lglut"
EXTRA_LDFLAGS=
EXTRA_CFLAGS=
- AC_CHECK_HEADER(GL/glut.h, , AC_MSG_ERROR([cannot find headers for freeglut]))
+# AC_CHECK_HEADER(GL/glut.h, , AC_MSG_ERROR([cannot find headers for freeglut]))
;;
esac
View
@@ -101,7 +101,7 @@ or
===== Install dependencies =====
--------------------------
-sudo apt-get install git-core build-essential intltool libtool libgtkglext1-dev libgtkmm-2.4-dev gtk2-engines-pixbuf freeglut3-dev libxml++ libcairomm-1.0 libzip-dev
+sudo apt-get install git-core build-essential intltool libtool libgtkglextmm-x11-1.2 libgtkmm-2.4-dev gtk2-engines-pixbuf libxml++ libcairomm-1.0 libzip-dev
--------------------------
@@ -144,7 +144,7 @@ yum install git gtk2-devel gcc-c++ gcc binutils make cmake gtkglextmm gtkglextmm
--------------------------
For Fedora 15 (tested on x86_64)
--------------------------
-yum install git gtk2-devel gcc-c++ gcc binutils make cmake gtkglextmm gtkglextmm-devel freeglut-devel libusb1-devel intltool gtkmm*
+yum install git gtk2-devel gcc-c++ gcc binutils make cmake gtkglextmm gtkglextmm-devel libusb1-devel intltool gtkmm*
--------------------------
Install repsnapper:
@@ -210,7 +210,7 @@ Install http://www.macports.org/[MacPorts].
Run from a terminal window:
- sudo port install intltool gtkmm gtkglext
+ sudo port install intltool gtkmm gtkglextmm
Acquire source and compile:
View
@@ -30,6 +30,7 @@
#include "geometry.h"
#include "ctype.h"
#include "settings.h"
+#include "render.h"
GCode::GCode()
@@ -575,8 +576,8 @@ void GCode::drawCommands(const Settings &settings, uint start, uint end,
}
if (settings.Display.DebugGCodeExtruders) {
ostringstream o; o << commands[i].extruder_no+1;
- drawString( (pos + commands[i].where) / 2. + extruder_offset,
- o.str());
+ Render::draw_string( (pos + commands[i].where) / 2. + extruder_offset,
+ o.str());
}
}
if (settings.Display.LuminanceShowsSpeed)
View
@@ -35,6 +35,7 @@
#include "ui/progress.h"
#include "shape.h"
#include "flatshape.h"
+#include "render.h"
Model::Model() :
m_previewLayer(NULL),
@@ -936,15 +937,15 @@ int Model::draw (vector<Gtk::TreeModel::Path> &iter)
Vector3d pos;
val << fixed << (Max.x()-Min.x());
pos = Vector3d((Max.x()+Min.x())/2.,Min.y(),Max.z());
- drawString(pos,val.str());
+ Render::draw_string(pos,val.str());
val.str("");
val << fixed << (Max.y()-Min.y());
pos = Vector3d(Min.x(),(Max.y()+Min.y())/2.,Max.z());
- drawString(pos,val.str());
+ Render::draw_string(pos,val.str());
val.str("");
val << fixed << (Max.z()-Min.z());
pos = Vector3d(Min.x(),Min.y(),(Max.z()+Min.z())/2.);
- drawString(pos,val.str());
+ Render::draw_string(pos,val.str());
}
int drawnlayer = -1;
if(settings.Display.DisplayLayer) {
View
@@ -32,13 +32,13 @@
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
- #include <GLUT/glut.h>
+// #include <GLUT/glut.h>
#else
#include <GL/gl.h> // Header File For The OpenGL32 Library
#include <GL/glu.h> // Header File For The GLu32 Library
-#ifndef WIN32
- #include <GL/glut.h> // Header GLUT Library
-#endif
+//#ifndef WIN32
+// #include <GL/glut.h> // Header GLUT Library
+//#endif
#endif
class Platform {
View
@@ -28,6 +28,11 @@
#define N_LIGHTS (sizeof (m_lights) / sizeof(m_lights[0]))
+
+const Glib::ustring Render::fontstring = "helvetica 8";
+GLuint Render::fontlistbase = 0;
+int Render::fontheight = 0;
+
inline GtkWidget *Render::get_widget()
{
return GTK_WIDGET (gobj());
@@ -124,15 +129,49 @@ void Render::zoom_to_model()
// reset the pan to center
setArcballTrans(m_transform, Vector3d::ZERO);
// zoom to platform if model has zero size
- // if (m_zoom == 0) {
- // m_zoom = model->settings.Hardware.Volume.find_max();
- // setArcballTrans(m_transform,
- // model->settings.getPrintMargin() +
- // model->settings.getPrintVolume()/2.);
- // }
+ if (m_zoom == 0) {
+ m_zoom = model->settings.Hardware.Volume.find_max();
+ setArcballTrans(m_transform,
+ model->settings.getPrintMargin() );
+ //model->settings.getPrintVolume()/2.);
+ }
queue_draw();
}
+void Render::draw_string(const Vector3d &pos, const string s)
+{
+ if (fontheight == 0) return;
+ glRasterPos3dv(pos);
+ glListBase(fontlistbase);
+ glCallLists(s.length(), GL_UNSIGNED_BYTE, s.c_str());
+}
+
+void Render::on_realize()
+{
+ cerr << "realize" << endl;
+ Gtk::GL::DrawingArea::on_realize();
+
+ fontlistbase = glGenLists (128);
+
+ Pango::FontDescription font_desc(fontstring);
+
+ Glib::RefPtr<Pango::Font> font =
+ Gdk::GL::Font::use_pango_font(font_desc, 0, 128, fontlistbase);
+ if (!font)
+ {
+ std::cerr << "*** Can't load font "
+ << fontstring
+ << std::endl;
+ Gtk::Main::quit();
+ }
+ Pango::FontMetrics font_metrics = font->get_metrics();
+
+ fontheight = font_metrics.get_ascent() + font_metrics.get_descent();
+ fontheight = PANGO_PIXELS(fontheight);
+
+}
+
+
bool Render::on_configure_event(GdkEventConfigure* event)
{
Glib::RefPtr<Gdk::GL::Drawable> gldrawable = get_gl_drawable();
View
@@ -37,6 +37,11 @@ class Render : public Gtk::GL::DrawingArea
Model *get_model() const;
Glib::RefPtr<Gtk::TreeSelection> m_selection;
+ // font rendering:
+ static const Glib::ustring fontstring;
+ static GLuint fontlistbase;
+ static int fontheight;
+
float m_zoom;
gllight *m_lights[4];
@@ -55,6 +60,10 @@ class Render : public Gtk::GL::DrawingArea
void set_zoom (float zoom) {m_zoom=zoom;};
void zoom_to_model();
void set_transform(const Matrix4fT &transform) {m_transform=transform;};
+
+ static void draw_string(const Vector3d &pos, const string s);
+
+ virtual void on_realize();
virtual bool on_configure_event(GdkEventConfigure* event);
virtual bool on_expose_event(GdkEventExpose* event);
virtual bool on_motion_notify_event(GdkEventMotion* event);
View
@@ -23,6 +23,7 @@
#include "ui/progress.h"
#include "settings.h"
#include "clipping.h"
+#include "render.h"
#ifdef _OPENMP
#include <omp.h>
@@ -950,15 +951,15 @@ void Shape::drawBBox() const
Vector3d pos;
val << fixed << (Max.x()-Min.x());
pos = Vector3d((Max.x()+Min.x())/2.,Min.y(),Max.z());
- drawString(pos,val.str());
+ Render::draw_string(pos,val.str());
val.str("");
val << fixed << (Max.y()-Min.y());
pos = Vector3d(Min.x(),(Max.y()+Min.y())/2.,Max.z());
- drawString(pos,val.str());
+ Render::draw_string(pos,val.str());
val.str("");
val << fixed << (Max.z()-Min.z());
pos = Vector3d(Min.x(),Min.y(),(Max.z()+Min.z())/2.);
- drawString(pos,val.str());
+ Render::draw_string(pos,val.str());
}
View
@@ -28,15 +28,16 @@
#include <lmmin.h>
-#ifdef WIN32
-# include <GL/glut.h> // Header GLUT Library
-#endif
+// #ifdef WIN32
+// # include <GL/glut.h> // Header GLUT Library
+// #endif
#ifdef _MSC_VER
# pragma warning( disable : 4018 4267)
#endif
-/* call me before glutting */
+/*
+// call me before glutting
void checkGlutInit()
{
static bool inited = false;
@@ -45,21 +46,21 @@ void checkGlutInit()
inited = true;
int argc = 1;
char *argv[] = { (char *) "repsnapper" };
- glutInit (&argc, argv);
+ //glutInit (&argc, argv);
}
void drawString(const Vector3d &pos, const string &text)
{
- drawString(pos,GLUT_BITMAP_HELVETICA_12,text);
+ //drawString(pos,GLUT_BITMAP_HELVETICA_12,text);
}
void drawString(const Vector3d &pos, void* font, const string &text)
{
checkGlutInit();
- glRasterPos3d(pos.x(), pos.y(), pos.z());
- for (uint c=0;c<text.length();c++)
- glutBitmapCharacter(font, text[c]);
+ //glRasterPos3d(pos.x(), pos.y(), pos.z());
+ //for (uint c=0;c<text.length();c++)
+ //glutBitmapCharacter(font, text[c]);
}
-
+*/
//////////////////////////// ARC FITTING //////////////////////////
View
@@ -30,9 +30,9 @@
#endif
-void drawString(const Vector3d &pos, void* font, const string &text);
-void drawString(const Vector3d &pos, const string &text);
-void checkGlutInit();
+/* void drawString(const Vector3d &pos, void* font, const string &text); */
+/* void drawString(const Vector3d &pos, const string &text); */
+/* void checkGlutInit(); */
void move(const Vector3f &delta, Matrix4f &mat);
View
@@ -22,6 +22,7 @@
#include "poly.h"
#include "shape.h"
#include "infill.h"
+#include "render.h"
// polygons will be simplified to thickness/CLEANFACTOR
#define CLEANFACTOR 7
@@ -962,7 +963,7 @@ void Layer::Draw(const Settings &settings)
ostringstream oss;
oss << p;
Vector2d center = polygons[p].getCenter();
- drawString(Vector3d(center.x(), center.y(), Z), oss.str());
+ Render::draw_string(Vector3d(center.x(), center.y(), Z), oss.str());
}
draw_poly(hullPolygon, GL_LINE_LOOP, 3, 3, ORANGE, 0.5, randomized);
@@ -1179,13 +1180,16 @@ void Layer::DrawRulers(const Vector2d &point)
val.str("");
double v = xint[i].p.x()-xint[i-1].p.x();
val << fixed << v;
- drawString(Vector3d((xint[i].p.x()+xint[i-1].p.x())/2.,xint[i].p.y()+1,Z),val.str());
+ Render::draw_string(Vector3d((xint[i].p.x()+xint[i-1].p.x())/2.,
+ xint[i].p.y()+1,Z),
+ val.str());
}
for(guint i = 1; i<yint.size(); i++) {
val.str("");
double v = yint[i].p.y()-yint[i-1].p.y();
val << fixed << v;
- drawString(Vector3d(yint[i].p.x()+1,(yint[i].p.y()+yint[i-1].p.y())/2.,Z),val.str());
+ Render::draw_string(Vector3d(yint[i].p.x()+1,(yint[i].p.y()+yint[i-1].p.y())/2.,Z),
+ val.str());
}
}
View
@@ -23,6 +23,7 @@
#include "layer.h"
#include "shape.h"
#include "clipping.h"
+#include "render.h"
#include <poly2tri/poly2tri/poly2tri/poly2tri.h>
@@ -694,7 +695,7 @@ void Poly::drawVertexNumbers() const
glVertex3f(v.x(),v.y(),v.z());
ostringstream oss;
oss << i;
- drawString(v, oss.str());
+ Render::draw_string(v, oss.str());
}
}
@@ -707,7 +708,7 @@ void Poly::drawVertexAngles() const
double angle = angleAtVertex(i);
ostringstream oss;
oss << (int)(angle*180/M_PI);
- drawString(v, oss.str());
+ Render::draw_string(v, oss.str());
}
}
@@ -719,7 +720,7 @@ void Poly::drawLineNumbers() const
v2 = getVertexCircular3(i+1);
ostringstream oss;
oss << i;
- drawString((v+v2)/2., oss.str());
+ Render::draw_string((v+v2)/2., oss.str());
}
}

0 comments on commit be07b4b

Please sign in to comment.