From 4cb247b3ea6fafdbc1c064dd0d14f1d716ee8aaf Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Tue, 4 Oct 2011 11:34:33 -0400 Subject: [PATCH] Change how Canvas is flipped and add Canvas::drawq --- src/modules/graphics/opengl/Canvas.cpp | 55 ++++++++++++++++---------- src/modules/graphics/opengl/Canvas.h | 12 ++++++ 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 60cf10ca2..70d66c13c 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -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 diff --git a/src/modules/graphics/opengl/Canvas.h b/src/modules/graphics/opengl/Canvas.h index a3ef7c323..40b9aed2d 100644 --- a/src/modules/graphics/opengl/Canvas.h +++ b/src/modules/graphics/opengl/Canvas.h @@ -8,7 +8,9 @@ #include #include #include +#include #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