|
@@ -1,27 +1,31 @@
|
|
-/**
|
|
|
|
-* Copyright (c) 2006-2009 LOVE Development Team
|
|
|
|
-*
|
|
|
|
-* This software is provided 'as-is', without any express or implied
|
|
|
|
-* warranty. In no event will the authors be held liable for any damages
|
|
|
|
-* arising from the use of this software.
|
|
|
|
-*
|
|
|
|
-* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
-* including commercial applications, and to alter it and redistribute it
|
|
|
|
-* freely, subject to the following restrictions:
|
|
|
|
-*
|
|
|
|
-* 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
-* claim that you wrote the original software. If you use this software
|
|
|
|
-* in a product, an acknowledgment in the product documentation would be
|
|
|
|
-* appreciated but is not required.
|
|
|
|
-* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
-* misrepresented as being the original software.
|
|
|
|
-* 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
|
|
+/**
|
|
|
|
+* Copyright (c) 2006-2009 LOVE Development Team
|
|
|
|
+*
|
|
|
|
+* This software is provided 'as-is', without any express or implied
|
|
|
|
+* warranty. In no event will the authors be held liable for any damages
|
|
|
|
+* arising from the use of this software.
|
|
|
|
+*
|
|
|
|
+* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
+* including commercial applications, and to alter it and redistribute it
|
|
|
|
+* freely, subject to the following restrictions:
|
|
|
|
+*
|
|
|
|
+* 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
+* claim that you wrote the original software. If you use this software
|
|
|
|
+* in a product, an acknowledgment in the product documentation would be
|
|
|
|
+* appreciated but is not required.
|
|
|
|
+* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
+* misrepresented as being the original software.
|
|
|
|
+* 3. This notice may not be removed or altered from any source distribution.
|
|
**/
|
|
**/
|
|
|
|
|
|
#include "Graphics.h"
|
|
#include "Graphics.h"
|
|
|
|
|
|
// LOVE
|
|
// LOVE
|
|
#include <common/config.h>
|
|
#include <common/config.h>
|
|
|
|
+#include <image/devil/Image.h>
|
|
|
|
+
|
|
|
|
+// IL
|
|
|
|
+#include <IL/ilu.h>
|
|
|
|
|
|
namespace love
|
|
namespace love
|
|
{
|
|
{
|
|
@@ -33,9 +37,9 @@ namespace opengl
|
|
Graphics::Graphics()
|
|
Graphics::Graphics()
|
|
: currentFont(0)
|
|
: currentFont(0)
|
|
{
|
|
{
|
|
- // Indicates that there is no screen
|
|
|
|
- // created yet.
|
|
|
|
- currentMode.width = 0;
|
|
|
|
|
|
+ // Indicates that there is no screen
|
|
|
|
+ // created yet.
|
|
|
|
+ currentMode.width = 0;
|
|
currentMode.height = 0;
|
|
currentMode.height = 0;
|
|
|
|
|
|
// Windows should be centered.
|
|
// Windows should be centered.
|
|
@@ -47,7 +51,7 @@ namespace opengl
|
|
|
|
|
|
Graphics::~Graphics()
|
|
Graphics::~Graphics()
|
|
{
|
|
{
|
|
- if(currentFont != 0)
|
|
|
|
|
|
+ if(currentFont != 0)
|
|
currentFont->release();
|
|
currentFont->release();
|
|
|
|
|
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
|
@@ -66,8 +70,8 @@ namespace opengl
|
|
int bpp = SDL_VideoModeOK(width, height, 32, sdlflags);
|
|
int bpp = SDL_VideoModeOK(width, height, 32, sdlflags);
|
|
|
|
|
|
return (bpp >= 16);
|
|
return (bpp >= 16);
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
DisplayState Graphics::saveState()
|
|
DisplayState Graphics::saveState()
|
|
{
|
|
{
|
|
DisplayState s;
|
|
DisplayState s;
|
|
@@ -117,7 +121,7 @@ namespace opengl
|
|
if (s.scissor)
|
|
if (s.scissor)
|
|
glGetIntegerv(GL_SCISSOR_BOX, s.scissorBox);
|
|
glGetIntegerv(GL_SCISSOR_BOX, s.scissorBox);
|
|
return s;
|
|
return s;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
void Graphics::restoreState(const DisplayState & s)
|
|
void Graphics::restoreState(const DisplayState & s)
|
|
{
|
|
{
|
|
@@ -135,8 +139,8 @@ namespace opengl
|
|
setScissor(s.scissorBox[0], s.scissorBox[1], s.scissorBox[2], s.scissorBox[3]);
|
|
setScissor(s.scissorBox[0], s.scissorBox[1], s.scissorBox[2], s.scissorBox[3]);
|
|
else
|
|
else
|
|
setScissor();
|
|
setScissor();
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
bool Graphics::setMode(int width, int height, bool fullscreen, bool vsync, int fsaa)
|
|
bool Graphics::setMode(int width, int height, bool fullscreen, bool vsync, int fsaa)
|
|
{
|
|
{
|
|
// This operation destroys the OpenGL context, so
|
|
// This operation destroys the OpenGL context, so
|
|
@@ -257,8 +261,8 @@ namespace opengl
|
|
restoreState(tempState);
|
|
restoreState(tempState);
|
|
|
|
|
|
return true;
|
|
return true;
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
bool Graphics::toggleFullscreen()
|
|
bool Graphics::toggleFullscreen()
|
|
{
|
|
{
|
|
// Try to do the change.
|
|
// Try to do the change.
|
|
@@ -271,8 +275,8 @@ namespace opengl
|
|
currentMode.fullscreen = !currentMode.fullscreen;
|
|
currentMode.fullscreen = !currentMode.fullscreen;
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
void Graphics::reset()
|
|
void Graphics::reset()
|
|
{
|
|
{
|
|
DisplayState s;
|
|
DisplayState s;
|
|
@@ -288,21 +292,21 @@ namespace opengl
|
|
void Graphics::present()
|
|
void Graphics::present()
|
|
{
|
|
{
|
|
SDL_GL_SwapBuffers();
|
|
SDL_GL_SwapBuffers();
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
void Graphics::setCaption(const char * caption)
|
|
void Graphics::setCaption(const char * caption)
|
|
{
|
|
{
|
|
SDL_WM_SetCaption(caption, 0);
|
|
SDL_WM_SetCaption(caption, 0);
|
|
}
|
|
}
|
|
|
|
|
|
- int Graphics::getCaption(lua_State * L)
|
|
|
|
- {
|
|
|
|
|
|
+ int Graphics::getCaption(lua_State * L)
|
|
|
|
+ {
|
|
char * title = 0;
|
|
char * title = 0;
|
|
- SDL_WM_GetCaption(&title, 0);
|
|
|
|
- lua_pushstring(L, title);
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ SDL_WM_GetCaption(&title, 0);
|
|
|
|
+ lua_pushstring(L, title);
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
int Graphics::getWidth()
|
|
int Graphics::getWidth()
|
|
{
|
|
{
|
|
return currentMode.width;
|
|
return currentMode.width;
|
|
@@ -379,19 +383,24 @@ namespace opengl
|
|
lua_pushnumber(L, scissor[3]);
|
|
lua_pushnumber(L, scissor[3]);
|
|
|
|
|
|
return 4;
|
|
return 4;
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
Image * Graphics::newImage(love::image::ImageData * data)
|
|
Image * Graphics::newImage(love::image::ImageData * data)
|
|
{
|
|
{
|
|
// Create the image.
|
|
// Create the image.
|
|
Image * image = new Image(data);
|
|
Image * image = new Image(data);
|
|
-
|
|
|
|
- if(!image->load())
|
|
|
|
- {
|
|
|
|
|
|
+ bool success;
|
|
|
|
+ try {
|
|
|
|
+ success = image->load();
|
|
|
|
+ } catch (love::Exception & e) {
|
|
|
|
+ image->release();
|
|
|
|
+ throw love::Exception(e.what());
|
|
|
|
+ }
|
|
|
|
+ if (!success) {
|
|
image->release();
|
|
image->release();
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
return image;
|
|
return image;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -403,10 +412,10 @@ namespace opengl
|
|
v.w = w;
|
|
v.w = w;
|
|
v.h = h;
|
|
v.h = h;
|
|
return new Quad(v, sw, sh);
|
|
return new Quad(v, sw, sh);
|
|
- }
|
|
|
|
-
|
|
|
|
- Font * Graphics::newFont(Data * data, int size)
|
|
|
|
- {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Font * Graphics::newFont(Data * data, int size)
|
|
|
|
+ {
|
|
Font * font = new TrueTypeFont(data, size);
|
|
Font * font = new TrueTypeFont(data, size);
|
|
|
|
|
|
// Load it and check for errors.
|
|
// Load it and check for errors.
|
|
@@ -416,11 +425,11 @@ namespace opengl
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- return font;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Font * Graphics::newImageFont(Image * image, const char * glyphs, float spacing)
|
|
|
|
- {
|
|
|
|
|
|
+ return font;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Font * Graphics::newImageFont(Image * image, const char * glyphs, float spacing)
|
|
|
|
+ {
|
|
Font * font = new ImageFont(image, std::string(glyphs));
|
|
Font * font = new ImageFont(image, std::string(glyphs));
|
|
|
|
|
|
// Load it and check for errors.
|
|
// Load it and check for errors.
|
|
@@ -430,19 +439,19 @@ namespace opengl
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- return font;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- SpriteBatch * Graphics::newSpriteBatch(Image * image, int size, int usage)
|
|
|
|
- {
|
|
|
|
- return new SpriteBatch(image, size, usage);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- ParticleSystem * Graphics::newParticleSystem(Image * image, int size)
|
|
|
|
- {
|
|
|
|
- return new ParticleSystem(image, size);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ return font;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SpriteBatch * Graphics::newSpriteBatch(Image * image, int size, int usage)
|
|
|
|
+ {
|
|
|
|
+ return new SpriteBatch(image, size, usage);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ParticleSystem * Graphics::newParticleSystem(Image * image, int size)
|
|
|
|
+ {
|
|
|
|
+ return new ParticleSystem(image, size);
|
|
|
|
+ }
|
|
|
|
+
|
|
void Graphics::setColor(Color c)
|
|
void Graphics::setColor(Color c)
|
|
{
|
|
{
|
|
glColor4ubv(&c.r);
|
|
glColor4ubv(&c.r);
|
|
@@ -479,33 +488,33 @@ namespace opengl
|
|
t.a = (unsigned char)(255.0f*c[3]);
|
|
t.a = (unsigned char)(255.0f*c[3]);
|
|
|
|
|
|
return t;
|
|
return t;
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
void Graphics::setFont( Font * font )
|
|
void Graphics::setFont( Font * font )
|
|
{
|
|
{
|
|
- if(currentFont != 0)
|
|
|
|
- currentFont->release();
|
|
|
|
|
|
+ if(currentFont != 0)
|
|
|
|
+ currentFont->release();
|
|
|
|
|
|
currentFont = font;
|
|
currentFont = font;
|
|
|
|
|
|
if(font != 0)
|
|
if(font != 0)
|
|
currentFont->retain();
|
|
currentFont->retain();
|
|
- }
|
|
|
|
-
|
|
|
|
- void Graphics::setFont( Data * data, int size )
|
|
|
|
- {
|
|
|
|
- if(currentFont != 0)
|
|
|
|
- currentFont->release();
|
|
|
|
-
|
|
|
|
- currentFont = new TrueTypeFont(data, size);
|
|
|
|
- currentFont->load();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Font * Graphics::getFont()
|
|
|
|
- {
|
|
|
|
- return currentFont;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void Graphics::setFont( Data * data, int size )
|
|
|
|
+ {
|
|
|
|
+ if(currentFont != 0)
|
|
|
|
+ currentFont->release();
|
|
|
|
+
|
|
|
|
+ currentFont = new TrueTypeFont(data, size);
|
|
|
|
+ currentFont->load();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Font * Graphics::getFont()
|
|
|
|
+ {
|
|
|
|
+ return currentFont;
|
|
|
|
+ }
|
|
|
|
+
|
|
void Graphics::setBlendMode( int mode )
|
|
void Graphics::setBlendMode( int mode )
|
|
{
|
|
{
|
|
if(mode == BLEND_ADDITIVE)
|
|
if(mode == BLEND_ADDITIVE)
|
|
@@ -659,8 +668,8 @@ namespace opengl
|
|
GLint max;
|
|
GLint max;
|
|
glGetIntegerv(GL_POINT_SIZE_MAX, &max);
|
|
glGetIntegerv(GL_POINT_SIZE_MAX, &max);
|
|
return (int)max;
|
|
return (int)max;
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
void Graphics::print( const char * str, float x, float y )
|
|
void Graphics::print( const char * str, float x, float y )
|
|
{
|
|
{
|
|
if(currentFont != 0)
|
|
if(currentFont != 0)
|
|
@@ -814,8 +823,8 @@ namespace opengl
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Primitives
|
|
* Primitives
|
|
**/
|
|
**/
|
|
@@ -1168,8 +1177,32 @@ namespace opengl
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- bool Graphics::screenshot(love::filesystem::File * file)
|
|
|
|
|
|
+ love::image::ImageData * Graphics::newScreenshot(lua_State * L)
|
|
{
|
|
{
|
|
|
|
+
|
|
|
|
+ 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.
|
|
// TODO: update this.
|
|
/*
|
|
/*
|
|
int w = getWidth();
|
|
int w = getWidth();
|
|
@@ -1233,31 +1266,31 @@ namespace opengl
|
|
void Graphics::translate(float x, float y)
|
|
void Graphics::translate(float x, float y)
|
|
{
|
|
{
|
|
glTranslatef(x, y, 0);
|
|
glTranslatef(x, y, 0);
|
|
- }
|
|
|
|
-
|
|
|
|
- void Graphics::drawTest(Image * image, float x, float y, float a, float sx, float sy, float ox, float oy)
|
|
|
|
- {
|
|
|
|
- image->bind();
|
|
|
|
-
|
|
|
|
- // Buffer for transforming the image.
|
|
|
|
- vertex buf[4];
|
|
|
|
-
|
|
|
|
- Matrix t;
|
|
|
|
- t.translate(x, y);
|
|
|
|
- t.rotate(a);
|
|
|
|
- t.scale(sx, sy);
|
|
|
|
- t.translate(ox, oy);
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void Graphics::drawTest(Image * image, float x, float y, float a, float sx, float sy, float ox, float oy)
|
|
|
|
+ {
|
|
|
|
+ image->bind();
|
|
|
|
+
|
|
|
|
+ // Buffer for transforming the image.
|
|
|
|
+ vertex buf[4];
|
|
|
|
+
|
|
|
|
+ Matrix t;
|
|
|
|
+ t.translate(x, y);
|
|
|
|
+ t.rotate(a);
|
|
|
|
+ t.scale(sx, sy);
|
|
|
|
+ t.translate(ox, oy);
|
|
t.transform(buf, image->getVertices(), 4);
|
|
t.transform(buf, image->getVertices(), 4);
|
|
|
|
|
|
const vertex * vertices = image->getVertices();
|
|
const vertex * vertices = image->getVertices();
|
|
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
|
|
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&buf[0].x);
|
|
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&buf[0].x);
|
|
- glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].s);
|
|
|
|
- glDrawArrays(GL_QUADS, 0, 4);
|
|
|
|
|
|
+ glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].s);
|
|
|
|
+ glDrawArrays(GL_QUADS, 0, 4);
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
- glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
|
|
+ glDisableClientState(GL_VERTEX_ARRAY);
|
|
}
|
|
}
|
|
|
|
|
|
} // opengl
|
|
} // opengl
|