Modules now reside in Lua and are treated (almost) like normal objects.

Also added a way of getting a pointer to abstract module instances internally.
This commit is contained in:
rude
2009-09-02 21:18:13 +02:00
parent bea504af2b
commit 623e701549
22 changed files with 247 additions and 176 deletions
+2 -61
View File
@@ -22,10 +22,6 @@
// LOVE
#include <common/config.h>
#include <image/devil/Image.h>
// IL
#include <IL/ilu.h>
namespace love
{
@@ -1177,70 +1173,15 @@ namespace opengl
return 0;
}
love::image::ImageData * Graphics::newScreenshot(lua_State * L)
love::image::ImageData * Graphics::newScreenshot(love::image::Image * image)
{
int w = getWidth();
int h = getHeight();
love::image::devil::Image * i = new love::image::devil::Image();
love::image::ImageData * img = i->newImageData(w, h);
GLubyte * pixels = new GLubyte[4*w*h];
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
try {
img = i->newImageData(w, h, pixels);
} catch (Exception & e) {
luaL_error(L, e.what());
}
// the screenshot is upside down, let's fix this
iluFlipImage();
delete [] pixels;
return img;
// TODO: update this.
/*
int w = getWidth();
int h = getHeight();
// Declare some storage.
GLubyte * pixels = new GLubyte[3*w*h];
GLubyte * screenshot = new GLubyte[3*w*h];
ILuint image;
// Read the pixels on the screen.
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
ilGenImages(1, &image);
ilBindImage(image);
ilTexImage(w, h, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, (ILvoid*)pixels);
delete [] pixels;
// Create the image.
ilSaveL(IL_BMP, screenshot, 3*w*h);
bool success = true;
if(file->open())
{
if(!file->write((const char *)screenshot, 3*w*h))
success = false;
file->close();
}
else
success = false;
delete [] screenshot;
ilDeleteImages(1, &image);
*/
return false;
return image->newImageData(w, h, (void*)pixels);
}
void Graphics::push()
+2 -1
View File
@@ -33,6 +33,7 @@
// LOVE
#include <graphics/Graphics.h>
#include <image/Image.h>
#include <image/ImageData.h>
#include "Image.h"
@@ -518,7 +519,7 @@ namespace opengl
* Creates a screenshot of the view and saves it to the default folder.
* @param file The file to write the screenshot to.
**/
love::image::ImageData * newScreenshot(lua_State * L);
love::image::ImageData * newScreenshot(love::image::Image * image);
void push();
void pop();
+12 -4
View File
@@ -479,7 +479,8 @@ namespace opengl
int w_newScreenshot(lua_State * L)
{
love::image::ImageData * i = instance->newScreenshot(L);
love::image::Image * image = luax_getmodule<love::image::Image>(L, "image", MODULE_IMAGE_T);
love::image::ImageData * i = instance->newScreenshot(image);
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)i);
return 1;
}
@@ -795,7 +796,7 @@ namespace opengl
};
// List of constants.
static const LuaConstant constants[] = {
static const Constant constants[] = {
{ "align_left", Graphics::ALIGN_LEFT },
{ "align_right", Graphics::ALIGN_RIGHT },
@@ -860,8 +861,15 @@ namespace opengl
}
}
luax_register_gc(L, instance);
luax_register_module(L, functions, types, constants, "graphics");
WrappedModule w;
w.module = instance;
w.name = "graphics";
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
w.constants = constants;
luax_register_module(L, w);
# include <scripts/graphics.lua.h>