mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Always draw OpenGL shapes' vertices in a counterclockwise order
This commit is contained in:
+5
-6
@@ -33,11 +33,12 @@ Quad* Common::createQuadForTexture(Texture* texture, int frameWidth, int frameHe
|
||||
float textureHalfWidth = texture->getWidth() / 2.0f;
|
||||
float textureHalfHeight = texture->getHeight() / 2.0f;
|
||||
|
||||
// XXX We should always draw OpenGL shapes counterclockwise
|
||||
return new Quad(
|
||||
Point(centerX-textureHalfWidth, centerY-textureHalfHeight),
|
||||
Point(centerX+textureHalfWidth, centerY-textureHalfHeight),
|
||||
Point(centerX+textureHalfWidth, centerY+textureHalfHeight),
|
||||
Point(centerX-textureHalfWidth, centerY+textureHalfHeight));
|
||||
Point(centerX - textureHalfWidth, centerY - textureHalfHeight),
|
||||
Point(centerX - textureHalfWidth, centerY + textureHalfHeight),
|
||||
Point(centerX + textureHalfWidth, centerY + textureHalfHeight),
|
||||
Point(centerX + textureHalfWidth, centerY - textureHalfHeight));
|
||||
}
|
||||
|
||||
void Common::addImage(const std::string imagePath, int frameWidth, int frameHeight)
|
||||
@@ -46,10 +47,8 @@ void Common::addImage(const std::string imagePath, int frameWidth, int frameHeig
|
||||
|
||||
TextureMapping* tm = new TextureMapping(
|
||||
img,
|
||||
|
||||
// Destination.
|
||||
createQuadForTexture(img, frameWidth, frameHeight),
|
||||
|
||||
// Input.
|
||||
createQuadForTexture(img, frameWidth, frameHeight)
|
||||
);
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ void QuadTextureMapper::draw()
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glBegin(GL_QUADS);
|
||||
{
|
||||
for (int i=0; i<4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Util::correctGlTexCoord(
|
||||
(inputQuad->getVertex(i).x - texture->getX()) / (GLfloat) texture->getWidth(),
|
||||
|
||||
+4
-4
@@ -33,7 +33,7 @@ void MapperGLCanvas::initializeGL()
|
||||
//glEnable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
void MapperGLCanvas::resizeGL(int width, int height)
|
||||
void MapperGLCanvas::resizeGL(int /* width */, int /* height */)
|
||||
{
|
||||
// glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
//
|
||||
@@ -63,8 +63,8 @@ void MapperGLCanvas::draw()
|
||||
exitDraw();
|
||||
}
|
||||
|
||||
void MapperGLCanvas::enterDraw() {
|
||||
|
||||
void MapperGLCanvas::enterDraw()
|
||||
{
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, width(), height());
|
||||
@@ -138,7 +138,7 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event)
|
||||
emit quadChanged();
|
||||
}
|
||||
|
||||
void MapperGLCanvas::paintEvent(QPaintEvent* event)
|
||||
void MapperGLCanvas::paintEvent(QPaintEvent* /* event */)
|
||||
{
|
||||
std::cout << "Paint event" << std::endl;
|
||||
updateGL();
|
||||
|
||||
@@ -17,12 +17,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SHAPE_H_
|
||||
#define SHAPE_H_
|
||||
|
||||
#include <vector>
|
||||
#include <SOIL/SOIL.h>
|
||||
|
||||
struct Point
|
||||
{
|
||||
@@ -41,8 +39,14 @@ public:
|
||||
|
||||
virtual void build() {}
|
||||
|
||||
const Point& getVertex(int i) { return vertices[i]; }
|
||||
void setVertex(int i, Point v) { vertices[i] = v; }
|
||||
const Point& getVertex(int i)
|
||||
{
|
||||
return vertices[i];
|
||||
}
|
||||
void setVertex(int i, Point v)
|
||||
{
|
||||
vertices[i] = v;
|
||||
}
|
||||
void setVertex(int i, double x, double y)
|
||||
{
|
||||
vertices[i].x = x;
|
||||
@@ -54,7 +58,8 @@ class Quad : public Shape
|
||||
{
|
||||
public:
|
||||
Quad() {}
|
||||
Quad(Point p1, Point p2, Point p3, Point p4) {
|
||||
Quad(Point p1, Point p2, Point p3, Point p4)
|
||||
{
|
||||
vertices.push_back(p1);
|
||||
vertices.push_back(p2);
|
||||
vertices.push_back(p3);
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
// NOTE: To run, it is recommended not to be in Compiz or Beryl, they have shown some instability.
|
||||
|
||||
#include <iostream>
|
||||
#include <QApplication>
|
||||
#include <QtGui>
|
||||
|
||||
#include "Common.h"
|
||||
#include "DestinationGLCanvas.h"
|
||||
#include "SourceGLCanvas.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#define DEFAULT_WIDTH 800
|
||||
#define DEFAULT_HEIGHT 600
|
||||
|
||||
@@ -40,8 +36,7 @@ int main(int argc, char *argv[])
|
||||
sourceCanvas.setFocusPolicy(Qt::ClickFocus);
|
||||
destinationCanvas.setFocusPolicy(Qt::ClickFocus);
|
||||
|
||||
|
||||
splitter.setWindowTitle(QObject::tr("Libremapping"));
|
||||
splitter.setWindowTitle(QObject::tr("LibreMapping"));
|
||||
splitter.resize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
splitter.show();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user