mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Add pixel effects (love-glsl)
This commit is contained in:
@@ -48,6 +48,9 @@ namespace opengl
|
||||
void unloadVolatile();
|
||||
|
||||
private:
|
||||
friend class PixelEffect;
|
||||
GLuint getTextureName() const { return img; }
|
||||
|
||||
GLsizei width;
|
||||
GLsizei height;
|
||||
GLuint fbo;
|
||||
|
||||
@@ -325,6 +325,7 @@ namespace opengl
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glLoadIdentity();
|
||||
PixelEffect::detach();
|
||||
}
|
||||
|
||||
void Graphics::present()
|
||||
@@ -541,6 +542,19 @@ namespace opengl
|
||||
return new Framebuffer(width, height);
|
||||
}
|
||||
|
||||
PixelEffect * Graphics::newPixelEffect(const std::string& code)
|
||||
{
|
||||
PixelEffect * effect = NULL;
|
||||
try {
|
||||
effect = new PixelEffect(code);
|
||||
} catch (love::Exception& e) {
|
||||
if (effect)
|
||||
delete effect;
|
||||
throw(e);
|
||||
}
|
||||
return effect;
|
||||
}
|
||||
|
||||
void Graphics::setColor(const Color& c)
|
||||
{
|
||||
glColor4ubv(&c.r);
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "SpriteBatch.h"
|
||||
#include "ParticleSystem.h"
|
||||
#include "Framebuffer.h"
|
||||
#include "PixelEffect.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -288,6 +289,8 @@ namespace opengl
|
||||
|
||||
Framebuffer * newFramebuffer(int width, int height);
|
||||
|
||||
PixelEffect * newPixelEffect(const std::string& code);
|
||||
|
||||
/**
|
||||
* Sets the foreground color.
|
||||
* @param c The new foreground color.
|
||||
|
||||
@@ -147,6 +147,9 @@ namespace opengl
|
||||
|
||||
void drawv(const Matrix & t, const vertex * v) const;
|
||||
|
||||
friend class PixelEffect;
|
||||
GLuint getTextureName() const { return texture; }
|
||||
|
||||
}; // Image
|
||||
|
||||
} // opengl
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <font/Rasterizer.h>
|
||||
|
||||
#include <scripts/graphics.lua.h>
|
||||
#include "GLInfo.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -383,6 +384,33 @@ namespace opengl
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newPixelEffect(lua_State * L)
|
||||
{
|
||||
if (!PixelEffect::isSupported())
|
||||
return luaL_error(L, "Sorry, your graphics card does not support pixel effects.");
|
||||
|
||||
try {
|
||||
luaL_checkstring(L, 1);
|
||||
|
||||
luax_getfunction(L, "graphics", "_effectCodeToGLSL");
|
||||
lua_pushvalue(L, 1);
|
||||
lua_pcall(L, 1, 1, 0);
|
||||
|
||||
const char* code = lua_tostring(L, -1);
|
||||
PixelEffect * effect = instance->newPixelEffect(code);
|
||||
luax_newtype(L, "PixelEffect", GRAPHICS_PIXELEFFECT_T, (void*)effect);
|
||||
} catch (love::Exception& e) {
|
||||
// memory is freed in Graphics::newPixelEffect
|
||||
luax_getfunction(L, "graphics", "_transformGLSLErrorMessages");
|
||||
lua_pushstring(L, e.what());
|
||||
lua_pcall(L, 1,1, 0);
|
||||
const char* err = lua_tostring(L, -1);
|
||||
return luaL_error(L, err);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_setColor(lua_State * L)
|
||||
{
|
||||
Color c;
|
||||
@@ -702,6 +730,24 @@ namespace opengl
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_setPixelEffect(lua_State * L)
|
||||
{
|
||||
if (lua_isnoneornil(L,1)) {
|
||||
PixelEffect::detach();
|
||||
return 0;
|
||||
}
|
||||
|
||||
PixelEffect * effect = luax_checkpixeleffect(L, 1);
|
||||
effect->attach();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_hasPixelEffects(lua_State * L)
|
||||
{
|
||||
lua_pushboolean(L, PixelEffect::isSupported());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws an Image at the specified coordinates, with rotation and
|
||||
* scaling along both axes.
|
||||
@@ -1075,6 +1121,7 @@ namespace opengl
|
||||
{ "newSpriteBatch", w_newSpriteBatch },
|
||||
{ "newParticleSystem", w_newParticleSystem },
|
||||
{ "newFramebuffer", w_newFramebuffer },
|
||||
{ "newPixelEffect", w_newPixelEffect },
|
||||
|
||||
{ "setColor", w_setColor },
|
||||
{ "getColor", w_getColor },
|
||||
@@ -1102,6 +1149,9 @@ namespace opengl
|
||||
{ "newScreenshot", w_newScreenshot },
|
||||
{ "setRenderTarget", w_setRenderTarget },
|
||||
|
||||
{ "setPixelEffect", w_setPixelEffect },
|
||||
{ "hasPixelEffects", w_hasPixelEffects },
|
||||
|
||||
{ "draw", w_draw },
|
||||
{ "drawq", w_drawq },
|
||||
{ "drawTest", w_drawTest },
|
||||
@@ -1158,6 +1208,7 @@ namespace opengl
|
||||
luaopen_spritebatch,
|
||||
luaopen_particlesystem,
|
||||
luaopen_framebuffer,
|
||||
luaopen_pixeleffect,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "wrap_SpriteBatch.h"
|
||||
#include "wrap_ParticleSystem.h"
|
||||
#include "wrap_Framebuffer.h"
|
||||
#include "wrap_PixelEffect.h"
|
||||
#include "Graphics.h"
|
||||
|
||||
namespace love
|
||||
@@ -61,6 +62,7 @@ namespace opengl
|
||||
int w_newSpriteBatch(lua_State * L);
|
||||
int w_newParticleSystem(lua_State * L);
|
||||
int w_newFramebuffer(lua_State * L); // comments in function
|
||||
int w_newPixelEffect(lua_State * L);
|
||||
int w_setColor(lua_State * L);
|
||||
int w_getColor(lua_State * L);
|
||||
int w_setBackgroundColor(lua_State * L);
|
||||
@@ -86,6 +88,9 @@ namespace opengl
|
||||
int w_getMaxPointSize(lua_State * L);
|
||||
int w_newScreenshot(lua_State * L);
|
||||
int w_setRenderTarget(lua_State * L);
|
||||
int w_setPixelEffect(lua_State * L);
|
||||
int w_hasPixelEffects(lua_State * L);
|
||||
int w_getGLSLVersion(lua_State * L);
|
||||
int w_draw(lua_State * L);
|
||||
int w_drawq(lua_State * L);
|
||||
int w_drawTest(lua_State * L);
|
||||
|
||||
Reference in New Issue
Block a user