diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 527a487f8..aab365f54 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -37,7 +37,7 @@ namespace opengl { Graphics::Graphics() - : currentFont(0), lineWidth(1), matrixLimit(0), userMatrices(0) + : currentFont(0), currentImageFilter(), lineWidth(1), matrixLimit(0), userMatrices(0) { // Indicates that there is no screen // created yet. @@ -476,7 +476,7 @@ namespace opengl Image * Graphics::newImage(love::image::ImageData * data) { // Create the image. - Image * image = new Image(data); + Image * image = new Image(data, currentImageFilter); bool success; try { success = image->load(); @@ -673,6 +673,11 @@ namespace opengl glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); } + void Graphics::setDefaultImageFilter(const Image::Filter& f) + { + currentImageFilter = f; + } + Graphics::BlendMode Graphics::getBlendMode () { GLint dst, src, equation; @@ -705,6 +710,11 @@ namespace opengl return COLOR_REPLACE; } + const Image::Filter& Graphics::getDefaultImageFilter() const + { + return currentImageFilter; + } + void Graphics::setLineWidth( float width ) { lineWidth = width; diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 2ade6ad3c..b55b6a547 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -113,6 +113,7 @@ namespace opengl private: Font * currentFont; + Image::Filter currentImageFilter; DisplayMode currentMode; float lineWidth; @@ -332,6 +333,11 @@ namespace opengl **/ void setColorMode (ColorMode mode); + /** + * Sets the current image filter. + **/ + void setDefaultImageFilter(const Image::Filter& f); + /** * Gets the current blend mode. **/ @@ -342,6 +348,11 @@ namespace opengl **/ ColorMode getColorMode(); + /** + * Gets the current image filter. + **/ + const Image::Filter& getDefaultImageFilter() const; + /** * Sets the line width. * @param width The new width of the line. diff --git a/src/modules/graphics/opengl/Image.cpp b/src/modules/graphics/opengl/Image.cpp index ec0f6a133..19a1a91bd 100644 --- a/src/modules/graphics/opengl/Image.cpp +++ b/src/modules/graphics/opengl/Image.cpp @@ -29,7 +29,7 @@ namespace graphics { namespace opengl { - Image::Image(love::image::ImageData * data) + Image::Image(love::image::ImageData * data, const Image::Filter& filter) : width((float)(data->getWidth())), height((float)(data->getHeight())), texture(0) { data->retain(); @@ -47,6 +47,7 @@ namespace opengl vertices[2].s = 1; vertices[2].t = 1; vertices[3].s = 1; vertices[3].t = 0; + setFilter(filter); } Image::~Image() @@ -119,7 +120,7 @@ namespace opengl drawv(t, v); } - void Image::setFilter(Image::Filter f) + void Image::setFilter(const Image::Filter& f) { GLint gmin, gmag; gmin = gmag = 0; // so that they're not used uninitialized diff --git a/src/modules/graphics/opengl/Image.h b/src/modules/graphics/opengl/Image.h index d97129d30..1e0dbefff 100644 --- a/src/modules/graphics/opengl/Image.h +++ b/src/modules/graphics/opengl/Image.h @@ -78,7 +78,7 @@ namespace opengl * * @param file The file from which to load the image. **/ - Image(love::image::ImageData * data); + Image(love::image::ImageData * data, const Image::Filter& f = Image::Filter()); /** * Destructor. Deletes the hardware texture and other resources. @@ -121,7 +121,7 @@ namespace opengl * * @param mode The filter mode. **/ - void setFilter(Image::Filter f); + void setFilter(const Image::Filter& f); Image::Filter getFilter() const; diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 14c9c80a5..753ff6332 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -568,6 +568,25 @@ namespace opengl return 0; } + int w_setDefaultImageFilter(lua_State * L) + { + Image::FilterMode min; + Image::FilterMode mag; + const char * minstr = luaL_checkstring(L, 1); + const char * magstr = luaL_checkstring(L, 2); + if (!Image::getConstant(minstr, min)) + return luaL_error(L, "Invalid filter mode: %s", minstr); + if (!Image::getConstant(magstr, mag)) + return luaL_error(L, "Invalid filter mode: %s", magstr); + + Image::Filter f; + f.min = min; + f.mag = mag; + instance->setDefaultImageFilter(f); + + return 0; + } + int w_getBlendMode(lua_State * L) { Graphics::BlendMode mode = instance->getBlendMode(); @@ -590,6 +609,18 @@ namespace opengl return 1; } + int w_getDefaultImageFilter(lua_State * L) + { + const Image::Filter& f = instance->getDefaultImageFilter(); + const char * minstr; + const char * magstr; + Image::getConstant(f.min, minstr); + Image::getConstant(f.mag, magstr); + lua_pushstring(L, minstr); + lua_pushstring(L, magstr); + return 2; + } + int w_setLineWidth(lua_State * L) { float width = (float)luaL_checknumber(L, 1); @@ -1159,8 +1190,10 @@ namespace opengl { "setBlendMode", w_setBlendMode }, { "setColorMode", w_setColorMode }, + { "setDefaultImageFilter", w_setDefaultImageFilter }, { "getBlendMode", w_getBlendMode }, { "getColorMode", w_getColorMode }, + { "getDefaultImageFilter", w_getDefaultImageFilter }, { "setLineWidth", w_setLineWidth }, { "setLineStyle", w_setLineStyle }, { "setLine", w_setLine }, diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/opengl/wrap_Graphics.h index 17a5a0a24..74f862006 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/src/modules/graphics/opengl/wrap_Graphics.h @@ -71,8 +71,10 @@ namespace opengl int w_getFont(lua_State * L); int w_setBlendMode(lua_State * L); int w_setColorMode(lua_State * L); + int w_setDefaultImageFilter(lua_State * L); int w_getBlendMode(lua_State * L); int w_getColorMode(lua_State * L); + int w_getDefaultImageFilter(lua_State * L); int w_setLineWidth(lua_State * L); int w_setLineStyle(lua_State * L); int w_setLine(lua_State * L); diff --git a/src/modules/graphics/opengl/wrap_Image.cpp b/src/modules/graphics/opengl/wrap_Image.cpp index bc855fc32..ffddc7f7d 100644 --- a/src/modules/graphics/opengl/wrap_Image.cpp +++ b/src/modules/graphics/opengl/wrap_Image.cpp @@ -67,7 +67,7 @@ namespace opengl int w_Image_getFilter(lua_State * L) { - Image * t = luax_checkimage(L, 1); + Image * t = luax_checkimage(L, 1); Image::Filter f = t->getFilter(); Image::FilterMode min = f.min; Image::FilterMode mag = f.mag;