mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
@@ -1,4 +1,5 @@
|
||||
#include "Framebuffer.h"
|
||||
#include "Graphics.h"
|
||||
#include <common/Matrix.h>
|
||||
|
||||
#include <cstring> // For memcpy
|
||||
@@ -233,6 +234,22 @@ namespace opengl
|
||||
current = NULL;
|
||||
}
|
||||
|
||||
|
||||
void Framebuffer::clear(const Color& c)
|
||||
{
|
||||
GLuint previous = 0;
|
||||
if (current != NULL)
|
||||
previous = current->fbo;
|
||||
|
||||
strategy->bindFBO(fbo);
|
||||
glPushAttrib(GL_COLOR_BUFFER_BIT);
|
||||
glClearColor((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glPopAttrib();
|
||||
|
||||
strategy->bindFBO(previous);
|
||||
}
|
||||
|
||||
void Framebuffer::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const
|
||||
{
|
||||
static Matrix t;
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
struct Color; // forward declaration for clear
|
||||
|
||||
class Framebuffer : public Drawable, public Volatile
|
||||
{
|
||||
public:
|
||||
@@ -29,6 +31,8 @@ namespace opengl
|
||||
void startGrab();
|
||||
void stopGrab();
|
||||
|
||||
void clear(const Color& c);
|
||||
|
||||
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
love::image::ImageData * getImageData(love::image::Image * image);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "Graphics.h"
|
||||
#include "wrap_Framebuffer.h"
|
||||
|
||||
namespace love
|
||||
@@ -105,6 +106,40 @@ namespace opengl
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_Framebuffer_clear(lua_State * L)
|
||||
{
|
||||
Framebuffer * fbo = luax_checkfbo(L, 1);
|
||||
Color c;
|
||||
if (lua_isnoneornil(L, 2)) {
|
||||
c.r = 0;
|
||||
c.g = 0;
|
||||
c.b = 0;
|
||||
c.a = 0;
|
||||
} else if (lua_istable(L, 2)) {
|
||||
lua_pushinteger(L, 1);
|
||||
lua_gettable(L, 2);
|
||||
c.r = (unsigned char)luaL_checkint(L, -1);
|
||||
lua_pushinteger(L, 2);
|
||||
lua_gettable(L, 2);
|
||||
c.g = (unsigned char)luaL_checkint(L, -1);
|
||||
lua_pushinteger(L, 3);
|
||||
lua_gettable(L, 2);
|
||||
c.b = (unsigned char)luaL_checkint(L, -1);
|
||||
lua_pushinteger(L, 4);
|
||||
lua_gettable(L, 2);
|
||||
c.g = (unsigned char)luaL_optint(L, -1, 255);
|
||||
lua_pop(L, 4);
|
||||
} else {
|
||||
c.r = (unsigned char)luaL_checkint(L, 2);
|
||||
c.g = (unsigned char)luaL_checkint(L, 3);
|
||||
c.b = (unsigned char)luaL_checkint(L, 4);
|
||||
c.a = (unsigned char)luaL_optint(L, 5, 255);
|
||||
}
|
||||
fbo->clear(c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "renderTo", w_Framebuffer_renderTo },
|
||||
{ "getImageData", w_Framebuffer_getImageData },
|
||||
@@ -112,6 +147,7 @@ namespace opengl
|
||||
{ "getFilter", w_Framebuffer_getFilter },
|
||||
{ "setWrap", w_Framebuffer_setWrap },
|
||||
{ "getWrap", w_Framebuffer_getWrap },
|
||||
{ "clear", w_Framebuffer_clear },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace opengl
|
||||
int w_Framebuffer_getFilter(lua_State * L);
|
||||
int w_Framebuffer_setWrap(lua_State * L);
|
||||
int w_Framebuffer_getWrap(lua_State * L);
|
||||
int w_Framebuffer_clear(lua_State * L);
|
||||
int luaopen_framebuffer(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
|
||||
Reference in New Issue
Block a user