From 05c1bf3a5cab8f630927bec1da154d594646c6a5 Mon Sep 17 00:00:00 2001 From: Tats Date: Wed, 30 Apr 2014 13:21:57 -0400 Subject: [PATCH 01/17] Major cleanup / redesign in the source canvas to make the Mapper class draw the inputs (more generic) --- DestinationGLCanvas.cpp | 52 ++------------ DestinationGLCanvas.h | 2 - Mapper.cpp | 48 +++++++++++++ Mapper.h | 5 ++ Mapping.h | 6 +- SourceGLCanvas.cpp | 148 +++------------------------------------- SourceGLCanvas.h | 4 -- 7 files changed, 72 insertions(+), 193 deletions(-) diff --git a/DestinationGLCanvas.cpp b/DestinationGLCanvas.cpp index e2f7224..988e170 100644 --- a/DestinationGLCanvas.cpp +++ b/DestinationGLCanvas.cpp @@ -36,57 +36,13 @@ Shape* DestinationGLCanvas::getShapeFromMappingId(uid mappingId) void DestinationGLCanvas::doDraw(QPainter* painter) { -// // No sources = nothing to do. -// if (Common::nImages() == 0) -// return; -// -// // TODO: Ceci est un hack necessaire car tout est en fonction de la width/height de la texture. -// // Il faut changer ca. -// std::tr1::shared_ptr textureMapping = std::tr1::static_pointer_cast(Common::currentMapping); -// Q_CHECK_PTR(textureMapping); -// -// std::tr1::shared_ptr texture = std::tr1::static_pointer_cast(textureMapping->getPaint()); -// Q_CHECK_PTR(texture); -// -// for (int i=0; i < Common::nImages(); i++) -// { -// std::tr1::shared_ptr tex = std::tr1::static_pointer_cast(Common::mappings[i]->getPaint()); -// Q_CHECK_PTR(tex); -// -// // FIXME: maybe the texture id is actually 0 and it's ok, no? -// // we should use a boolean is_texture_loaded, or so -// if (tex->getTextureId() == 0) -// { -// tex->loadTexture(); -// } -// } - - - if (getMainWindow() == NULL) - return; - glPushMatrix(); - MappingManager& mappingManager = getMainWindow()->getMappingManager(); - QVector mappings = mappingManager.getVisibleMappings(); + + // Draw the mappings. + QVector mappings = getMainWindow()->getMappingManager().getVisibleMappings(); for (QVector::const_iterator it = mappings.begin(); it != mappings.end(); ++it) { - Mapping::ptr mapping = (*it); - - // XXX: change : UGLY! - if (mapping->getType().endsWith("_texture")) - { - std::tr1::shared_ptr textureMapping = std::tr1::static_pointer_cast(mapping); - Q_CHECK_PTR(textureMapping); - - std::tr1::shared_ptr texture = std::tr1::static_pointer_cast(textureMapping->getPaint()); - Q_CHECK_PTR(texture); - - if (texture->getTextureId() == 0) - texture->loadTexture(); - } - - // Draw the mappings. - getMainWindow()->getMapperByMappingId(mapping->getId())->draw(painter); + getMainWindow()->getMapperByMappingId((*it)->getId())->draw(painter); } // Draw the controls of current mapping. diff --git a/DestinationGLCanvas.h b/DestinationGLCanvas.h index 46cbc8c..cfd270a 100644 --- a/DestinationGLCanvas.h +++ b/DestinationGLCanvas.h @@ -36,8 +36,6 @@ public: virtual Shape* getShapeFromMappingId(uid mappingId); -// virtual Quad& getQuad(); - private: virtual void doDraw(QPainter* painter); }; diff --git a/Mapper.cpp b/Mapper.cpp index 9d682ea..75075b9 100644 --- a/Mapper.cpp +++ b/Mapper.cpp @@ -333,6 +333,54 @@ void TextureMapper::draw(QPainter* painter) void TextureMapper::drawInput(QPainter* painter) { Q_UNUSED(painter); + painter->beginNativePainting(); + + // Only works for similar shapes. + Q_ASSERT( outputShape->nVertices() == outputShape->nVertices()); + + // Project source texture and sent it to destination. + texture->update(); + + glEnable (GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texture->getTextureId()); + + // Copy bits to texture iff necessary. + if (texture->bitsHaveChanged()) + { + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, + texture->getWidth(), texture->getHeight(), 0, GL_RGBA, + GL_UNSIGNED_BYTE, texture->getBits()); + } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + // FIXME: Does this draw the quad counterclockwise? + glBegin (GL_QUADS); + { + Util::correctGlTexCoord(0, 0); + glVertex3f (texture->getX(), texture->getY(), 0); + + Util::correctGlTexCoord(1, 0); + glVertex3f (texture->getX()+texture->getWidth(), texture->getY(), 0); + + Util::correctGlTexCoord(1, 1); + glVertex3f (texture->getX()+texture->getWidth(), texture->getY() + texture->getHeight(), 0); + + Util::correctGlTexCoord(0, 1); + glVertex3f (texture->getX(), texture->getY() + texture->getHeight(), 0); + } + glEnd (); + + glDisable(GL_TEXTURE_2D); + + glPopMatrix(); + + painter->endNativePainting(); } void TextureMapper::drawControls(QPainter* painter) diff --git a/Mapper.h b/Mapper.h index f6a635d..227e473 100644 --- a/Mapper.h +++ b/Mapper.h @@ -72,9 +72,14 @@ protected: public: virtual QWidget* getPropertiesEditor(); + + virtual void draw(QPainter* painter) = 0; virtual void drawControls(QPainter* painter) = 0; + virtual void drawInput(QPainter* painter) { Q_UNUSED(painter); } + virtual void drawInputControls(QPainter* painter) { Q_UNUSED(painter); } + static void drawShapeContour(QPainter* painter, const Shape& shape, int lineWidth, const QColor& color); public slots: diff --git a/Mapping.h b/Mapping.h index 68db3e7..f01cb05 100644 --- a/Mapping.h +++ b/Mapping.h @@ -85,6 +85,9 @@ public: Paint::ptr getPaint() const { return _paint; } Shape::ptr getShape() const { return _shape; } + virtual bool hasInputShape() const { return false; } + virtual Shape::ptr getInputShape() const { return Shape::ptr(); } + uid getId() const { return _id; } void setLocked(bool locked) { _isLocked = locked; } @@ -148,7 +151,8 @@ public: } public: - Shape::ptr getInputShape() const { return _inputShape; } + virtual bool hasInputShape() const { return true; } + virtual Shape::ptr getInputShape() const { return _inputShape; } }; #endif /* MAPPING_H_ */ diff --git a/SourceGLCanvas.cpp b/SourceGLCanvas.cpp index ce2152d..db75cd4 100644 --- a/SourceGLCanvas.cpp +++ b/SourceGLCanvas.cpp @@ -36,149 +36,21 @@ Shape* SourceGLCanvas::getShapeFromMappingId(uid mappingId) else { Mapping::ptr mapping = getMainWindow()->getMappingManager().getMappingById(mappingId); - // TODO: this is real shit... : we should at the very least use some dynamic casting or (better) implement a correct - // class architecture to suit our needs - if (mapping->getType().endsWith("_texture")) - { - std::tr1::shared_ptr textureMapping = std::tr1::static_pointer_cast(mapping); - Q_CHECK_PTR(textureMapping); - - return textureMapping->getInputShape().get(); - } - else - return NULL; + Q_CHECK_PTR(mapping); + return mapping->getInputShape().get(); } } -//Quad& SourceGLCanvas::getQuad() -//{ -// std::tr1::shared_ptr textureMapping = std::tr1::static_pointer_cast(Common::currentMapping); -// Q_CHECK_PTR(textureMapping); -// -// std::tr1::shared_ptr inputQuad = std::tr1::static_pointer_cast(textureMapping->getInputShape()); -// Q_CHECK_PTR(inputQuad); -// -// return (*inputQuad); -//} void SourceGLCanvas::doDraw(QPainter* painter) { - if (!getMainWindow()->hasCurrentPaint()) - return; - - uint paintId = getMainWindow()->getCurrentPaintId(); - - // Retrieve paint (as texture) and draw it. - Paint::ptr paint = getMainWindow()->getMappingManager().getPaintById(paintId); - Q_CHECK_PTR(paint); - - // Retrieve all mappings associated to paint. - QMap mappings = getMainWindow()->getMappingManager().getPaintMappingsById(paintId); - - if (paint->getType() == "color") - _drawColor(painter, paint, mappings); - else - _drawTexture(painter, paint, mappings); -} - -void SourceGLCanvas::_drawColor(QPainter* painter, Paint::ptr paint, QMap mappings) -{ - // Not doing anything for now. - Q_UNUSED(painter); - Q_UNUSED(paint); - Q_UNUSED(mappings); -} - -void SourceGLCanvas::_drawTexture(QPainter* painter, Paint::ptr paint, QMap mappings) -{ - Q_UNUSED(painter); - - std::tr1::shared_ptr texture = std::tr1::static_pointer_cast(paint); - Q_CHECK_PTR(texture); - - // Load texture if needed. - if (texture->getTextureId() == 0) { - texture->loadTexture(); - } - - // Draw the texture. - glPushMatrix(); - - // Enable blending mode (for alphas). - glEnable (GL_BLEND); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glDisable (GL_LIGHTING); - glEnable (GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texture->getTextureId()); - - if (texture->bitsHaveChanged()) - { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->getWidth(), texture->getHeight(), 0, GL_RGBA, - GL_UNSIGNED_BYTE, texture->getBits()); - } - - //std::cout << texture->getX() << "x" << texture->getY() << " : " << texture->getWidth() << "x" << texture->getHeight() << " " << texture->getTextureId() << std::endl; - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - // TODO: Exact projection of texture - // see http://stackoverflow.com/questions/15242507/perspective-correct-texturing-of-trapezoid-in-opengl-es-2-0 - - // Draw source texture (not moving) in the center of the area. - - // float centerX = (float) width() / 2.0f; - // float centerY = (float) height() / 2.0f; - // float textureHalfWidth = (float) texture->getWidth() / 2.0f; - // float textureHalfHeight = (float) texture->getHeight() / 2.0f; - - - glColor4f (1.0f, 1.0f, 1.0f, 1.0f); - // FIXME: Does this draw the quad counterclockwise? - glBegin (GL_QUADS); - { - Util::correctGlTexCoord(0, 0); - glVertex3f (texture->getX(), texture->getY(), 0); - - Util::correctGlTexCoord(1, 0); - glVertex3f (texture->getX()+texture->getWidth(), texture->getY(), 0); - - Util::correctGlTexCoord(1, 1); - glVertex3f (texture->getX()+texture->getWidth(), texture->getY() + texture->getHeight(), 0); - - Util::correctGlTexCoord(0, 1); - glVertex3f (texture->getX(), texture->getY() + texture->getHeight(), 0); - } - glEnd (); - - glDisable(GL_TEXTURE_2D); - - for (QMap::iterator it = mappings.begin(); it != mappings.end(); ++it) - { - // TODO: Ceci est un hack necessaire car tout est en fonction de la width/height de la texture. - // Il faut changer ca. - std::tr1::shared_ptr textureMapping = std::tr1::static_pointer_cast(it.value()); - Q_CHECK_PTR(textureMapping); - - std::tr1::shared_ptr inputShape = std::tr1::static_pointer_cast(textureMapping->getInputShape()); - Q_CHECK_PTR(inputShape); - - if (displayControls() && - it.key() == getMainWindow()->getCurrentMappingId()) - { - Mapper::ptr mapper = getMainWindow()->getMapperByMappingId(it.key()); - Q_CHECK_PTR(mapper); - - std::tr1::shared_ptr textureMapper = std::tr1::static_pointer_cast(mapper); - Q_CHECK_PTR(textureMapper); - - textureMapper->drawInputControls(painter); - } - } - - glPopMatrix(); + if (getMainWindow()->hasCurrentMapping()) + { + uint mappingId = getMainWindow()->getCurrentMappingId(); + Mapper::ptr mapper = getMainWindow()->getMapperByMappingId(mappingId); + mapper->drawInput(painter); + if (displayControls()) + mapper->drawInputControls(painter); + } } diff --git a/SourceGLCanvas.h b/SourceGLCanvas.h index f0ac43e..60161f1 100644 --- a/SourceGLCanvas.h +++ b/SourceGLCanvas.h @@ -36,13 +36,9 @@ public: // virtual ~SourceGLCanvas() {} virtual Shape* getShapeFromMappingId(uid mappingId); -// virtual Quad& getQuad(); private: virtual void doDraw(QPainter* painter); - - void _drawColor(QPainter* painter, Paint::ptr paint, QMap mappings); - void _drawTexture(QPainter* painter, Paint::ptr paint, QMap mappings); }; From 5ced74f36092c704e12a5d625aad2b2d10b0be60 Mon Sep 17 00:00:00 2001 From: Alexandre Quessy Date: Sat, 26 Apr 2014 06:21:58 -0400 Subject: [PATCH 02/17] remove useless flags in .pro file for os x --- mapmap.pro | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mapmap.pro b/mapmap.pro index 095efe1..a9ce38b 100644 --- a/mapmap.pro +++ b/mapmap.pro @@ -93,9 +93,9 @@ unix:!mac { # Mac OS X-specific: mac { DEFINES += MACOSX - INCLUDEPATH += \ - /opt/local/include/ \ - /opt/local/include/libxml2 + # INCLUDEPATH += \ + # /opt/local/include/ \ + # /opt/local/include/libxml2 LIBS += \ -framework OpenGL \ -framework GLUT From c1d6a407167f606fd5d325a32aee2f82032bb325 Mon Sep 17 00:00:00 2001 From: Alexandre Quessy Date: Wed, 30 Apr 2014 15:56:08 -0400 Subject: [PATCH 03/17] more instructions and more todo --- BUGS | 5 +++++ INSTALL | 2 +- TODO | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/BUGS b/BUGS index 61ee0c5..cf14dbc 100644 --- a/BUGS +++ b/BUGS @@ -4,3 +4,8 @@ LibreMapping known bugs * cannot delete paints * cannot remove points in meshes +On OS X +------- +QObject: shared QObject was deleted directly. The program is malformed and may crash. +mapmap(299,0x7fff79da0310) malloc: *** error for object 0x102229ce0: pointer being freed was not allocated +*** set a breakpoint in malloc_error_break to debug diff --git a/INSTALL b/INSTALL index 01e2cf1..fe296f8 100644 --- a/INSTALL +++ b/INSTALL @@ -46,7 +46,7 @@ Build on Mac OS X * Install the Apple Developer Tools. You need to register with a credit card in the Apple Store in order to download it. * Install Qt5. You can get it from http://qt-project.org/downloads and choose the default location. -* Install the GStreamer SDK development files. +* Install the GStreamer SDK development files http://docs.gstreamer.com/display/GstSDK/Installing+on+Mac+OS+X Do this:: diff --git a/TODO b/TODO index 8393dee..da18912 100644 --- a/TODO +++ b/TODO @@ -49,3 +49,25 @@ Fonctionnalités cool à faire plus tard * animation de stroke par groupe * OSC pour controler les positions et l'alpha des quads +OSC INTERFACE ADDITIONAL CALLBACKS +---------------------------------- +Instead of using boolean values (true or false) we use numbers, where 0 means false, and any positive number means true. + +You should make sure to block all incoming messages on that port if you don't want to be hacked during a show. + +/mapmap/mapping/move/xy ,iff +/mapmap/mapping/vertex/source/xy ,iiff +/mapmap/mapping/vertex/destination/xy ,iiff +/mapmap/mapping/visible ,ii +/mapmap/mapping/highlight ,ii +/mapmap/mapping/vertex/highlight ,iii +/mapmap/project/load ,s +/mapmap/project/save ,s +/mapmap/paint/color/rgba ,iffff (each channel within [0,1]) +/mapmap/paint/texture/load ,is +/mapmap/paint/texture/speed ,if (1.0 means 100% speed) +/mapmap/paint/texture/seek ,il