-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDestinationGLCanvas.cpp
112 lines (97 loc) · 3.36 KB
/
DestinationGLCanvas.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* DestinationGLCanvas.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 <http://www.gnu.org/licenses/>.
*/
#include "DestinationGLCanvas.h"
#include "MainWindow.h"
DestinationGLCanvas::DestinationGLCanvas(QWidget* parent, const QGLWidget * shareWidget)
: MapperGLCanvas(parent, shareWidget)
{
;
}
Shape* DestinationGLCanvas::getShapeFromMappingId(int mappingId)
{
if (mappingId >= 0)
return MainWindow::getInstance().getMappingManager().getMapping(mappingId)->getShape().get();
else
return NULL;
}
void DestinationGLCanvas::doDraw()
{
// // 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> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(Common::currentMapping);
// Q_CHECK_PTR(textureMapping);
//
// std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
// Q_CHECK_PTR(texture);
//
// for (int i=0; i < Common::nImages(); i++)
// {
// std::tr1::shared_ptr<Texture> tex = std::tr1::static_pointer_cast<Texture>(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();
// }
// }
glPushMatrix();
MappingManager& mappingManager = MainWindow::getInstance().getMappingManager();
std::vector<Layer::ptr> layers = mappingManager.getVisibleLayers();
for (std::vector<Layer::ptr>::const_iterator it = layers.begin(); it != layers.end(); ++it)
{
Mapping::ptr mapping = (*it)->getMapping();
std::tr1::shared_ptr<TextureMapping> textureMapping = std::tr1::static_pointer_cast<TextureMapping>(mapping);
Q_CHECK_PTR(textureMapping);
std::tr1::shared_ptr<Texture> texture = std::tr1::static_pointer_cast<Texture>(textureMapping->getPaint());
Q_CHECK_PTR(texture);
if (texture->getTextureId() == 0)
texture->loadTexture();
// Draw the mappings.
MainWindow::getInstance().getMapperByMappingId(mapping->getId())->draw();
}
// Draw the shape.
if (!MainWindow::getInstance().hasCurrentMapping())
return;
Shape* shape = getCurrentShape();
if (shape)
{
glColor4f(0.0f, 0.0f, 0.7f, 1.0f);
// Destination quad.
// Source quad.
glLineWidth(5);
glBegin (GL_LINE_STRIP);
{
for (int i = 0; i < shape->nVertices()+1; i++)
{
glVertex2f(
shape->getVertex(i % shape->nVertices()).x,
shape->getVertex(i % shape->nVertices()).y
);
}
}
glEnd ();
}
glPopMatrix();
}