summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--openscad.pro3
-rw-r--r--src/OpenCSGRenderer.cc35
-rw-r--r--src/Preferences.cc76
-rw-r--r--src/Preferences.h16
-rw-r--r--src/ThrownTogetherRenderer.cc57
-rw-r--r--src/glview.cc34
-rw-r--r--src/polyset.cc57
-rw-r--r--src/polyset.h12
-rw-r--r--src/renderer.cc66
-rw-r--r--src/renderer.h17
-rw-r--r--src/rendersettings.cc35
-rw-r--r--src/rendersettings.h35
-rw-r--r--tests/CMakeLists.txt6
-rw-r--r--tests/regression/opencsgtest/color-tests-expected.pngbin11055 -> 10950 bytes
-rw-r--r--tests/regression/throwntogethertest/color-tests-expected.pngbin9139 -> 10215 bytes
15 files changed, 280 insertions, 169 deletions
diff --git a/openscad.pro b/openscad.pro
index 31c1e15..80dd7d9 100644
--- a/openscad.pro
+++ b/openscad.pro
@@ -163,6 +163,7 @@ FORMS += src/MainWindow.ui \
src/OpenCSGWarningDialog.ui
HEADERS += src/renderer.h \
+ src/rendersettings.h \
src/ThrownTogetherRenderer.h \
src/CGAL_renderer.h \
src/OGL_helper.h \
@@ -217,6 +218,8 @@ HEADERS += src/renderer.h \
SOURCES += src/openscad.cc \
src/mainwin.cc \
src/handle_dep.cc \
+ src/renderer.cc \
+ src/rendersettings.cc \
src/ThrownTogetherRenderer.cc \
src/glview.cc \
src/export.cc \
diff --git a/src/OpenCSGRenderer.cc b/src/OpenCSGRenderer.cc
index a1aafc5..233124b 100644
--- a/src/OpenCSGRenderer.cc
+++ b/src/OpenCSGRenderer.cc
@@ -40,11 +40,11 @@ public:
OpenCSG::Primitive(operation, convexity) { }
shared_ptr<PolySet> ps;
Transform3d m;
- int csgmode;
+ PolySet::csgmode_e csgmode;
virtual void render() {
glPushMatrix();
glMultMatrixd(m.data());
- ps->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode), m);
+ ps->render_surface(csgmode, m);
glPopMatrix();
}
};
@@ -89,24 +89,23 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo,
double *c = chain->colors[j];
glPushMatrix();
glMultMatrixd(m.data());
- int csgmode = chain->types[j] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL;
+ PolySet::csgmode_e csgmode = chain->types[j] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL;
if (highlight) {
- chain->polysets[j]->render_surface(PolySet::COLORMODE_HIGHLIGHT, PolySet::csgmode_e(csgmode + 20), m, shaderinfo);
- } else if (background) {
- chain->polysets[j]->render_surface(PolySet::COLORMODE_BACKGROUND, PolySet::csgmode_e(csgmode + 10), m, shaderinfo);
- } else if (c[0] >= 0 || c[1] >= 0 || c[2] >= 0) {
- // User-defined color from source
- glColor4dv(c);
- if (shaderinfo) {
- glUniform4f(shaderinfo[1], c[0], c[1], c[2], c[3]);
- glUniform4f(shaderinfo[2], (c[0]+1)/2, (c[1]+1)/2, (c[2]+1)/2, 1.0);
- }
- chain->polysets[j]->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode), m, shaderinfo);
+ setColor(COLORMODE_HIGHLIGHT, shaderinfo);
+ csgmode = PolySet::csgmode_e(csgmode + 20);
+ }
+ else if (background) {
+ setColor(COLORMODE_BACKGROUND, shaderinfo);
+ csgmode = PolySet::csgmode_e(csgmode + 10);
+ } else if (c[0] >= 0 || c[1] >= 0 || c[2] >= 0 || c[3] >= 0) {
+ // User-defined color or alpha from source
+ setColor(c, shaderinfo);
} else if (chain->types[j] == CSGTerm::TYPE_DIFFERENCE) {
- chain->polysets[j]->render_surface(PolySet::COLORMODE_CUTOUT, PolySet::csgmode_e(csgmode), m, shaderinfo);
+ setColor(COLORMODE_CUTOUT, shaderinfo);
} else {
- chain->polysets[j]->render_surface(PolySet::COLORMODE_MATERIAL, PolySet::csgmode_e(csgmode), m, shaderinfo);
+ setColor(COLORMODE_MATERIAL, shaderinfo);
}
+ chain->polysets[j]->render_surface(csgmode, m, shaderinfo);
glPopMatrix();
}
if (shaderinfo) glUseProgram(0);
@@ -124,8 +123,8 @@ void OpenCSGRenderer::renderCSGChain(CSGChain *chain, GLint *shaderinfo,
prim->ps = chain->polysets[i];
prim->m = chain->matrices[i];
prim->csgmode = chain->types[i] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL;
- if (highlight) prim->csgmode += 20;
- else if (background) prim->csgmode += 10;
+ if (highlight) prim->csgmode = PolySet::csgmode_e(prim->csgmode + 20);
+ else if (background) prim->csgmode = PolySet::csgmode_e(prim->csgmode + 10);
primitives.push_back(prim);
}
std::for_each(primitives.begin(), primitives.end(), del_fun<OpenCSG::Primitive>());
diff --git a/src/Preferences.cc b/src/Preferences.cc
index 577ed4a..aefbd12 100644
--- a/src/Preferences.cc
+++ b/src/Preferences.cc
@@ -54,38 +54,38 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
this->actionTriggered(this->prefsAction3DView);
// 3D View pane
- this->colorschemes["Cornfield"][BACKGROUND_COLOR] = QColor(0xff, 0xff, 0xe5);
- this->colorschemes["Cornfield"][OPENCSG_FACE_FRONT_COLOR] = QColor(0xf9, 0xd7, 0x2c);
- this->colorschemes["Cornfield"][OPENCSG_FACE_BACK_COLOR] = QColor(0x9d, 0xcb, 0x51);
- this->colorschemes["Cornfield"][CGAL_FACE_FRONT_COLOR] = QColor(0xf9, 0xd7, 0x2c);
- this->colorschemes["Cornfield"][CGAL_FACE_BACK_COLOR] = QColor(0x9d, 0xcb, 0x51);
- this->colorschemes["Cornfield"][CGAL_FACE_2D_COLOR] = QColor(0x00, 0xbf, 0x99);
- this->colorschemes["Cornfield"][CGAL_EDGE_FRONT_COLOR] = QColor(0xff, 0x00, 0x00);
- this->colorschemes["Cornfield"][CGAL_EDGE_BACK_COLOR] = QColor(0xff, 0x00, 0x00);
- this->colorschemes["Cornfield"][CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00);
- this->colorschemes["Cornfield"][CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00);
-
- this->colorschemes["Metallic"][BACKGROUND_COLOR] = QColor(0xaa, 0xaa, 0xff);
- this->colorschemes["Metallic"][OPENCSG_FACE_FRONT_COLOR] = QColor(0xdd, 0xdd, 0xff);
- this->colorschemes["Metallic"][OPENCSG_FACE_BACK_COLOR] = QColor(0xdd, 0x22, 0xdd);
- this->colorschemes["Metallic"][CGAL_FACE_FRONT_COLOR] = QColor(0xdd, 0xdd, 0xff);
- this->colorschemes["Metallic"][CGAL_FACE_BACK_COLOR] = QColor(0xdd, 0x22, 0xdd);
- this->colorschemes["Metallic"][CGAL_FACE_2D_COLOR] = QColor(0x00, 0xbf, 0x99);
- this->colorschemes["Metallic"][CGAL_EDGE_FRONT_COLOR] = QColor(0xff, 0x00, 0x00);
- this->colorschemes["Metallic"][CGAL_EDGE_BACK_COLOR] = QColor(0xff, 0x00, 0x00);
- this->colorschemes["Metallic"][CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00);
- this->colorschemes["Metallic"][CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00);
-
- this->colorschemes["Sunset"][BACKGROUND_COLOR] = QColor(0xaa, 0x44, 0x44);
- this->colorschemes["Sunset"][OPENCSG_FACE_FRONT_COLOR] = QColor(0xff, 0xaa, 0xaa);
- this->colorschemes["Sunset"][OPENCSG_FACE_BACK_COLOR] = QColor(0x88, 0x22, 0x33);
- this->colorschemes["Sunset"][CGAL_FACE_FRONT_COLOR] = QColor(0xff, 0xaa, 0xaa);
- this->colorschemes["Sunset"][CGAL_FACE_BACK_COLOR] = QColor(0x88, 0x22, 0x33);
- this->colorschemes["Sunset"][CGAL_FACE_2D_COLOR] = QColor(0x00, 0xbf, 0x99);
- this->colorschemes["Sunset"][CGAL_EDGE_FRONT_COLOR] = QColor(0xff, 0x00, 0x00);
- this->colorschemes["Sunset"][CGAL_EDGE_BACK_COLOR] = QColor(0xff, 0x00, 0x00);
- this->colorschemes["Sunset"][CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00);
- this->colorschemes["Sunset"][CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00);
+ this->colorschemes["Cornfield"][RenderSettings::BACKGROUND_COLOR] = QColor(0xff, 0xff, 0xe5);
+ this->colorschemes["Cornfield"][RenderSettings::OPENCSG_FACE_FRONT_COLOR] = QColor(0xf9, 0xd7, 0x2c);
+ this->colorschemes["Cornfield"][RenderSettings::OPENCSG_FACE_BACK_COLOR] = QColor(0x9d, 0xcb, 0x51);
+ this->colorschemes["Cornfield"][RenderSettings::CGAL_FACE_FRONT_COLOR] = QColor(0xf9, 0xd7, 0x2c);
+ this->colorschemes["Cornfield"][RenderSettings::CGAL_FACE_BACK_COLOR] = QColor(0x9d, 0xcb, 0x51);
+ this->colorschemes["Cornfield"][RenderSettings::CGAL_FACE_2D_COLOR] = QColor(0x00, 0xbf, 0x99);
+ this->colorschemes["Cornfield"][RenderSettings::CGAL_EDGE_FRONT_COLOR] = QColor(0xff, 0x00, 0x00);
+ this->colorschemes["Cornfield"][RenderSettings::CGAL_EDGE_BACK_COLOR] = QColor(0xff, 0x00, 0x00);
+ this->colorschemes["Cornfield"][RenderSettings::CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00);
+ this->colorschemes["Cornfield"][RenderSettings::CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00);
+
+ this->colorschemes["Metallic"][RenderSettings::BACKGROUND_COLOR] = QColor(0xaa, 0xaa, 0xff);
+ this->colorschemes["Metallic"][RenderSettings::OPENCSG_FACE_FRONT_COLOR] = QColor(0xdd, 0xdd, 0xff);
+ this->colorschemes["Metallic"][RenderSettings::OPENCSG_FACE_BACK_COLOR] = QColor(0xdd, 0x22, 0xdd);
+ this->colorschemes["Metallic"][RenderSettings::CGAL_FACE_FRONT_COLOR] = QColor(0xdd, 0xdd, 0xff);
+ this->colorschemes["Metallic"][RenderSettings::CGAL_FACE_BACK_COLOR] = QColor(0xdd, 0x22, 0xdd);
+ this->colorschemes["Metallic"][RenderSettings::CGAL_FACE_2D_COLOR] = QColor(0x00, 0xbf, 0x99);
+ this->colorschemes["Metallic"][RenderSettings::CGAL_EDGE_FRONT_COLOR] = QColor(0xff, 0x00, 0x00);
+ this->colorschemes["Metallic"][RenderSettings::CGAL_EDGE_BACK_COLOR] = QColor(0xff, 0x00, 0x00);
+ this->colorschemes["Metallic"][RenderSettings::CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00);
+ this->colorschemes["Metallic"][RenderSettings::CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00);
+
+ this->colorschemes["Sunset"][RenderSettings::BACKGROUND_COLOR] = QColor(0xaa, 0x44, 0x44);
+ this->colorschemes["Sunset"][RenderSettings::OPENCSG_FACE_FRONT_COLOR] = QColor(0xff, 0xaa, 0xaa);
+ this->colorschemes["Sunset"][RenderSettings::OPENCSG_FACE_BACK_COLOR] = QColor(0x88, 0x22, 0x33);
+ this->colorschemes["Sunset"][RenderSettings::CGAL_FACE_FRONT_COLOR] = QColor(0xff, 0xaa, 0xaa);
+ this->colorschemes["Sunset"][RenderSettings::CGAL_FACE_BACK_COLOR] = QColor(0x88, 0x22, 0x33);
+ this->colorschemes["Sunset"][RenderSettings::CGAL_FACE_2D_COLOR] = QColor(0x00, 0xbf, 0x99);
+ this->colorschemes["Sunset"][RenderSettings::CGAL_EDGE_FRONT_COLOR] = QColor(0xff, 0x00, 0x00);
+ this->colorschemes["Sunset"][RenderSettings::CGAL_EDGE_BACK_COLOR] = QColor(0xff, 0x00, 0x00);
+ this->colorschemes["Sunset"][RenderSettings::CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00);
+ this->colorschemes["Sunset"][RenderSettings::CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00);
// Editor pane
QFontDatabase db;
@@ -102,6 +102,8 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
connect(this->openCSGWarningBox, SIGNAL(toggled(bool)),
this, SLOT(openCSGWarningChanged(bool)));
updateGUI();
+
+ RenderSettings::inst()->setColors(this->colorschemes[getValue("3dview/colorscheme").toString()]);
}
Preferences::~Preferences()
@@ -125,15 +127,13 @@ Preferences::actionTriggered(QAction *action)
void Preferences::colorSchemeChanged()
{
+ QString scheme = this->colorSchemeChooser->currentItem()->text();
QSettings settings;
- settings.setValue("3dview/colorscheme", this->colorSchemeChooser->currentItem()->text());
+ settings.setValue("3dview/colorscheme", scheme);
- emit requestRedraw();
-}
+ RenderSettings::inst()->setColors(this->colorschemes[scheme]);
-const QColor &Preferences::color(RenderColor idx)
-{
- return this->colorschemes[getValue("3dview/colorscheme").toString()][idx];
+ emit requestRedraw();
}
void Preferences::fontFamilyChanged(const QString &family)
diff --git a/src/Preferences.h b/src/Preferences.h
index add1a11..7e22e63 100644
--- a/src/Preferences.h
+++ b/src/Preferences.h
@@ -4,6 +4,7 @@
#include <QMainWindow>
#include <QSettings>
#include "ui_Preferences.h"
+#include "rendersettings.h"
class Preferences : public QMainWindow, public Ui::Preferences
{
@@ -13,19 +14,6 @@ public:
~Preferences();
static Preferences *inst() { if (!instance) instance = new Preferences(); return instance; }
- enum RenderColor {
- BACKGROUND_COLOR,
- OPENCSG_FACE_FRONT_COLOR,
- OPENCSG_FACE_BACK_COLOR,
- CGAL_FACE_FRONT_COLOR,
- CGAL_FACE_2D_COLOR,
- CGAL_FACE_BACK_COLOR,
- CGAL_EDGE_FRONT_COLOR,
- CGAL_EDGE_BACK_COLOR,
- CGAL_EDGE_2D_COLOR,
- CROSSHAIR_COLOR
- };
- const QColor &color(RenderColor idx);
QVariant getValue(const QString &key) const;
void apply() const;
@@ -48,7 +36,7 @@ private:
void removeDefaultSettings();
QSettings::SettingsMap defaultmap;
- QHash<QString, QMap<RenderColor, QColor> > colorschemes;
+ QHash<QString, QMap<RenderSettings::RenderColor, QColor> > colorschemes;
static Preferences *instance;
};
diff --git a/src/ThrownTogetherRenderer.cc b/src/ThrownTogetherRenderer.cc
index 3ab13ea..36f7b95 100644
--- a/src/ThrownTogetherRenderer.cc
+++ b/src/ThrownTogetherRenderer.cc
@@ -70,51 +70,48 @@ void ThrownTogetherRenderer::renderCSGChain(CSGChain *chain, bool highlight,
double *c = chain->colors[i];
glPushMatrix();
glMultMatrixd(m.data());
- int csgmode = chain->types[i] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL;
+ PolySet::csgmode_e csgmode = chain->types[i] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL;
if (highlight) {
- chain->polysets[i]->render_surface(PolySet::COLORMODE_HIGHLIGHT, PolySet::csgmode_e(csgmode + 20), m);
+ csgmode = PolySet::csgmode_e(csgmode + 20);
+ setColor(COLORMODE_HIGHLIGHT);
+ chain->polysets[i]->render_surface(csgmode, m);
if (showedges) {
- glDisable(GL_LIGHTING);
- chain->polysets[i]->render_edges(PolySet::COLORMODE_HIGHLIGHT, PolySet::csgmode_e(csgmode + 20));
- glEnable(GL_LIGHTING);
+ setColor(COLORMODE_HIGHLIGHT_EDGES);
+ chain->polysets[i]->render_edges(csgmode);
}
} else if (background) {
- chain->polysets[i]->render_surface(PolySet::COLORMODE_BACKGROUND, PolySet::csgmode_e(csgmode + 10), m);
+ csgmode = PolySet::csgmode_e(csgmode + 10);
+ setColor(COLORMODE_BACKGROUND);
+ chain->polysets[i]->render_surface(csgmode, m);
if (showedges) {
- glDisable(GL_LIGHTING);
- chain->polysets[i]->render_edges(PolySet::COLORMODE_BACKGROUND, PolySet::csgmode_e(csgmode + 10));
- glEnable(GL_LIGHTING);
+ setColor(COLORMODE_BACKGROUND_EDGES);
+ chain->polysets[i]->render_edges(csgmode);
}
} else if (fberror) {
- if (highlight) {
- chain->polysets[i]->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode + 20), m);
- } else if (background) {
- chain->polysets[i]->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode + 10), m);
- } else {
- chain->polysets[i]->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode), m);
- }
- } else if (c[0] >= 0 || c[1] >= 0 || c[2] >= 0) {
- glColor4dv(c);
- chain->polysets[i]->render_surface(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode), m);
+ if (highlight) csgmode = PolySet::csgmode_e(csgmode + 20);
+ else if (background) csgmode = PolySet::csgmode_e(csgmode + 10);
+ else csgmode = PolySet::csgmode_e(csgmode);
+ chain->polysets[i]->render_surface(csgmode, m);
+ } else if (c[0] >= 0 || c[1] >= 0 || c[2] >= 0 || c[3] >= 0) {
+ setColor(c);
+ chain->polysets[i]->render_surface(csgmode, m);
if (showedges) {
- glDisable(GL_LIGHTING);
glColor4d((c[0]+1)/2, (c[1]+1)/2, (c[2]+1)/2, 1.0);
- chain->polysets[i]->render_edges(PolySet::COLORMODE_NONE, PolySet::csgmode_e(csgmode));
- glEnable(GL_LIGHTING);
+ chain->polysets[i]->render_edges(csgmode);
}
} else if (chain->types[i] == CSGTerm::TYPE_DIFFERENCE) {
- chain->polysets[i]->render_surface(PolySet::COLORMODE_CUTOUT, PolySet::csgmode_e(csgmode), m);
+ setColor(COLORMODE_CUTOUT);
+ chain->polysets[i]->render_surface(csgmode, m);
if (showedges) {
- glDisable(GL_LIGHTING);
- chain->polysets[i]->render_edges(PolySet::COLORMODE_CUTOUT, PolySet::csgmode_e(csgmode));
- glEnable(GL_LIGHTING);
+ setColor(COLORMODE_CUTOUT_EDGES);
+ chain->polysets[i]->render_edges(csgmode);
}
} else {
- chain->polysets[i]->render_surface(PolySet::COLORMODE_MATERIAL, PolySet::csgmode_e(csgmode), m);
+ setColor(COLORMODE_MATERIAL);
+ chain->polysets[i]->render_surface(csgmode, m);
if (showedges) {
- glDisable(GL_LIGHTING);
- chain->polysets[i]->render_edges(PolySet::COLORMODE_MATERIAL, PolySet::csgmode_e(csgmode));
- glEnable(GL_LIGHTING);
+ setColor(COLORMODE_MATERIAL_EDGES);
+ chain->polysets[i]->render_edges(csgmode);
}
}
glPopMatrix();
diff --git a/src/glview.cc b/src/glview.cc
index d0b3517..6836e3b 100644
--- a/src/glview.cc
+++ b/src/glview.cc
@@ -27,6 +27,7 @@
#include "GLView.h"
#include "Preferences.h"
#include "renderer.h"
+#include "rendersettings.h"
#include <QApplication>
#include <QWheelEvent>
@@ -190,6 +191,28 @@ void GLView::initializeGL()
}
}
if (opencsg_support && this->has_shaders) {
+ /*
+ Uniforms:
+ 1 color1 - face color
+ 2 color2 - edge color
+ 7 xscale
+ 8 yscale
+
+ Attributes:
+ 3 trig
+ 4 pos_b
+ 5 pos_c
+ 6 mask
+
+ Other:
+ 9 width
+ 10 height
+
+ Outputs:
+ tp
+ tr
+ shading
+ */
const char *vs_source =
"uniform float xscale, yscale;\n"
"attribute vec3 pos_b, pos_c;\n"
@@ -215,6 +238,11 @@ void GLView::initializeGL()
" shading = abs(dot(normal, lightDir));\n"
"}\n";
+ /*
+ Inputs:
+ tp && tr - if any components of tp < tr, use color2 (edge color)
+ shading - multiplied by color1. color2 is is without lighting
+ */
const char *fs_source =
"uniform vec4 color1, color2;\n"
"varying vec3 tp, tr, tmp;\n"
@@ -351,7 +379,7 @@ void GLView::paintGL()
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
- const QColor &bgcol = Preferences::inst()->color(Preferences::BACKGROUND_COLOR);
+ const QColor &bgcol = RenderSettings::inst()->color(RenderSettings::BACKGROUND_COLOR);
glClearColor(bgcol.redF(), bgcol.greenF(), bgcol.blueF(), 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
@@ -369,7 +397,7 @@ void GLView::paintGL()
if (showcrosshairs)
{
glLineWidth(3);
- const QColor &col = Preferences::inst()->color(Preferences::CROSSHAIR_COLOR);
+ const QColor &col = RenderSettings::inst()->color(RenderSettings::CROSSHAIR_COLOR);
glColor3f(col.redF(), col.greenF(), col.blueF());
glBegin(GL_LINES);
for (double xf = -1; xf <= +1; xf += 2)
@@ -470,7 +498,7 @@ void GLView::paintGL()
// FIXME: This was an attempt to keep contrast with background, but is suboptimal
// (e.g. nearly invisible against a gray background).
int r,g,b;
- bgcol.getRgb(&r, &g, &b);
+// bgcol.getRgb(&r, &g, &b);
glColor3d((255.0-r)/255.0, (255.0-g)/255.0, (255.0-b)/255.0);
glBegin(GL_LINES);
// X Label
diff --git a/src/polyset.cc b/src/polyset.cc
index 742e425..481cbec 100644
--- a/src/polyset.cc
+++ b/src/polyset.cc
@@ -108,52 +108,9 @@ static void gl_draw_triangle(GLint *shaderinfo, const Vector3d &p0, const Vector
}
}
-void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, const Transform3d &m, GLint *shaderinfo) const
+void PolySet::render_surface(csgmode_e csgmode, const Transform3d &m, GLint *shaderinfo) const
{
bool mirrored = m.matrix().determinant() < 0;
-
- if (colormode == COLORMODE_MATERIAL) {
-// FIXME: Reenable/rewrite - don't be dependant on GUI
-// const QColor &col = Preferences::inst()->color(Preferences::OPENCSG_FACE_FRONT_COLOR);
- const QColor &col = QColor(0xf9, 0xd7, 0x2c);
- glColor3f(col.redF(), col.greenF(), col.blueF());
-#ifdef ENABLE_OPENCSG
- if (shaderinfo) {
- glUniform4f(shaderinfo[1], col.redF(), col.greenF(), col.blueF(), 1.0f);
- glUniform4f(shaderinfo[2], 255 / 255.0f, 236 / 255.0f, 94 / 255.0f, 1.0f);
- }
-#endif /* ENABLE_OPENCSG */
- }
- if (colormode == COLORMODE_CUTOUT) {
-// FIXME: Reenable/rewrite - don't be dependant on GUI
-// const QColor &col = Preferences::inst()->color(Preferences::OPENCSG_FACE_BACK_COLOR);
- const QColor &col = QColor(0x9d, 0xcb, 0x51);
- glColor3f(col.redF(), col.greenF(), col.blueF());
-#ifdef ENABLE_OPENCSG
- if (shaderinfo) {
- glUniform4f(shaderinfo[1], 157 / 255.0f, 203 / 255.0f, 81 / 255.0f, 1.0f);
- glUniform4f(shaderinfo[2], 171 / 255.0f, 216 / 255.0f, 86 / 255.0f, 1.0f);
- }
-#endif /* ENABLE_OPENCSG */
- }
- if (colormode == COLORMODE_HIGHLIGHT) {
- glColor4ub(255, 157, 81, 128);
-#ifdef ENABLE_OPENCSG
- if (shaderinfo) {
- glUniform4f(shaderinfo[1], 255 / 255.0f, 157 / 255.0f, 81 / 255.0f, 0.5f);
- glUniform4f(shaderinfo[2], 255 / 255.0f, 171 / 255.0f, 86 / 255.0f, 0.5f);
- }
-#endif /* ENABLE_OPENCSG */
- }
- if (colormode == COLORMODE_BACKGROUND) {
- glColor4ub(180, 180, 180, 128);
-#ifdef ENABLE_OPENCSG
- if (shaderinfo) {
- glUniform4f(shaderinfo[1], 180 / 255.0f, 180 / 255.0f, 180 / 255.0f, 0.5f);
- glUniform4f(shaderinfo[2], 150 / 255.0f, 150 / 255.0f, 150 / 255.0f, 0.5f);
- }
-#endif /* ENABLE_OPENCSG */
- }
#ifdef ENABLE_OPENCSG
if (shaderinfo) {
glUniform1f(shaderinfo[7], shaderinfo[9]);
@@ -248,16 +205,9 @@ void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, const Tra
}
}
-void PolySet::render_edges(colormode_e colormode, csgmode_e csgmode) const
+void PolySet::render_edges(csgmode_e csgmode) const
{
- if (colormode == COLORMODE_MATERIAL)
- glColor3ub(255, 236, 94);
- if (colormode == COLORMODE_CUTOUT)
- glColor3ub(171, 216, 86);
- if (colormode == COLORMODE_HIGHLIGHT)
- glColor4ub(255, 171, 86, 128);
- if (colormode == COLORMODE_BACKGROUND)
- glColor4ub(150, 150, 150, 128);
+ glDisable(GL_LIGHTING);
if (this->is2d) {
double zbase = csgmode;
for (double z = -zbase/2; z < zbase; z += zbase)
@@ -293,6 +243,7 @@ void PolySet::render_edges(colormode_e colormode, csgmode_e csgmode) const
glEnd();
}
}
+ glEnable(GL_LIGHTING);
}
BoundingBox PolySet::getBoundingBox() const
diff --git a/src/polyset.h b/src/polyset.h
index 57f5057..5698621 100644
--- a/src/polyset.h
+++ b/src/polyset.h
@@ -27,14 +27,6 @@ public:
BoundingBox getBoundingBox() const;
- enum colormode_e {
- COLORMODE_NONE,
- COLORMODE_MATERIAL,
- COLORMODE_CUTOUT,
- COLORMODE_HIGHLIGHT,
- COLORMODE_BACKGROUND
- };
-
enum csgmode_e {
CSGMODE_NONE,
CSGMODE_NORMAL = 1,
@@ -45,8 +37,8 @@ public:
CSGMODE_HIGHLIGHT_DIFFERENCE = 22
};
- void render_surface(colormode_e colormode, csgmode_e csgmode, const Transform3d &m, GLint *shaderinfo = NULL) const;
- void render_edges(colormode_e colormode, csgmode_e csgmode) const;
+ void render_surface(csgmode_e csgmode, const Transform3d &m, GLint *shaderinfo = NULL) const;
+ void render_edges(csgmode_e csgmode) const;
};
#endif
diff --git a/src/renderer.cc b/src/renderer.cc
new file mode 100644
index 0000000..b791673
--- /dev/null
+++ b/src/renderer.cc
@@ -0,0 +1,66 @@
+#include "renderer.h"
+#include "rendersettings.h"
+#include <QColor>
+
+void Renderer::setColor(const double color[4], GLint *shaderinfo) const
+{
+ QColor col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_FRONT_COLOR);
+ double c[4] = {color[0], color[1], color[2], color[3]};
+ if (c[0] < 0) c[0] = col.redF();
+ if (c[1] < 0) c[1] = col.greenF();
+ if (c[2] < 0) c[2] = col.blueF();
+ if (c[3] < 0) c[3] = col.alphaF();
+ glColor4dv(c);
+ if (shaderinfo) {
+ glUniform4f(shaderinfo[1], c[0], c[1], c[2], c[3]);
+ glUniform4f(shaderinfo[2], (c[0]+1)/2, (c[1]+1)/2, (c[2]+1)/2, 1.0);
+ }
+}
+
+void Renderer::setColor(ColorMode colormode, GLint *shaderinfo) const
+{
+ QColor col;
+ switch (colormode) {
+ case COLORMODE_NONE:
+ return;
+ break;
+ case COLORMODE_MATERIAL:
+ col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_FRONT_COLOR);
+ break;
+ case COLORMODE_CUTOUT:
+ col = RenderSettings::inst()->color(RenderSettings::OPENCSG_FACE_BACK_COLOR);
+ break;
+ case COLORMODE_HIGHLIGHT:
+ col.setRgb(255, 157, 81, 128);
+ break;
+ case COLORMODE_BACKGROUND:
+ col.setRgb(180, 180, 180, 128);
+ break;
+ case COLORMODE_MATERIAL_EDGES:
+ col.setRgb(255, 236, 94);
+ break;
+ case COLORMODE_CUTOUT_EDGES:
+ col.setRgb(171, 216, 86);
+ break;
+ case COLORMODE_HIGHLIGHT_EDGES:
+ col.setRgb(255, 171, 86, 128);
+ break;
+ case COLORMODE_BACKGROUND_EDGES:
+ col.setRgb(150, 150, 150, 128);
+ break;
+ default:
+ break;
+ }
+ float rgba[4];
+ rgba[0] = col.redF();
+ rgba[1] = col.greenF();
+ rgba[2] = col.blueF();
+ rgba[3] = col.alphaF();
+ glColor4fv(rgba);
+#ifdef ENABLE_OPENCSG
+ if (shaderinfo) {
+ glUniform4f(shaderinfo[1], col.redF(), col.greenF(), col.blueF(), 1.0f);
+ glUniform4f(shaderinfo[2], (col.redF()+1)/2, (col.greenF()+1)/2, (col.blueF()+1)/2, 1.0f);
+ }
+#endif
+}
diff --git a/src/renderer.h b/src/renderer.h
index 3c25e98..e978080 100644
--- a/src/renderer.h
+++ b/src/renderer.h
@@ -1,11 +1,28 @@
#ifndef RENDERER_H_
#define RENDERER_H_
+#include "system-gl.h"
+
class Renderer
{
public:
virtual ~Renderer() {}
virtual void draw(bool showfaces, bool showedges) const = 0;
+
+ enum ColorMode {
+ COLORMODE_NONE,
+ COLORMODE_MATERIAL,
+ COLORMODE_CUTOUT,
+ COLORMODE_HIGHLIGHT,
+ COLORMODE_BACKGROUND,
+ COLORMODE_MATERIAL_EDGES,
+ COLORMODE_CUTOUT_EDGES,
+ COLORMODE_HIGHLIGHT_EDGES,
+ COLORMODE_BACKGROUND_EDGES
+ };
+
+ virtual void setColor(const double color[4], GLint *shaderinfo = NULL) const;
+ virtual void setColor(ColorMode colormode, GLint *shaderinfo = NULL) const;
};
#endif // RENDERER_H
diff --git a/src/rendersettings.cc b/src/rendersettings.cc
new file mode 100644
index 0000000..ee57c34
--- /dev/null
+++ b/src/rendersettings.cc
@@ -0,0 +1,35 @@
+#include "rendersettings.h"
+
+RenderSettings *RenderSettings::inst(bool erase)
+{
+ static RenderSettings *instance = new RenderSettings;
+ if (erase) {
+ delete instance;
+ instance = NULL;
+ }
+ return instance;
+}
+
+RenderSettings::RenderSettings()
+{
+ this->colors[BACKGROUND_COLOR] = QColor(0xff, 0xff, 0xe5);
+ this->colors[OPENCSG_FACE_FRONT_COLOR] = QColor(0xf9, 0xd7, 0x2c);
+ this->colors[OPENCSG_FACE_BACK_COLOR] = QColor(0x9d, 0xcb, 0x51);
+ this->colors[CGAL_FACE_FRONT_COLOR] = QColor(0xf9, 0xd7, 0x2c);
+ this->colors[CGAL_FACE_BACK_COLOR] = QColor(0x9d, 0xcb, 0x51);
+ this->colors[CGAL_FACE_2D_COLOR] = QColor(0x00, 0xbf, 0x99);
+ this->colors[CGAL_EDGE_FRONT_COLOR] = QColor(0xff, 0x00, 0x00);
+ this->colors[CGAL_EDGE_BACK_COLOR] = QColor(0xff, 0x00, 0x00);
+ this->colors[CGAL_EDGE_2D_COLOR] = QColor(0xff, 0x00, 0x00);
+ this->colors[CROSSHAIR_COLOR] = QColor(0x80, 0x00, 0x00);
+}
+
+QColor RenderSettings::color(RenderColor idx) const
+{
+ return this->colors[idx];
+}
+
+void RenderSettings::setColors(const QMap<RenderColor, QColor> &colors)
+{
+ this->colors = colors;
+}
diff --git a/src/rendersettings.h b/src/rendersettings.h
new file mode 100644
index 0000000..32e56f1
--- /dev/null
+++ b/src/rendersettings.h
@@ -0,0 +1,35 @@
+#ifndef RENDERSETTINGS_H_
+#define RENDERSETTINGS_H_
+
+#include <QColor>
+#include <QMap>
+
+class RenderSettings
+{
+public:
+ static RenderSettings *inst(bool erase = false);
+
+ enum RenderColor {
+ BACKGROUND_COLOR,
+ OPENCSG_FACE_FRONT_COLOR,
+ OPENCSG_FACE_BACK_COLOR,
+ CGAL_FACE_FRONT_COLOR,
+ CGAL_FACE_2D_COLOR,
+ CGAL_FACE_BACK_COLOR,
+ CGAL_EDGE_FRONT_COLOR,
+ CGAL_EDGE_BACK_COLOR,
+ CGAL_EDGE_2D_COLOR,
+ CROSSHAIR_COLOR
+ };
+
+ void setColors(const QMap<RenderColor, QColor> &colors);
+ QColor color(RenderColor idx) const;
+
+private:
+ RenderSettings();
+ ~RenderSettings() {}
+
+ QMap<RenderColor, QColor> colors;
+};
+
+#endif
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 585c3b1..61e0ef0 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -351,7 +351,7 @@ target_link_libraries(cgaltest tests-cgal ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRA
#
# cgalpngtest
#
-add_executable(cgalpngtest cgalpngtest.cc bboxhelp.cc ../src/CGALRenderer.cc)
+add_executable(cgalpngtest cgalpngtest.cc bboxhelp.cc ../src/CGALRenderer.cc ../src/renderer.cc ../src/rendersettings.cc)
set_target_properties(cgalpngtest PROPERTIES COMPILE_FLAGS "-DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}")
target_link_libraries(cgalpngtest tests-offscreen tests-cgal ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_LIBRARIES} ${GLEW_LIBRARY} ${COCOA_LIBRARY} ${OPENGL_LIBRARY} ${Boost_LIBRARIES})
@@ -359,7 +359,7 @@ target_link_libraries(cgalpngtest tests-offscreen tests-cgal ${CGAL_LIBRARY} ${C
# opencsgtest
#
-add_executable(opencsgtest opencsgtest.cc csgtestcore.cc ../src/OpenCSGRenderer.cc ../src/ThrownTogetherRenderer.cc)
+add_executable(opencsgtest opencsgtest.cc csgtestcore.cc ../src/OpenCSGRenderer.cc ../src/ThrownTogetherRenderer.cc ../src/renderer.cc ../src/rendersettings.cc)
set_target_properties(opencsgtest PROPERTIES COMPILE_FLAGS "-DENABLE_OPENCSG -DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}")
target_link_libraries(opencsgtest tests-offscreen tests-cgal ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_LIBRARIES} ${OPENCSG_LIBRARY} ${GLEW_LIBRARY} ${COCOA_LIBRARY} ${OPENGL_LIBRARY} ${Boost_LIBRARIES})
@@ -367,7 +367,7 @@ target_link_libraries(opencsgtest tests-offscreen tests-cgal ${CGAL_LIBRARY} ${C
# throwntogethertest
#
-add_executable(throwntogethertest throwntogethertest.cc csgtestcore.cc ../src/OpenCSGRenderer.cc ../src/ThrownTogetherRenderer.cc)
+add_executable(throwntogethertest throwntogethertest.cc csgtestcore.cc ../src/OpenCSGRenderer.cc ../src/ThrownTogetherRenderer.cc ../src/renderer.cc ../src/rendersettings.cc)
set_target_properties(throwntogethertest PROPERTIES COMPILE_FLAGS "-DENABLE_OPENCSG -DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}")
target_link_libraries(throwntogethertest tests-offscreen tests-cgal ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_LIBRARIES} ${OPENCSG_LIBRARY} ${GLEW_LIBRARY} ${COCOA_LIBRARY} ${OPENGL_LIBRARY} ${Boost_LIBRARIES})
diff --git a/tests/regression/opencsgtest/color-tests-expected.png b/tests/regression/opencsgtest/color-tests-expected.png
index b2ef8dd..82ba36a 100644
--- a/tests/regression/opencsgtest/color-tests-expected.png
+++ b/tests/regression/opencsgtest/color-tests-expected.png
Binary files differ
diff --git a/tests/regression/throwntogethertest/color-tests-expected.png b/tests/regression/throwntogethertest/color-tests-expected.png
index 6b50080..5d4ed89 100644
--- a/tests/regression/throwntogethertest/color-tests-expected.png
+++ b/tests/regression/throwntogethertest/color-tests-expected.png
Binary files differ
contact: Jan Huwald // Impressum