mirror of
https://github.com/love2d/love.git
synced 2026-08-13 09:00:54 +02:00
Revert Canvas flipping (commits 9cb824e2fa84, e0234edd0026) in order to fix issue #324.
This commit is contained in:
@@ -50,6 +50,11 @@ namespace graphics
|
||||
|
||||
virtual void flip(bool x, bool y) = 0;
|
||||
|
||||
/**
|
||||
* Mirror texture coordinates around 0.5
|
||||
*/
|
||||
virtual void mirror(bool x, bool y) = 0;
|
||||
|
||||
/**
|
||||
* Gets a pointer to the vertices.
|
||||
**/
|
||||
|
||||
@@ -195,10 +195,10 @@ namespace opengl
|
||||
vertices[3].x = w; vertices[3].y = 0;
|
||||
|
||||
// texture coordinates
|
||||
vertices[0].s = 0; vertices[0].t = 0;
|
||||
vertices[1].s = 0; vertices[1].t = 1;
|
||||
vertices[2].s = 1; vertices[2].t = 1;
|
||||
vertices[3].s = 1; vertices[3].t = 0;
|
||||
vertices[0].s = 0; vertices[0].t = 1;
|
||||
vertices[1].s = 0; vertices[1].t = 0;
|
||||
vertices[2].s = 1; vertices[2].t = 0;
|
||||
vertices[3].s = 1; vertices[3].t = 1;
|
||||
|
||||
loadStrategy();
|
||||
|
||||
@@ -246,8 +246,8 @@ namespace opengl
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
// Set up upside-down orthographic view (no depth)
|
||||
glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
|
||||
// Set up orthographic view (no depth)
|
||||
glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
|
||||
|
||||
// Switch back to modelview matrix
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
@@ -297,15 +297,20 @@ namespace opengl
|
||||
void Canvas::drawq(love::graphics::Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||
{
|
||||
static Matrix t;
|
||||
quad->mirror(false, true);
|
||||
const vertex * v = quad->getVertices();
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
drawv(t, v);
|
||||
quad->mirror(false, true);
|
||||
}
|
||||
|
||||
love::image::ImageData * Canvas::getImageData(love::image::Image * image)
|
||||
{
|
||||
GLubyte * pixels = new GLubyte[4*width*height];
|
||||
int row = 4 * width;
|
||||
int size = row * height;
|
||||
GLubyte* pixels = new GLubyte[size];
|
||||
GLubyte* screenshot = new GLubyte[size];
|
||||
|
||||
strategy->bindFBO( fbo );
|
||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
@@ -314,8 +319,15 @@ namespace opengl
|
||||
else
|
||||
strategy->bindFBO( 0 );
|
||||
|
||||
love::image::ImageData * img = image->newImageData(width, height, (void*)pixels);
|
||||
GLubyte * src = pixels - row; // second line of source image
|
||||
GLubyte * dst = screenshot + size; // last row of destination image
|
||||
|
||||
for (int i = 0; i < height; ++i)
|
||||
memcpy(dst -= row, src += row, row);
|
||||
|
||||
love::image::ImageData* img = image->newImageData(width, height, (void*)screenshot);
|
||||
|
||||
delete[] screenshot;
|
||||
delete[] pixels;
|
||||
|
||||
return img;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
@@ -36,7 +36,7 @@ namespace opengl
|
||||
Quad::Quad(const Viewport & v, float sw, float sh)
|
||||
: sw(sw), sh(sh)
|
||||
{
|
||||
memset(vertices, 255, sizeof(vertex)*4);
|
||||
memset(vertices, 255, sizeof(vertex)*NUM_VERTICES);
|
||||
refresh(v, sw, sh);
|
||||
}
|
||||
|
||||
@@ -53,22 +53,22 @@ namespace opengl
|
||||
}
|
||||
viewport = v;
|
||||
|
||||
vertices[0].x = 0;
|
||||
vertices[0].x = 0;
|
||||
vertices[0].y = 0;
|
||||
vertices[1].x = 0;
|
||||
vertices[1].x = 0;
|
||||
vertices[1].y = v.h;
|
||||
vertices[2].x = v.w;
|
||||
vertices[2].x = v.w;
|
||||
vertices[2].y = v.h;
|
||||
vertices[3].x = v.w;
|
||||
vertices[3].x = v.w;
|
||||
vertices[3].y = 0;
|
||||
|
||||
vertices[0].s = v.x/sw;
|
||||
|
||||
vertices[0].s = v.x/sw;
|
||||
vertices[0].t = v.y/sh;
|
||||
vertices[1].s = v.x/sw;
|
||||
vertices[1].s = v.x/sw;
|
||||
vertices[1].t = (v.y+v.h)/sh;
|
||||
vertices[2].s = (v.x+v.w)/sw;
|
||||
vertices[2].s = (v.x+v.w)/sw;
|
||||
vertices[2].t = (v.y+v.h)/sh;
|
||||
vertices[3].s = (v.x+v.w)/sw;
|
||||
vertices[3].s = (v.x+v.w)/sw;
|
||||
vertices[3].t = v.y/sh;
|
||||
}
|
||||
|
||||
@@ -79,15 +79,15 @@ namespace opengl
|
||||
|
||||
Quad::Viewport Quad::getViewport() const
|
||||
{
|
||||
return viewport;
|
||||
return viewport;
|
||||
}
|
||||
|
||||
|
||||
void Quad::flip(bool x, bool y)
|
||||
{
|
||||
vertex temp[4];
|
||||
if (x)
|
||||
{
|
||||
memcpy(temp, vertices, sizeof(vertex)*4);
|
||||
memcpy(temp, vertices, sizeof(vertex)*NUM_VERTICES);
|
||||
vertices[0].s = temp[3].s; vertices[0].t = temp[3].t;
|
||||
vertices[1].s = temp[2].s; vertices[1].t = temp[2].t;
|
||||
vertices[2].s = temp[1].s; vertices[2].t = temp[1].t;
|
||||
@@ -95,7 +95,7 @@ namespace opengl
|
||||
}
|
||||
if (y)
|
||||
{
|
||||
memcpy(temp, vertices, sizeof(vertex)*4);
|
||||
memcpy(temp, vertices, sizeof(vertex)*NUM_VERTICES);
|
||||
vertices[0].s = temp[1].s; vertices[0].t = temp[1].t;
|
||||
vertices[1].s = temp[0].s; vertices[1].t = temp[0].t;
|
||||
vertices[2].s = temp[3].s; vertices[2].t = temp[3].t;
|
||||
@@ -103,6 +103,16 @@ namespace opengl
|
||||
}
|
||||
}
|
||||
|
||||
void Quad::mirror(bool x, bool y)
|
||||
{
|
||||
for (size_t i = 0; i < NUM_VERTICES; ++i) {
|
||||
if (x)
|
||||
vertices[i].s = 1.0 - vertices[i].s;
|
||||
if (y)
|
||||
vertices[i].s = 1.0 - vertices[i].s;
|
||||
}
|
||||
}
|
||||
|
||||
const vertex * Quad::getVertices() const
|
||||
{
|
||||
return vertices;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
@@ -33,11 +33,12 @@ namespace opengl
|
||||
{
|
||||
class Quad : public love::graphics::Quad
|
||||
{
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
vertex vertices[4];
|
||||
|
||||
|
||||
static const unsigned int NUM_VERTICES = 4;
|
||||
vertex vertices[NUM_VERTICES];
|
||||
|
||||
Viewport viewport;
|
||||
float sw, sh;
|
||||
|
||||
@@ -47,7 +48,7 @@ namespace opengl
|
||||
* Creates a new Quad of size (w,h), using (x,y) as the top-left
|
||||
* anchor point in the source image. The size of the source image is
|
||||
* is specified by (sw,sh).
|
||||
*
|
||||
*
|
||||
* @param sw Width of the source image.
|
||||
* @param sh Height of the source image.
|
||||
**/
|
||||
@@ -61,6 +62,7 @@ namespace opengl
|
||||
Viewport getViewport() const;
|
||||
|
||||
void flip(bool x, bool y);
|
||||
void mirror(bool x, bool y);
|
||||
|
||||
/**
|
||||
* Gets a pointer to the vertices.
|
||||
|
||||
Reference in New Issue
Block a user