Always draw OpenGL shapes' vertices in a counterclockwise order

This commit is contained in:
Alexandre Quessy
2013-11-26 22:08:02 -05:00
parent b6bcd27706
commit ed1056527d
5 changed files with 22 additions and 23 deletions
+5 -6
View File
@@ -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
View File
@@ -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
View File
@@ -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();
+10 -5
View File
@@ -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);
+2 -7
View File
@@ -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();