summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/GLView.h3
-rw-r--r--src/glview.cc49
-rw-r--r--tests/opencsgtest.cc68
3 files changed, 88 insertions, 32 deletions
diff --git a/src/GLView.h b/src/GLView.h
index 7516894..f729838 100644
--- a/src/GLView.h
+++ b/src/GLView.h
@@ -18,6 +18,7 @@ class GLView : public QGLWidget
public:
GLView(QWidget *parent = NULL);
+ GLView(const QGLFormat & format, QWidget *parent = NULL);
void setRenderFunc(void (*func)(void*), void *userdata);
#ifdef ENABLE_OPENCSG
bool hasOpenCSGSupport() { return this->opencsg_support; }
@@ -45,6 +46,8 @@ public:
#endif
private:
+ void init();
+
void (*renderfunc)(void*);
void *renderfunc_vp;
diff --git a/src/glview.cc b/src/glview.cc
index e51f31f..f4b2ccf 100644
--- a/src/glview.cc
+++ b/src/glview.cc
@@ -39,35 +39,45 @@
GLView::GLView(QWidget *parent) : QGLWidget(parent)
{
- viewer_distance = 500;
- object_rot_x = 35;
- object_rot_y = 0;
- object_rot_z = 25;
- object_trans_x = 0;
- object_trans_y = 0;
- object_trans_z = 0;
+ init();
+}
- mouse_drag_active = false;
- last_mouse_x = 0;
- last_mouse_y = 0;
+GLView::GLView(const QGLFormat & format, QWidget *parent) : QGLWidget(format, parent)
+{
+ init();
+}
- orthomode = false;
- showaxes = false;
- showcrosshairs = false;
+void GLView::init()
+{
+ this->viewer_distance = 500;
+ this->object_rot_x = 35;
+ this->object_rot_y = 0;
+ this->object_rot_z = 25;
+ this->object_trans_x = 0;
+ this->object_trans_y = 0;
+ this->object_trans_z = 0;
+
+ this->mouse_drag_active = false;
+ this->last_mouse_x = 0;
+ this->last_mouse_y = 0;
- renderfunc = NULL;
- renderfunc_vp = NULL;
+ this->orthomode = false;
+ this->showaxes = false;
+ this->showcrosshairs = false;
+
+ this->renderfunc = NULL;
+ this->renderfunc_vp = NULL;
for (int i = 0; i < 10; i++)
- shaderinfo[i] = 0;
+ this->shaderinfo[i] = 0;
- statusLabel = NULL;
+ this->statusLabel = NULL;
setMouseTracking(true);
#ifdef ENABLE_OPENCSG
- opencsg_support = true;
+ this->opencsg_support = true;
static int sId = 0;
- opencsg_id = sId++;
+ this->opencsg_id = sId++;
#endif
}
@@ -513,4 +523,3 @@ void GLView::mouseReleaseEvent(QMouseEvent*)
mouse_drag_active = false;
releaseMouse();
}
-
diff --git a/tests/opencsgtest.cc b/tests/opencsgtest.cc
index f6e5917..9381c54 100644
--- a/tests/opencsgtest.cc
+++ b/tests/opencsgtest.cc
@@ -13,13 +13,16 @@
#include "render-opencsg.h"
#include <GL/glew.h>
#include "GLView.h"
+#include "mainwindow.h"
#include <QApplication>
#include <QFile>
#include <QDir>
#include <QSet>
+#include <QTimer>
using std::cerr;
+using std::cout;
QString commandline_commands;
QString librarydir;
@@ -139,15 +142,32 @@ static void renderGLThrownTogether(void *vp)
static void renderGLviaOpenCSG(void *vp)
{
CsgInfo *csgInfo = (CsgInfo *)vp;
- static bool glew_initialized = false;
- if (!glew_initialized) {
- glew_initialized = true;
- glewInit();
+
+ if (csgInfo->root_chain) {
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+ glDepthFunc(GL_LEQUAL);
+ QHash<QPair<PolySet*,double*>,int> polySetVisitMark;
+ bool showEdges = false;
+ int i = 1;
+ double *m = csgInfo->root_chain->matrices[i];
+ glPushMatrix();
+ glMultMatrixd(m);
+ int csgmode = csgInfo->root_chain->types[i] == CSGTerm::TYPE_DIFFERENCE ? PolySet::CSGMODE_DIFFERENCE : PolySet::CSGMODE_NORMAL;
+ csgInfo->root_chain->polysets[i]->render_surface(PolySet::COLORMODE_MATERIAL, PolySet::csgmode_e(csgmode), m);
+ glPopMatrix();
}
+
+ // static bool glew_initialized = false;
+ // if (!glew_initialized) {
+ // glew_initialized = true;
+ // glewInit();
+ // }
#ifdef ENABLE_MDI
OpenCSG::setContext(csgInfo->glview->opencsg_id);
#endif
if (csgInfo->root_chain) {
+ renderCSGChainviaOpenCSG(csgInfo->root_chain, NULL, false, false);
GLint *shaderinfo = csgInfo->glview->shaderinfo;
if (!shaderinfo[0]) shaderinfo = NULL;
renderCSGChainviaOpenCSG(csgInfo->root_chain, NULL, false, false);
@@ -306,16 +326,40 @@ int main(int argc, char *argv[])
}
}
- // QGLFormat fmt;
- // fmt.setDirectRendering(false);
- csgInfo.glview = new GLView(NULL);
-// FIXME: Thrown together works, OpenCSG not..
-// csgInfo.glview->setRenderFunc(renderGLviaOpenCSG, &csgInfo);
- csgInfo.glview->setRenderFunc(renderGLThrownTogether, &csgInfo);
-
QDir::setCurrent(original_path.absolutePath());
- csgInfo.glview->renderPixmap(512, 512).save("out.png");
+ QGLFormat fmt = QGLFormat::defaultFormat();
+// fmt.setDirectRendering(false);
+// fmt.setDoubleBuffer(false);
+
+ csgInfo.glview = new GLView(fmt, NULL);
+ csgInfo.glview->makeCurrent();
+
+ glewInit();
+ cout << "GLEW version " << glewGetString(GLEW_VERSION) << "\n";
+ cout << (const char *)glGetString(GL_RENDERER) << "(" << (const char *)glGetString(GL_VENDOR) << ")\n"
+ << "OpenGL version " << (const char *)glGetString(GL_VERSION) << "\n";
+ cout << "Extensions: " << (const char *)glGetString(GL_EXTENSIONS) << "\n";
+
+
+ if (GLEW_ARB_framebuffer_object) {
+ cout << "ARB_FBO supported\n";
+ }
+ if (GLEW_EXT_framebuffer_object) {
+ cout << "EXT_FBO supported\n";
+ }
+ if (GLEW_EXT_packed_depth_stencil) {
+ cout << "EXT_packed_depth_stencil\n";
+ }
+
+// csgInfo.glview->setRenderFunc(renderGLThrownTogether, &csgInfo);
+ csgInfo.glview->setRenderFunc(renderGLviaOpenCSG, &csgInfo);
+ csgInfo.glview->show();
+ csgInfo.glview->hide();
+
+ QImage img = csgInfo.glview->grabFrameBuffer();
+ cout << "Image: " << img.width() << "x" << img.height() << " " << img.format() << "\n";
+ img.save("out.png");
destroy_builtin_functions();
destroy_builtin_modules();
contact: Jan Huwald // Impressum