diff --git a/Mapper.cpp b/Mapper.cpp
new file mode 100644
index 0000000..f65b0f2
--- /dev/null
+++ b/Mapper.cpp
@@ -0,0 +1,66 @@
+/*
+ * Mapper.cpp
+ *
+ * (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "Mapper.h"
+
+void QuadTextureMapper::draw()
+{
+ 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);
+
+ std::tr1::shared_ptr quad = std::tr1::static_pointer_cast(textureMapping->getShape());
+ Q_CHECK_PTR(quad);
+
+ std::tr1::shared_ptr inputQuad = std::tr1::static_pointer_cast(textureMapping->getInputShape());
+ Q_CHECK_PTR(inputQuad);
+
+ printf("Texid: %d\n", texture->getTextureId());
+ // Project source texture and sent it to destination.
+
+ glEnable (GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, texture->getTextureId());
+
+ 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_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ glColor4f(1, 1, 1, 1.0f);
+ glBegin(GL_QUADS);
+ {
+ for (int i=0; i<4; i++)
+ {
+ Util::correctGlTexCoord(
+ ( inputQuad->getVertex(i).x - texture->getX() ) / (GLfloat) texture->getWidth(),
+ ( inputQuad->getVertex(i).y - texture->getY() ) / (GLfloat) texture->getHeight());
+ glVertex3f( quad->getVertex(i).x,
+ quad->getVertex(i).y,
+ 0);
+ }
+ }
+ glEnd();
+
+ glDisable(GL_TEXTURE_2D);
+}
diff --git a/Mapper.h b/Mapper.h
index b7c0c18..e571fb2 100644
--- a/Mapper.h
+++ b/Mapper.h
@@ -26,6 +26,8 @@
#include "Shape.h"
#include "Paint.h"
+#include "Util.h"
+
#include
#include
@@ -129,49 +131,7 @@ public:
QuadTextureMapper(TextureMapping* mapping) : Mapper(mapping) {}
virtual ~QuadTextureMapper() {}
- virtual void draw() {
- 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);
-
- std::tr1::shared_ptr quad = std::tr1::static_pointer_cast(textureMapping->getShape());
- Q_CHECK_PTR(quad);
-
- std::tr1::shared_ptr inputQuad = std::tr1::static_pointer_cast(textureMapping->getInputShape());
- Q_CHECK_PTR(inputQuad);
-
- printf("Texid: %d\n", texture->getTextureId());
- // Project source texture and sent it to destination.
-
- glEnable (GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, texture->getTextureId());
-
- 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_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- glColor4f(1, 1, 1, 1.0f);
- glBegin(GL_QUADS);
- {
- for (int i=0; i<4; i++)
- {
- glTexCoord2f( ( inputQuad->getVertex(i).x - texture->getX() ) / (GLfloat) texture->getWidth(),
- ( inputQuad->getVertex(i).y - texture->getY() ) / (GLfloat) texture->getHeight());
- glVertex3f( quad->getVertex(i).x,
- quad->getVertex(i).y,
- 0);
- }
- }
- glEnd();
-
- glDisable(GL_TEXTURE_2D);
- }
+ virtual void draw();
};
diff --git a/SourceGLCanvas.cpp b/SourceGLCanvas.cpp
index fea83ce..b06d891 100644
--- a/SourceGLCanvas.cpp
+++ b/SourceGLCanvas.cpp
@@ -86,16 +86,16 @@ void SourceGLCanvas::doDraw() {
glColor4f (1, 1, 1, 1.0f);
glBegin (GL_QUADS);
{
- glTexCoord2f (0, 0);
+ Util::correctGlTexCoord(0, 0);
glVertex3f (texture->getX(), texture->getY(), 0);
- glTexCoord2f (1, 0);
+ Util::correctGlTexCoord(1, 0);
glVertex3f (texture->getX()+texture->getWidth(), texture->getY(), 0);
- glTexCoord2f (1, 1);
+ Util::correctGlTexCoord(1, 1);
glVertex3f (texture->getX()+texture->getWidth(), texture->getY()+texture->getHeight(), 0);
- glTexCoord2f (0, 1);
+ Util::correctGlTexCoord(0, 1);
glVertex3f (texture->getX(), texture->getY()+texture->getHeight(), 0);
}
glEnd ();
diff --git a/SourceGLCanvas.h b/SourceGLCanvas.h
index b806db6..8981892 100644
--- a/SourceGLCanvas.h
+++ b/SourceGLCanvas.h
@@ -25,6 +25,8 @@
#include "MapperGLCanvas.h"
#include "DestinationGLCanvas.h"
+#include "Util.h"
+
class SourceGLCanvas: public MapperGLCanvas
{
Q_OBJECT
diff --git a/Util.cpp b/Util.cpp
new file mode 100644
index 0000000..5cedd74
--- /dev/null
+++ b/Util.cpp
@@ -0,0 +1,25 @@
+/*
+ * Util.cpp
+ *
+ * (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "Util.h"
+
+void Util::correctGlTexCoord(GLfloat x, GLfloat y)
+{
+ glTexCoord2f (x, 1.0f - y);
+}
diff --git a/Util.h b/Util.h
new file mode 100644
index 0000000..78a576f
--- /dev/null
+++ b/Util.h
@@ -0,0 +1,31 @@
+/*
+ * Util.h
+ *
+ * (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef UTIL_H_
+#define UTIL_H_
+
+#include
+
+class Util {
+public:
+
+ static void correctGlTexCoord(GLfloat x, GLfloat y);
+};
+
+#endif /* UTIL_H_ */
diff --git a/libremapping.pro b/libremapping.pro
index a2df701..d1e1137 100644
--- a/libremapping.pro
+++ b/libremapping.pro
@@ -1,7 +1,7 @@
CONFIG += qt debug
TEMPLATE = app
-HEADERS = Common.h SourceGLCanvas.h DestinationGLCanvas.h MapperGLCanvas.h
-SOURCES = main.cpp Common.cpp SourceGLCanvas.cpp DestinationGLCanvas.cpp MapperGLCanvas.cpp
+HEADERS = Common.h Util.h SourceGLCanvas.h DestinationGLCanvas.h MapperGLCanvas.h Mapper.h Shape.h Paint.h
+SOURCES = main.cpp Common.cpp Util.cpp Mapper.cpp SourceGLCanvas.cpp DestinationGLCanvas.cpp MapperGLCanvas.cpp
QT += gui opengl
LIBS += -lSOIL -lglut
diff --git a/main.cpp b/main.cpp
index 31ab41d..b51855d 100644
--- a/main.cpp
+++ b/main.cpp
@@ -11,6 +11,9 @@
#include
+#define DEFAULT_WIDTH 800
+#define DEFAULT_HEIGHT 600
+
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
@@ -30,8 +33,6 @@ int main(int argc, char *argv[])
QObject::connect(&destinationCanvas, SIGNAL(quadSwitched()),
&sourceCanvas, SLOT(updateCanvas()));
- Common::initializeLibremapper(320, 480);
-
QSplitter splitter(Qt::Horizontal);
splitter.addWidget(&sourceCanvas);
splitter.addWidget(&destinationCanvas);
@@ -39,10 +40,12 @@ int main(int argc, char *argv[])
sourceCanvas.setFocusPolicy(Qt::ClickFocus);
destinationCanvas.setFocusPolicy(Qt::ClickFocus);
+
splitter.setWindowTitle(QObject::tr("Libremapping"));
- splitter.resize(650, 480);
+ splitter.resize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
splitter.show();
+ Common::initializeLibremapper(sourceCanvas.width(), sourceCanvas.height());
return app.exec();
}