Change how Canvas is flipped and add Canvas::drawq

This commit is contained in:
Bill Meltsner
2011-10-04 11:34:33 -04:00
parent 9425c56de8
commit 4cb247b3ea
2 changed files with 47 additions and 20 deletions
+35 -20
View File
@@ -177,10 +177,10 @@ namespace opengl
vertices[3].x = w; vertices[3].y = 0;
// texture coordinates
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;
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;
loadStrategy();
@@ -228,8 +228,8 @@ namespace opengl
glPushMatrix();
glLoadIdentity();
// Set up orthographic view (no depth)
glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
// Set up upside-down orthographic view (no depth)
glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
// Switch back to modelview matrix
glMatrixMode(GL_MODELVIEW);
@@ -273,20 +273,16 @@ namespace opengl
static Matrix t;
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
glPushMatrix();
glMultMatrixf((const GLfloat*)t.getElements());
glBindTexture(GL_TEXTURE_2D, img);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].s);
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
drawv(t, vertices);
}
void Canvas::drawq(Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
static Matrix t;
const vertex * v = quad->getVertices();
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
drawv(t, v);
}
love::image::ImageData * Canvas::getImageData(love::image::Image * image)
@@ -399,6 +395,25 @@ namespace opengl
{
return height;
}
void Canvas::drawv(const Matrix & t, const vertex * v) const
{
glPushMatrix();
glMultMatrixf((const GLfloat*)t.getElements());
glBindTexture(GL_TEXTURE_2D, img);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&v[0].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&v[0].s);
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
} // opengl
} // graphics
+12
View File
@@ -8,7 +8,9 @@
#include <image/Image.h>
#include <image/ImageData.h>
#include <common/math.h>
#include <common/Matrix.h>
#include "GLee.h"
#include "Quad.h"
namespace love
{
@@ -35,6 +37,14 @@ namespace opengl
void clear(const Color& c);
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
/**
* This function draws a section of the canvas using a Quad object.
*
* @param quad Represents the region of the Canvas to draw.
**/
void drawq(Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
love::image::ImageData * getImageData(love::image::Image * image);
void setFilter(const Image::Filter &f);
@@ -67,6 +77,8 @@ namespace opengl
Image::Filter filter;
Image::Wrap wrap;
} settings;
void drawv(const Matrix & t, const vertex * v) const;
};
} // opengl