mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Initial Mercurial commit.
This commit is contained in:
@@ -0,0 +1,235 @@
|
||||
/**
|
||||
* 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 "Animation.h"
|
||||
|
||||
// STD
|
||||
#include <cmath>
|
||||
|
||||
// LOVE
|
||||
#include <common/constants.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Animation::Animation(Image * image)
|
||||
: image(image), mode(1), current(0), playing(true),
|
||||
timeBuffer(0), direction(1), speed(1.0f)
|
||||
{
|
||||
image->retain();
|
||||
}
|
||||
|
||||
Animation::Animation(Image * image, float fw, float fh, float delay, int num)
|
||||
: image(image), mode(1), current(0), playing(true), timeBuffer(0), direction(1), speed(1.0f)
|
||||
{
|
||||
|
||||
image->retain();
|
||||
|
||||
// Generate frames.
|
||||
int w = (int)(image->getWidth()/fw);
|
||||
int h = (int)(image->getHeight()/fh);
|
||||
|
||||
int real_num = (num == 0) ? (w * h) : num;
|
||||
if(real_num > (w * h)) real_num = (w * h);
|
||||
|
||||
for(int i = 0;i<real_num;i++)
|
||||
{
|
||||
int x = (int)((i % w)*fw);
|
||||
int y = (int)((i/w)*fh);
|
||||
|
||||
addFrame((float)x, (float)y, fw, fh, delay);
|
||||
}
|
||||
}
|
||||
|
||||
Animation::~Animation()
|
||||
{
|
||||
if(image != 0)
|
||||
image->release();
|
||||
}
|
||||
|
||||
void Animation::addFrame(float x, float y, float w, float h, float delay)
|
||||
{
|
||||
// Add delay.
|
||||
delays.push_back(delay);
|
||||
|
||||
// Add frame.
|
||||
AnimationFrame f;
|
||||
f.x = x;
|
||||
f.y = y;
|
||||
f.w = w;
|
||||
f.h = h;
|
||||
f.postDelay = (int)delays.size() - 1;
|
||||
|
||||
frames.push_back(f);
|
||||
|
||||
if(frames.size() > 1)
|
||||
{
|
||||
frames.back().preDelay = frames[frames.size() - 2].postDelay;
|
||||
|
||||
// Update delay of first frame.
|
||||
frames.front().preDelay = frames.back().postDelay;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Animation::setMode(int mode)
|
||||
{
|
||||
this->mode = mode;
|
||||
}
|
||||
|
||||
void Animation::play()
|
||||
{
|
||||
playing = true;
|
||||
}
|
||||
|
||||
void Animation::stop()
|
||||
{
|
||||
playing = false;
|
||||
}
|
||||
|
||||
void Animation::reset()
|
||||
{
|
||||
current = 0;
|
||||
timeBuffer = 0;
|
||||
}
|
||||
|
||||
void Animation::seek(int frame)
|
||||
{
|
||||
if(frame >= 0 && frame < (int)frames.size())
|
||||
current = frame;
|
||||
}
|
||||
|
||||
int Animation::getCurrentFrame() const
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
int Animation::getSize() const
|
||||
{
|
||||
return (int)frames.size();
|
||||
}
|
||||
|
||||
void Animation::setDelay(int frame, float delay)
|
||||
{
|
||||
if(frame >= 0 && frame < (int)frames.size())
|
||||
delays[frames[0].postDelay] = delay;
|
||||
}
|
||||
|
||||
void Animation::setSpeed(float speed)
|
||||
{
|
||||
this->speed = speed;
|
||||
}
|
||||
|
||||
float Animation::getSpeed() const
|
||||
{
|
||||
return speed;
|
||||
}
|
||||
|
||||
void Animation::update(float dt)
|
||||
{
|
||||
if(!playing)
|
||||
return;
|
||||
|
||||
if(frames.size() <= 0)
|
||||
return;
|
||||
|
||||
timeBuffer += (dt * speed);
|
||||
|
||||
int next;
|
||||
float d;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case ANIMATION_LOOP:
|
||||
next = current;
|
||||
while(timeBuffer >= delays[frames[current].postDelay])
|
||||
{
|
||||
timeBuffer -= delays[frames[current].postDelay];
|
||||
if(++next >= (int)frames.size())
|
||||
next = 0;
|
||||
}
|
||||
current = next;
|
||||
break;
|
||||
case ANIMATION_PLAY_ONCE:
|
||||
next = current;
|
||||
while(timeBuffer >= delays[frames[current].postDelay])
|
||||
{
|
||||
timeBuffer -= delays[frames[current].postDelay];
|
||||
if(++next >= (int)frames.size())
|
||||
{
|
||||
next--;
|
||||
playing = false;
|
||||
timeBuffer = 0;
|
||||
}
|
||||
}
|
||||
current = next;
|
||||
break;
|
||||
case ANIMATION_BOUNCE:
|
||||
next = current;
|
||||
d = (direction == 1) ? delays[frames[next].postDelay] : delays[frames[next].preDelay];
|
||||
|
||||
while(timeBuffer >= d)
|
||||
{
|
||||
timeBuffer -= d;
|
||||
next += direction;
|
||||
if(next < 0 || next >= (int)frames.size())
|
||||
{
|
||||
direction *= -1;
|
||||
next += direction;
|
||||
}
|
||||
d = (direction == 1) ? delays[frames[next].postDelay] : delays[frames[next].preDelay];
|
||||
}
|
||||
current = next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Animation::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const
|
||||
{
|
||||
if(frames.size() <= 0)
|
||||
return;
|
||||
|
||||
const AnimationFrame & f = frames[current];
|
||||
image->draws(x, y, angle, sx, sy, ox, oy, f.x, f.y, f.w, f.h);
|
||||
}
|
||||
|
||||
float Animation::getWidth() const
|
||||
{
|
||||
if(frames.size() <= 0)
|
||||
return 0;
|
||||
|
||||
return frames[current].w;
|
||||
}
|
||||
|
||||
float Animation::getHeight() const
|
||||
{
|
||||
if(frames.size() <= 0)
|
||||
return 0;
|
||||
|
||||
return frames[current].h;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_OPENGL_ANIMATION_H
|
||||
#define LOVE_OPENGL_ANIMATION_H
|
||||
|
||||
// LOVE
|
||||
#include "../Drawable.h"
|
||||
#include "Image.h"
|
||||
|
||||
// STD
|
||||
#include <vector>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// Represents a single frame.
|
||||
struct AnimationFrame
|
||||
{
|
||||
float x, y; // Top left corner of the frame.
|
||||
float w, h; // Size of the frame.
|
||||
int preDelay; // Delay to previous frame.
|
||||
int postDelay; // Delay to next frame.
|
||||
};
|
||||
|
||||
class Animation : public Drawable
|
||||
{
|
||||
private:
|
||||
|
||||
// The source of the animation.
|
||||
Image * image;
|
||||
|
||||
// Delays between frames.
|
||||
// delays[0] is the delay between frames[0] and frames[1].
|
||||
std::vector<float> delays;
|
||||
|
||||
// Holds all the frames.
|
||||
std::vector<AnimationFrame> frames;
|
||||
|
||||
// Animation mode.
|
||||
int mode;
|
||||
|
||||
// The current frame.
|
||||
int current;
|
||||
|
||||
// True if playing, false otherwise.
|
||||
bool playing;
|
||||
|
||||
// "Left over"-time.
|
||||
float timeBuffer;
|
||||
|
||||
// Used for bounce mode.
|
||||
int direction;
|
||||
|
||||
// Overall speed. (1 = normal).
|
||||
float speed;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates an Animation with no frames.
|
||||
* @param image The image to use as the source.
|
||||
**/
|
||||
Animation(Image * image);
|
||||
|
||||
/**
|
||||
* Creates an Animation with frames from top-left to bottom right.
|
||||
* @param image The image to use as the source.
|
||||
* @param fw The width of each frame.
|
||||
* @param fh The height of each frame.
|
||||
* @param delay The delay after each frame.
|
||||
* @param num The number of frames. (0 = all)
|
||||
**/
|
||||
Animation(Image * image, float fw, float fh, float delay, int num = 0);
|
||||
|
||||
virtual ~Animation();
|
||||
|
||||
/**
|
||||
* Adds a single frame.
|
||||
* @param x The top-left corner of the frame.
|
||||
* @param y The top-right corner of the frame.
|
||||
* @param w The width of the frame.
|
||||
* @param h The height of the frame.
|
||||
* @param delay The delay after the frame.
|
||||
**/
|
||||
void addFrame(float x, float y, float w, float h, float delay);
|
||||
|
||||
/**
|
||||
* Sets the current animation mode, and reset.
|
||||
**/
|
||||
void setMode(int mode);
|
||||
|
||||
/**
|
||||
* Causes the Animation to start playing.
|
||||
**/
|
||||
void play();
|
||||
|
||||
/**
|
||||
* Causes the Animation to stop.
|
||||
**/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* Resets the Animation.
|
||||
**/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Resets timebuffers, and sets the current frame directly.
|
||||
**/
|
||||
void seek(int frame);
|
||||
|
||||
/**
|
||||
* Gets the current frame.
|
||||
**/
|
||||
int getCurrentFrame() const;
|
||||
|
||||
/**
|
||||
* Gets amount of frames.
|
||||
**/
|
||||
int getSize() const;
|
||||
|
||||
/**
|
||||
* Sets the delay after a frame.
|
||||
**/
|
||||
void setDelay(int frame, float delay);
|
||||
|
||||
/**
|
||||
* Sets the overall animation speed.
|
||||
**/
|
||||
void setSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Gets the overall animation speed.
|
||||
**/
|
||||
float getSpeed() const;
|
||||
|
||||
void update(float dt);
|
||||
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
|
||||
float getWidth() const;
|
||||
|
||||
float getHeight() const;
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_OPENGL_ANIMATION_H
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* 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 "Color.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Color::Color()
|
||||
: red(255), green(255), blue(255), alpha(255)
|
||||
{
|
||||
}
|
||||
|
||||
Color::Color(int r, int g, int b, int a)
|
||||
: red(r), green(g), blue(b), alpha(a)
|
||||
{
|
||||
}
|
||||
|
||||
Color::~Color()
|
||||
{
|
||||
}
|
||||
|
||||
void Color::setRed(int red)
|
||||
{
|
||||
this->red = red;
|
||||
}
|
||||
|
||||
void Color::setGreen(int green)
|
||||
{
|
||||
this->green = green;
|
||||
}
|
||||
|
||||
void Color::setBlue(int blue)
|
||||
{
|
||||
this->blue = blue;
|
||||
}
|
||||
|
||||
void Color::setAlpha(int alpha)
|
||||
{
|
||||
this->alpha = alpha;
|
||||
}
|
||||
|
||||
int Color::getRed() const
|
||||
{
|
||||
return red;
|
||||
}
|
||||
|
||||
int Color::getGreen() const
|
||||
{
|
||||
return green;
|
||||
}
|
||||
|
||||
int Color::getBlue() const
|
||||
{
|
||||
return blue;
|
||||
}
|
||||
|
||||
int Color::getAlpha() const
|
||||
{
|
||||
return alpha;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_COLOR_H
|
||||
#define LOVE_GRAPHICS_OPENGL_COLOR_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* @author Michael Enger
|
||||
**/
|
||||
class Color : public Object
|
||||
{
|
||||
protected:
|
||||
|
||||
// Color components. (0-255)
|
||||
int red, green, blue, alpha;
|
||||
|
||||
public:
|
||||
|
||||
Color();
|
||||
|
||||
/**
|
||||
* Creates a new color with the specified component values.
|
||||
* Values must be unsigned bytes. (0-255).
|
||||
**/
|
||||
Color(int r, int g, int b, int a);
|
||||
|
||||
virtual ~Color();
|
||||
|
||||
/**
|
||||
* Sets the amount of red in the color.
|
||||
**/
|
||||
void setRed(int red);
|
||||
|
||||
/**
|
||||
* Sets the amount of green in the color.
|
||||
**/
|
||||
void setGreen(int green);
|
||||
|
||||
/**
|
||||
* Sets the amount of blue in the color.
|
||||
**/
|
||||
void setBlue(int blue);
|
||||
|
||||
/**
|
||||
* Sets the amount of alpha.
|
||||
**/
|
||||
void setAlpha(int alpha);
|
||||
|
||||
/**
|
||||
* Returns the amount of red in the color.
|
||||
**/
|
||||
int getRed() const;
|
||||
|
||||
/**
|
||||
* Returns the amount of green in the color.
|
||||
**/
|
||||
int getGreen() const;
|
||||
|
||||
/**
|
||||
* Returns the amount of blue in the color.
|
||||
**/
|
||||
int getBlue() const;
|
||||
|
||||
/**
|
||||
* Returns the amount of alpha.
|
||||
**/
|
||||
int getAlpha() const;
|
||||
|
||||
}; // Color
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_COLOR_H
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* 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 "Font.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Font::Font(int size)
|
||||
: size(size), lineHeight(1), mSpacing(1)
|
||||
{
|
||||
for(unsigned int i = 0; i < MAX_CHARS; i++)
|
||||
{
|
||||
widths[i] = 0;
|
||||
spacing[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Font::~Font()
|
||||
{
|
||||
}
|
||||
|
||||
float Font::getHeight() const
|
||||
{
|
||||
return (float)size;
|
||||
}
|
||||
|
||||
float Font::getWidth(const std::string & line) const
|
||||
{
|
||||
if(line.size() == 0) return 0;
|
||||
float temp = 0;
|
||||
|
||||
for(unsigned int i = 0; i < line.size() - 1; i++)
|
||||
{
|
||||
temp += widths[(int)line[i]] + (spacing[(int)line[i]] * mSpacing);
|
||||
}
|
||||
temp += widths[(int)line[line.size() - 1]]; // the last character's spacing isn't counted
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
float Font::getWidth(const char * line) const
|
||||
{
|
||||
return this->getWidth(std::string(line));
|
||||
}
|
||||
|
||||
float Font::getWidth(const char character) const
|
||||
{
|
||||
return (float)widths[(int)character];
|
||||
}
|
||||
|
||||
void Font::setLineHeight(float height)
|
||||
{
|
||||
this->lineHeight = height;
|
||||
}
|
||||
|
||||
float Font::getLineHeight() const
|
||||
{
|
||||
return lineHeight;
|
||||
}
|
||||
|
||||
void Font::setSpacing(float amount)
|
||||
{
|
||||
mSpacing = amount;
|
||||
}
|
||||
|
||||
float Font::getSpacing() const
|
||||
{
|
||||
return mSpacing;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_FONT_H
|
||||
#define LOVE_GRAPHICS_OPENGL_FONT_H
|
||||
|
||||
// LOVE
|
||||
#include <filesystem/File.h>
|
||||
#include <graphics/Volatile.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
class Font : public Object, public Volatile
|
||||
{
|
||||
protected:
|
||||
|
||||
love::filesystem::File * file;
|
||||
|
||||
int size;
|
||||
float lineHeight;
|
||||
float mSpacing; // modifies the spacing by multiplying it with this value
|
||||
|
||||
public:
|
||||
static const unsigned int MAX_CHARS = 256;
|
||||
// The widths of each character.
|
||||
int widths[MAX_CHARS];
|
||||
int spacing[MAX_CHARS];
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param file The file containing the OpenGLFont data.
|
||||
* @param size The size of the OpenGLFont.
|
||||
**/
|
||||
Font(int size);
|
||||
|
||||
virtual ~Font();
|
||||
|
||||
virtual bool load() = 0;
|
||||
virtual void unload() = 0;
|
||||
|
||||
/**
|
||||
* Prints the text at the designated position.
|
||||
*
|
||||
* @param text A string.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
virtual void print(std::string text, float x, float y) const = 0;
|
||||
|
||||
/**
|
||||
* Prints the text at the designated position with rotation and scaling.
|
||||
*
|
||||
* @param text A string.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
**/
|
||||
virtual void print(std::string text, float x, float y, float angle, float sx, float sy) const = 0;
|
||||
|
||||
/**
|
||||
* Prints the character at the designated position.
|
||||
*
|
||||
* @param character A character.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
virtual void print(char character, float x, float y) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the height of the font.
|
||||
**/
|
||||
virtual float getHeight() const;
|
||||
|
||||
/**
|
||||
* Returns the width of the passed string.
|
||||
*
|
||||
* @param line A line of text.
|
||||
**/
|
||||
virtual float getWidth(const std::string & line) const;
|
||||
virtual float getWidth(const char * line) const;
|
||||
|
||||
/**
|
||||
* Returns the width of the passed character.
|
||||
*
|
||||
* @param character A character.
|
||||
**/
|
||||
virtual float getWidth(const char character) const;
|
||||
|
||||
/**
|
||||
* Sets the line height (which should be a number to multiply the font size by,
|
||||
* example: line height = 1.2 and size = 12 means that rendered line height = 12*1.2)
|
||||
* @param height The new line height.
|
||||
**/
|
||||
void setLineHeight(float height);
|
||||
|
||||
/**
|
||||
* Returns the line height.
|
||||
**/
|
||||
virtual float getLineHeight() const;
|
||||
|
||||
/**
|
||||
* Sets the spacing modifier (changes the spacing between the characters the
|
||||
* same way that the line height does [multiplication]).
|
||||
* Note: The spacing must be set BEFORE the font is loaded to have any effect.
|
||||
* @param amount The amount of modification.
|
||||
**/
|
||||
void setSpacing(float amount);
|
||||
|
||||
/**
|
||||
* Returns the spacing modifier.
|
||||
**/
|
||||
float getSpacing() const;
|
||||
|
||||
}; // Font
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_FONT_H
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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 "Frame.h"
|
||||
#include <common/Matrix.h>
|
||||
|
||||
// STD
|
||||
#include <cstring> // For memcpy
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Frame::Frame(int x, int y, int w, int h, int sw, int sh)
|
||||
{
|
||||
memset(vertices, 255, sizeof(vertex)*4);
|
||||
|
||||
vertices[0].x = 0; vertices[0].y = 0;
|
||||
vertices[1].x = 0; vertices[1].y = (float)h;
|
||||
vertices[2].x = (float)w; vertices[2].y = (float)h;
|
||||
vertices[3].x = (float)w; vertices[3].y = 0;
|
||||
|
||||
vertices[0].s = (float)x/(float)sw; vertices[0].t = (float)y/(float)sh;
|
||||
vertices[1].s = (float)x/(float)sw; vertices[1].t = (float)(y+h)/(float)sh;
|
||||
vertices[2].s = (float)(x+w)/(float)sw; vertices[2].t = (float)(y+h)/(float)sh;
|
||||
vertices[3].s = (float)(x+w)/(float)sw; vertices[3].t = (float)y/(float)sh;
|
||||
}
|
||||
|
||||
void Frame::flip(bool x, bool y)
|
||||
{
|
||||
vertex temp[4];
|
||||
if (x)
|
||||
{
|
||||
memcpy(temp, vertices, sizeof(vertex)*4);
|
||||
vertices[0].s = temp[3].s; vertices[0].t = temp[3].t;
|
||||
vertices[1].s = temp[2].s; vertices[1].t = temp[2].t;
|
||||
vertices[2].s = temp[1].s; vertices[2].t = temp[1].t;
|
||||
vertices[3].s = temp[0].s; vertices[3].t = temp[0].t;
|
||||
}
|
||||
if (y)
|
||||
{
|
||||
memcpy(temp, vertices, sizeof(vertex)*4);
|
||||
vertices[0].s = temp[1].s; vertices[0].t = temp[1].t;
|
||||
vertices[1].s = temp[0].s; vertices[1].t = temp[0].t;
|
||||
vertices[2].s = temp[3].s; vertices[2].t = temp[3].t;
|
||||
vertices[3].s = temp[2].s; vertices[3].t = temp[2].t;
|
||||
}
|
||||
}
|
||||
|
||||
const vertex * Frame::getVertices() const
|
||||
{
|
||||
return vertices;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_FRAME_H
|
||||
#define LOVE_GRAPHICS_OPENGL_FRAME_H
|
||||
|
||||
// LOVE
|
||||
#include <common/math.h>
|
||||
#include <graphics/Drawable.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
class Frame
|
||||
{
|
||||
private:
|
||||
vertex vertices[4];
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new Frame of size (w,h), using (x,y) as the top-left
|
||||
* anchor point in the source image. The size of the source image is
|
||||
* is specified by (sw,sh).
|
||||
*
|
||||
* @param x Frame source position along the x-axis.
|
||||
* @param y Frame source position along the y-axis.
|
||||
* @param w Frame width.
|
||||
* @param h Frame width.
|
||||
* @param sw Width of the source image.
|
||||
* @param sh Height of the source image.
|
||||
**/
|
||||
Frame(int x, int y, int w, int h, int sw, int sh);
|
||||
|
||||
void flip(bool x, bool y);
|
||||
|
||||
/**
|
||||
* Gets a pointer to the vertices.
|
||||
**/
|
||||
const vertex * getVertices() const;
|
||||
};
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_FRAME_H
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,576 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_GRAPHICS_H
|
||||
#define LOVE_GRAPHICS_OPENGL_GRAPHICS_H
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
// SDL
|
||||
#include <SDL.h>
|
||||
#include "GLee.h"
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
// LOVE
|
||||
#include <common/Module.h>
|
||||
#include "Image.h"
|
||||
#include "Animation.h"
|
||||
#include "Color.h"
|
||||
#include "TrueTypeFont.h"
|
||||
#include "ImageFont.h"
|
||||
#include "ParticleSystem.h"
|
||||
#include "SpriteBatch.h"
|
||||
#include "VertexBuffer.h"
|
||||
#include "Frame.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
struct DisplayMode
|
||||
{
|
||||
int width, height; // The size of the screen.
|
||||
int colorDepth; // The color depth of the display mode.
|
||||
bool fullscreen; // Fullscreen (true), or windowed (false).
|
||||
bool vsync; // Vsync enabled (true), or disabled (false).
|
||||
int fsaa; // 0 for no FSAA, otherwise 1, 2 or 4.
|
||||
};
|
||||
|
||||
// During display mode changing, certain
|
||||
// variables about the OpenGL context are
|
||||
// lost.
|
||||
struct DisplayState
|
||||
{
|
||||
// Colors.
|
||||
GLubyte color[4];
|
||||
GLubyte backgroundColor[4];
|
||||
|
||||
// Blend and color modes.
|
||||
int blendMode, colorMode;
|
||||
|
||||
// Line.
|
||||
float lineWidth;
|
||||
int lineStyle;
|
||||
bool stipple;
|
||||
int stippleRepeat;
|
||||
int stipplePattern;
|
||||
|
||||
// Point.
|
||||
float pointSize;
|
||||
int pointStyle;
|
||||
|
||||
// Scissor.
|
||||
bool scissor;
|
||||
GLint scissorBox[4];
|
||||
|
||||
// Default values.
|
||||
DisplayState()
|
||||
{
|
||||
color[0] = 255;
|
||||
color[1] = 255;
|
||||
color[2] = 255;
|
||||
color[3] = 255;
|
||||
backgroundColor[0] = 0;
|
||||
backgroundColor[1] = 0;
|
||||
backgroundColor[2] = 0;
|
||||
backgroundColor[3] = 255;
|
||||
blendMode = BLEND_NORMAL;
|
||||
colorMode = COLOR_NORMAL;
|
||||
lineWidth = 1.0f;
|
||||
lineStyle = LINE_SMOOTH;
|
||||
stipple = false;
|
||||
pointSize = 1.0f;
|
||||
pointStyle = POINT_SMOOTH;
|
||||
scissor = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class Graphics : public Module
|
||||
{
|
||||
private:
|
||||
|
||||
Font * currentFont;
|
||||
DisplayMode currentMode;
|
||||
|
||||
public:
|
||||
Graphics();
|
||||
~Graphics();
|
||||
|
||||
// Implements Module.
|
||||
const char * getName() const;
|
||||
|
||||
/**
|
||||
* Checks whether a display mode is supported or not. Note
|
||||
* that fullscreen is assumed, because windowed modes are
|
||||
* generally supported regardless of size.
|
||||
* @param width The window width.
|
||||
* @param height The window height.
|
||||
**/
|
||||
bool checkMode(int width, int height, bool fullscreen);
|
||||
|
||||
|
||||
DisplayState saveState();
|
||||
|
||||
void restoreState(const DisplayState & s);
|
||||
|
||||
/**
|
||||
* Sets the current display mode.
|
||||
* @param width The window width.
|
||||
* @param height The window height.
|
||||
* @param fullscreen True if fullscreen, false otherwise.
|
||||
* @param vsync True if we should wait for vsync, false otherwise.
|
||||
* @param fsaa Number of full scene anti-aliasing buffer, or 0 for disabled.
|
||||
**/
|
||||
bool setMode(int width, int height, bool fullscreen, bool vsync, int fsaa);
|
||||
|
||||
/**
|
||||
* Toggles fullscreen. Note that this also needs to reload the
|
||||
* entire OpenGL context.
|
||||
**/
|
||||
bool toggleFullscreen();
|
||||
|
||||
/**
|
||||
* Resets the current color, background color,
|
||||
* line style, and so forth. (This will be called
|
||||
* when the game reloads.
|
||||
**/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Clears the screen.
|
||||
**/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Flips buffers. (Rendered geometry is
|
||||
* presented on screen).
|
||||
**/
|
||||
void present();
|
||||
|
||||
/**
|
||||
* Sets the windows caption.
|
||||
**/
|
||||
void setCaption(const char * caption);
|
||||
|
||||
int getCaption(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the width of the current display mode.
|
||||
**/
|
||||
int getWidth();
|
||||
|
||||
/**
|
||||
* Gets the height of the current display mode.
|
||||
**/
|
||||
int getHeight();
|
||||
|
||||
/**
|
||||
* True if some display mode is set.
|
||||
**/
|
||||
bool isCreated();
|
||||
|
||||
/**
|
||||
* This native Lua function gets available modes
|
||||
* from SDL and returns them as a table on the following format:
|
||||
*
|
||||
* {
|
||||
* { width = 800, height = 600 },
|
||||
* { width = 1024, height = 768 },
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* Only fullscreen modes are returned here, as all
|
||||
* window sizes are supported (normally).
|
||||
**/
|
||||
int getModes(lua_State * L);
|
||||
|
||||
/**
|
||||
* Scissor defines a box such that everything outside that box is discared and not drawn.
|
||||
* Scissoring is automatically enabled.
|
||||
* @param x The x-coordinate of the top-left corner.
|
||||
* @param y The y-coordinate of the top-left corner.
|
||||
* @param width The width of the box.
|
||||
* @param height The height of the box.
|
||||
**/
|
||||
void setScissor(int x, int y, int width, int height);
|
||||
|
||||
/**
|
||||
* Clears any scissor that has been created.
|
||||
**/
|
||||
void setScissor();
|
||||
|
||||
/**
|
||||
* This native Lua function gets the current scissor box in the order of:
|
||||
* x, y, width, height
|
||||
**/
|
||||
int getScissor(lua_State * L);
|
||||
|
||||
/**
|
||||
* Creates a new Color object.
|
||||
**/
|
||||
Color * newColor( int r, int g, int b, int a );
|
||||
|
||||
/**
|
||||
* Creates an Image object with padding and/or optimization.
|
||||
**/
|
||||
Image * newImage(love::filesystem::File * file);
|
||||
Image * newImage(love::image::ImageData * data);
|
||||
|
||||
/**
|
||||
* Creates a Frame
|
||||
**/
|
||||
Frame * newFrame(int x, int y, int w, int h, int sw, int sh);
|
||||
|
||||
/**
|
||||
* Creates a Font object.
|
||||
**/
|
||||
Font * newFont(love::filesystem::File * file, int size = 12);
|
||||
|
||||
/**
|
||||
* Creates an ImageFont object.
|
||||
**/
|
||||
Font * newImageFont(Image * image, const char * glyphs, float spacing = 1);
|
||||
|
||||
/**
|
||||
* Creates an Animation object with no frames.
|
||||
**/
|
||||
Animation * newAnimation(Image * image);
|
||||
|
||||
/**
|
||||
* Creates an Animation object with generated frames in a grid.
|
||||
**/
|
||||
Animation * newAnimation(Image * image, float fw, float fh, float delay, int num = 0);
|
||||
|
||||
/**
|
||||
* Creates a ParticleSystem object with the specified buffer size and using the specified sprite.
|
||||
**/
|
||||
//pParticleSystem newParticleSystem(Image * image, unsigned int size);
|
||||
|
||||
/**
|
||||
* Creates a PointParticleSystem object with the specified buffer size and sprite.
|
||||
* @param mode This should be love::POINT_SPRITE.
|
||||
**/
|
||||
//pParticleSystem newParticleSystem(Image * image, unsigned int size, int mode);
|
||||
|
||||
SpriteBatch * newSpriteBatch(Image * image, int size, int usage);
|
||||
VertexBuffer * newVertexBuffer(Image * image, int size, int type, int usage);
|
||||
|
||||
/**
|
||||
* Sets the foreground color.
|
||||
**/
|
||||
void setColor(Color * color);
|
||||
|
||||
/**
|
||||
* Sets the foreground color.
|
||||
**/
|
||||
void setColor( int r, int g, int b, int a = 255);
|
||||
|
||||
/**
|
||||
* Gets current color.
|
||||
**/
|
||||
Color * getColor();
|
||||
|
||||
/**
|
||||
* Sets the background Color.
|
||||
**/
|
||||
void setBackgroundColor( Color * color );
|
||||
|
||||
/**
|
||||
* Sets the background Color.
|
||||
**/
|
||||
void setBackgroundColor( int r, int g, int b );
|
||||
|
||||
/**
|
||||
* Gets the current background color.
|
||||
**/
|
||||
Color * getBackgroundColor();
|
||||
|
||||
/**
|
||||
* Sets the current font.
|
||||
* @parm font A Font object.
|
||||
**/
|
||||
void setFont( Font * font );
|
||||
|
||||
/**
|
||||
* Sets a default font. The font is
|
||||
* loaded and sent to the GPU every time this is called,
|
||||
* so no over-using.
|
||||
* @param file File from which to load the font.
|
||||
* @param size The size of the font.
|
||||
**/
|
||||
void setFont( love::filesystem::File * file, int size = 12);
|
||||
|
||||
/**
|
||||
* Gets the current Font, or nil if none.
|
||||
**/
|
||||
Font * getFont();
|
||||
|
||||
/**
|
||||
* Sets the current blend mode.
|
||||
**/
|
||||
void setBlendMode( int mode );
|
||||
|
||||
/**
|
||||
* Sets the current color mode.
|
||||
**/
|
||||
void setColorMode ( int mode );
|
||||
|
||||
/**
|
||||
* Gets the current blend mode.
|
||||
**/
|
||||
int getBlendMode();
|
||||
|
||||
/**
|
||||
* Gets the current color mode.
|
||||
**/
|
||||
int getColorMode();
|
||||
|
||||
/**
|
||||
* Sets the line width.
|
||||
* @param width The new width of the line.
|
||||
**/
|
||||
void setLineWidth( float width );
|
||||
|
||||
/**
|
||||
* Sets the line style.
|
||||
* @param style LINE_ROUGH or LINE_SMOOTH.
|
||||
**/
|
||||
void setLineStyle( int style );
|
||||
|
||||
/**
|
||||
* Sets the type of line used to draw primitives.
|
||||
* A shorthand for setLineWidth and setLineStyle.
|
||||
**/
|
||||
void setLine( float width, int style = 0 );
|
||||
|
||||
/**
|
||||
* Disables line stippling.
|
||||
**/
|
||||
void setLineStipple();
|
||||
|
||||
/**
|
||||
* Sets a line stipple pattern.
|
||||
**/
|
||||
void setLineStipple(unsigned short pattern, int repeat = 1);
|
||||
|
||||
/**
|
||||
* Gets the line width.
|
||||
**/
|
||||
float getLineWidth();
|
||||
|
||||
/**
|
||||
* Gets the line style.
|
||||
**/
|
||||
int getLineStyle();
|
||||
|
||||
/**
|
||||
* Gets the line stipple pattern and repeat factor.
|
||||
* @return pattern The stipplie bit-pattern.
|
||||
* @return repeat The reapeat factor.
|
||||
**/
|
||||
int getLineStipple(lua_State * L);
|
||||
|
||||
/**
|
||||
* Sets the size of points.
|
||||
**/
|
||||
void setPointSize( float size );
|
||||
|
||||
/**
|
||||
* Sets the style of points.
|
||||
* @param style POINT_SMOOTH or POINT_ROUGH.
|
||||
**/
|
||||
void setPointStyle( int style );
|
||||
|
||||
/**
|
||||
* Shorthand for setPointSize and setPointStyle.
|
||||
**/
|
||||
void setPoint( float size, int style );
|
||||
|
||||
/**
|
||||
* Gets the point size.
|
||||
**/
|
||||
float getPointSize();
|
||||
|
||||
/**
|
||||
* Gets the point style.
|
||||
**/
|
||||
int getPointStyle();
|
||||
|
||||
/**
|
||||
* Gets the maximum point size supported.
|
||||
* This may vary from computer to computer.
|
||||
**/
|
||||
int getMaxPointSize();
|
||||
|
||||
/**
|
||||
* Draw text on screen at the specified coordiantes (automatically breaks \n characters).
|
||||
*
|
||||
* @param str A string of text.
|
||||
* @param x The x-coordiante.
|
||||
* @param y The y-coordiante.
|
||||
**/
|
||||
void print( const char * str, float x, float y );
|
||||
|
||||
/**
|
||||
* Draws text at the specified coordinates, with rotation.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
**/
|
||||
void print( const char * str, float x, float y , float angle );
|
||||
|
||||
/**
|
||||
* Draws text at the specified coordinates, with rotation and
|
||||
* scaling.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
* @param s The scale factor. (1 = normal).
|
||||
**/
|
||||
void print( const char * str, float x, float y , float angle, float s );
|
||||
|
||||
/**
|
||||
* Draws text at the specified coordinates, with rotation and
|
||||
* scaling along both axes.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
* @param sx The scale factor along the x-axis. (1 = normal).
|
||||
* @param sy The scale factor along the y-axis. (1 = normal).
|
||||
**/
|
||||
void print( const char * str, float x, float y , float angle, float sx, float sy);
|
||||
|
||||
/**
|
||||
* Draw formatted text on screen at the specified coordinates.
|
||||
*
|
||||
* @param str A string of text.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param wrap The maximum width of the text area.
|
||||
* @param align Where to align the text.
|
||||
**/
|
||||
void printf( const char * str, float x, float y, float wrap, int align = 0 );
|
||||
|
||||
/**
|
||||
* Draws an Image at the specified coordinates, with rotation and
|
||||
* scaling along both axes.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
* @param sx The scale factor along the x-axis. (1 = normal).
|
||||
* @param sy The scale factor along the y-axis. (1 = normal).
|
||||
**/
|
||||
//void draw(Drawable * drawable, float x, float y, float angle, float sx, float sy);
|
||||
|
||||
/**
|
||||
* Draws a point at (x,y).
|
||||
* @param x Point along x-axis.
|
||||
* @param y Point along y-axis.
|
||||
**/
|
||||
void point( float x, float y );
|
||||
|
||||
/**
|
||||
* Draws a line from (x1,y1) to (x2,y2).
|
||||
* @param x1 First x-coordinate.
|
||||
* @param y1 First y-coordinate.
|
||||
* @param x2 Second x-coordinate.
|
||||
* @param y2 Second y-coordinate.
|
||||
**/
|
||||
void line( float x1, float y1, float x2, float y2 );
|
||||
|
||||
/**
|
||||
* Draws a triangle using the three coordinates passed.
|
||||
* @param type The type of drawing (line/filled).
|
||||
* @param x1 First x-coordinate.
|
||||
* @param y1 First y-coordinate.
|
||||
* @param x2 Second x-coordinate.
|
||||
* @param y2 Second y-coordinate.
|
||||
* @param x3 Third x-coordinate.
|
||||
* @param y3 Third y-coordinate.
|
||||
**/
|
||||
void triangle( int type, float x1, float y1, float x2, float y2, float x3, float y3 );
|
||||
|
||||
/**
|
||||
* Draws a rectangle.
|
||||
* @param x Position along x-axis for top-left corner.
|
||||
* @param y Position along y-axis for top-left corner.
|
||||
* @param w The width of the rectangle.
|
||||
* @param h The height of the rectangle.
|
||||
**/
|
||||
void rectangle( int type, float x, float y, float w, float h );
|
||||
|
||||
/**
|
||||
* Draws a quadrilateral using the four coordinates passed.
|
||||
* @param type The type of drawing (line/filled).
|
||||
* @param x1 First x-coordinate.
|
||||
* @param y1 First y-coordinate.
|
||||
* @param x2 Second x-coordinate.
|
||||
* @param y2 Second y-coordinate.
|
||||
* @param x3 Third x-coordinate.
|
||||
* @param y3 Third y-coordinate.
|
||||
* @param x4 Fourth x-coordinate.
|
||||
* @param y4 Fourth y-coordinate.
|
||||
**/
|
||||
void quad( int type, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4 );
|
||||
|
||||
/**
|
||||
* Draws a circle using the specified arguments.
|
||||
* @param type The type of drawing (line/filled).
|
||||
* @param x X-coordinate.
|
||||
* @param y Y-coordinate.
|
||||
* @param radius Radius of the circle.
|
||||
* @param points Amount of points to use to draw the circle.
|
||||
**/
|
||||
void circle( int type, float x, float y, float radius, int points = 10 );
|
||||
|
||||
/**
|
||||
* Draws a polygon with an arbitrary number of vertices.
|
||||
* @param type The type of drawing (line/filled).
|
||||
* @param ... Vertex components (x1, y1, x2, y2, etc).
|
||||
**/
|
||||
int polygon( lua_State * L );
|
||||
int polygong( lua_State * L );
|
||||
|
||||
/**
|
||||
* Creates a screenshot of the view and saves it to the default folder.
|
||||
* @param file The file to write the screenshot to.
|
||||
**/
|
||||
bool screenshot(love::filesystem::File * file);
|
||||
|
||||
void push();
|
||||
void pop();
|
||||
void rotate(float r);
|
||||
void scale(float x, float y = 1.0f);
|
||||
void translate(float x, float y);
|
||||
|
||||
void drawTest(Image * image, float x, float y, float a, float sx, float sy, float ox, float oy);
|
||||
|
||||
}; // Graphics
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_GRAPHICS_H
|
||||
@@ -0,0 +1,337 @@
|
||||
/**
|
||||
* 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 "Image.h"
|
||||
|
||||
// STD
|
||||
#include <cstring> // For memcpy
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Image::Image(love::image::ImageData * data)
|
||||
: width((float)(data->getWidth())), height((float)(data->getHeight())), texture(0)
|
||||
{
|
||||
data->retain();
|
||||
this->data = data;
|
||||
|
||||
memset(vertices, 255, sizeof(vertex)*4);
|
||||
|
||||
vertices[0].x = 0; vertices[0].y = 0;
|
||||
vertices[1].x = 0; vertices[1].y = height;
|
||||
vertices[2].x = width; vertices[2].y = height;
|
||||
vertices[3].x = width; vertices[3].y = 0;
|
||||
|
||||
vertices[0].s = 0; vertices[0].t = 0;
|
||||
vertices[1].s = 0; vertices[1].t = 1;
|
||||
vertices[2].s = 1; vertices[2].t = 1;
|
||||
vertices[3].s = 1; vertices[3].t = 0;
|
||||
|
||||
}
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
if(data != 0)
|
||||
data->release();
|
||||
unload();
|
||||
}
|
||||
|
||||
float Image::getWidth() const
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
float Image::getHeight() const
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
const vertex * Image::getVertices() const
|
||||
{
|
||||
return vertices;
|
||||
}
|
||||
|
||||
love::image::ImageData * Image::getData() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
void Image::getRectangleVertices(int x, int y, int w, int h, vertex * vertices) const
|
||||
{
|
||||
// Check upper.
|
||||
x = (x+w > (int)width) ? (int)width-w : x;
|
||||
y = (y+h > (int)height) ? (int)height-h : y;
|
||||
|
||||
// Check lower.
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
|
||||
vertices[0].x = 0; vertices[0].y = 0;
|
||||
vertices[1].x = 0; vertices[1].y = (float)h;
|
||||
vertices[2].x = (float)w; vertices[2].y = (float)h;
|
||||
vertices[3].x = (float)w; vertices[3].y = 0;
|
||||
|
||||
float tx = (float)x/width;
|
||||
float ty = (float)y/height;
|
||||
float tw = (float)w/width;
|
||||
float th = (float)h/height;
|
||||
|
||||
vertices[0].s = tx; vertices[0].t = ty;
|
||||
vertices[1].s = tx; vertices[1].t = ty+th;
|
||||
vertices[2].s = tx+tw; vertices[2].t = ty+th;
|
||||
vertices[3].s = tx+tw; vertices[3].t = ty;
|
||||
}
|
||||
|
||||
void Image::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const
|
||||
{
|
||||
static Matrix t;
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy);
|
||||
drawv(t, vertices);
|
||||
}
|
||||
|
||||
void Image::draws(float x, float y, float angle, float sx, float sy, float ox, float oy, float rx, float ry, float rw, float rh) const
|
||||
{
|
||||
static Matrix t;
|
||||
static vertex cache[4];
|
||||
|
||||
getRectangleVertices((int)rx, (int)ry, (int)rw, (int)rh, cache);
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy);
|
||||
drawv(t, cache);
|
||||
}
|
||||
|
||||
void Image::draws(float x, float y, float angle, float sx, float sy, float ox, float oy, Frame * frame) const
|
||||
{
|
||||
static Matrix t;
|
||||
const vertex * v = frame->getVertices();
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy);
|
||||
drawv(t, v);
|
||||
}
|
||||
|
||||
void Image::setFilter(Image::Filter f)
|
||||
{
|
||||
GLint gmin, gmag;
|
||||
|
||||
switch(f.min)
|
||||
{
|
||||
case FILTER_LINEAR:
|
||||
gmin = GL_LINEAR;
|
||||
break;
|
||||
case FILTER_NEAREST:
|
||||
gmin = GL_NEAREST;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(f.mag)
|
||||
{
|
||||
case FILTER_LINEAR:
|
||||
gmag = GL_LINEAR;
|
||||
break;
|
||||
case FILTER_NEAREST:
|
||||
gmag = GL_NEAREST;
|
||||
break;
|
||||
}
|
||||
|
||||
bind();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gmin);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gmag);
|
||||
}
|
||||
|
||||
Image::Filter Image::getFilter() const
|
||||
{
|
||||
bind();
|
||||
|
||||
GLint gmin, gmag;
|
||||
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &gmin);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &gmag);
|
||||
|
||||
Image::Filter f;
|
||||
|
||||
switch(gmin)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.min = FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.min = FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(gmin)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.mag = FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.mag = FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void Image::setWrap(Image::Wrap w)
|
||||
{
|
||||
GLint gs, gt;
|
||||
|
||||
switch(w.s)
|
||||
{
|
||||
case WRAP_CLAMP:
|
||||
gs = GL_CLAMP;
|
||||
break;
|
||||
case WRAP_REPEAT:
|
||||
default:
|
||||
gs = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(w.t)
|
||||
{
|
||||
case WRAP_CLAMP:
|
||||
gt = GL_CLAMP;
|
||||
break;
|
||||
case WRAP_REPEAT:
|
||||
default:
|
||||
gt = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
bind();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gs);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gt);
|
||||
}
|
||||
|
||||
Image::Wrap Image::getWrap() const
|
||||
{
|
||||
bind();
|
||||
|
||||
GLint gs, gt;
|
||||
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &gs);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, >);
|
||||
|
||||
Wrap w;
|
||||
|
||||
switch(gs)
|
||||
{
|
||||
case GL_CLAMP:
|
||||
w.s = WRAP_CLAMP;
|
||||
break;
|
||||
case GL_REPEAT:
|
||||
default:
|
||||
w.s = WRAP_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(gt)
|
||||
{
|
||||
case GL_CLAMP:
|
||||
w.t = WRAP_CLAMP;
|
||||
break;
|
||||
case GL_REPEAT:
|
||||
default:
|
||||
w.t = WRAP_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
void Image::bind() const
|
||||
{
|
||||
if(texture != 0)
|
||||
glBindTexture(GL_TEXTURE_2D,texture);
|
||||
}
|
||||
|
||||
bool Image::load()
|
||||
{
|
||||
return loadVolatile();
|
||||
}
|
||||
|
||||
void Image::unload()
|
||||
{
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
bool Image::loadVolatile()
|
||||
{
|
||||
glGenTextures(1,(GLuint*)&texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA8,
|
||||
(GLsizei)width,
|
||||
(GLsizei)height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
data->getData());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Image::unloadVolatile()
|
||||
{
|
||||
// Delete the hardware texture.
|
||||
if(texture != 0)
|
||||
{
|
||||
glDeleteTextures(1, (GLuint*)&texture);
|
||||
texture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Image::drawv(const Matrix & t, const vertex * v) const
|
||||
{
|
||||
bind();
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
glMultMatrixf((const GLfloat*)t.getElements());
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&v[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&v[0].s);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_IMAGE_H
|
||||
#define LOVE_GRAPHICS_OPENGL_IMAGE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/config.h>
|
||||
#include <image/ImageData.h>
|
||||
#include <common/math.h>
|
||||
#include <graphics/Image.h>
|
||||
#include "Frame.h"
|
||||
#include <common/Matrix.h>
|
||||
#include <common/math.h>
|
||||
|
||||
// OpenGL
|
||||
#include <SDL/SDL_opengl.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* A drawable image based on OpenGL-textures. This class takes ImageData
|
||||
* objects and create textures on the GPU for fast drawing.
|
||||
*
|
||||
* @author Anders Ruud
|
||||
**/
|
||||
class Image : public love::graphics::Image
|
||||
{
|
||||
private:
|
||||
|
||||
// The ImageData from which the texture is created.
|
||||
love::image::ImageData * data;
|
||||
|
||||
// Width and height of the hardware texture.
|
||||
float width, height;
|
||||
|
||||
// OpenGL texture identifier.
|
||||
GLuint texture;
|
||||
|
||||
// The source vertices of the image.
|
||||
vertex vertices[4];
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new Image. Not that anything is ready to use
|
||||
* before load is called.
|
||||
*
|
||||
* @param file The file from which to load the image.
|
||||
**/
|
||||
Image(love::image::ImageData * data);
|
||||
|
||||
/**
|
||||
* Destructor. Deletes the hardware texture and other resources.
|
||||
**/
|
||||
virtual ~Image();
|
||||
|
||||
float getWidth() const;
|
||||
float getHeight() const;
|
||||
|
||||
const vertex * getVertices() const;
|
||||
|
||||
love::image::ImageData * getData() const;
|
||||
|
||||
/**
|
||||
* Generate vertices according to a subimage.
|
||||
*
|
||||
* Note: out-of-range values will be clamped.
|
||||
* Note: the vertex colors will not be changed.
|
||||
*
|
||||
* @param x The top-left corner of the subimage along the x-axis.
|
||||
* @param y The top-left corner of the subimage along the y-axis.
|
||||
* @param w The width of the subimage.
|
||||
* @param h The height of the subimage.
|
||||
* @param vertices A vertex array of size four.
|
||||
**/
|
||||
void getRectangleVertices(int x, int y, int w, int h, vertex * vertices) const;
|
||||
|
||||
/**
|
||||
* @copydoc Drawable::draw()
|
||||
**/
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
|
||||
/**
|
||||
* This function draws a section of the image.
|
||||
*
|
||||
* @copydetails Drawable::draw()
|
||||
* @param rx The upper-left corner of the source rectangle along the x-axis.
|
||||
* @param ry The upper-left corner of the source rectangle along the y-axis.
|
||||
* @param rw The width of the source rectangle.
|
||||
* @param rw The height of the source rectangle.
|
||||
**/
|
||||
void draws(float x, float y, float angle, float sx, float sy, float ox, float oy, float rx, float ry, float rw, float rh) const;
|
||||
|
||||
/**
|
||||
* This function draws a section of the image using a Frame object.
|
||||
*
|
||||
* @copydetails Image::draws()
|
||||
* @param frame Represents the region of the Image to draw.
|
||||
**/
|
||||
void draws(float x, float y, float angle, float sx, float sy, float ox, float oy, Frame * frame) const;
|
||||
|
||||
/**
|
||||
* Sets the filter mode.
|
||||
*
|
||||
* @param mode The filter mode.
|
||||
**/
|
||||
void setFilter(Image::Filter f);
|
||||
|
||||
Image::Filter getFilter() const;
|
||||
|
||||
void setWrap(Image::Wrap r);
|
||||
|
||||
Image::Wrap getWrap() const;
|
||||
|
||||
void bind() const;
|
||||
|
||||
bool load();
|
||||
void unload();
|
||||
|
||||
// Implements Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
private:
|
||||
|
||||
void drawv(const Matrix & t, const vertex * v) const;
|
||||
|
||||
}; // Image
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_IMAGE_H
|
||||
@@ -0,0 +1,225 @@
|
||||
/**
|
||||
* 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 "ImageFont.h"
|
||||
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
ImageFont::ImageFont(Image * image, std::string glyphs)
|
||||
: Font(0), glyphs(glyphs), image(image)
|
||||
|
||||
{
|
||||
image->retain();
|
||||
}
|
||||
|
||||
ImageFont::~ImageFont()
|
||||
{
|
||||
unload();
|
||||
image->release();
|
||||
}
|
||||
|
||||
void ImageFont::print(string text, float x, float y) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, 0.0f);
|
||||
GLuint OpenGLFont = list;
|
||||
glListBase(OpenGLFont);
|
||||
glCallLists((int)text.length(), GL_UNSIGNED_BYTE, text.c_str());
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void ImageFont::print(std::string text, float x, float y, float angle, float sx, float sy) const
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef(x, y, 0.0f);
|
||||
glRotatef(angle, 0, 0, 1.0f);
|
||||
glScalef(sx, sy, 1.0f);
|
||||
|
||||
GLuint OpenGLFont = list;
|
||||
glListBase(OpenGLFont);
|
||||
glCallLists((int)text.length(), GL_UNSIGNED_BYTE, text.c_str());
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void ImageFont::print(char character, float x, float y) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, 0.0f);
|
||||
GLuint OpenGLFont = list;
|
||||
glListBase(OpenGLFont);
|
||||
glCallList(list + (int)character);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
bool ImageFont::load()
|
||||
{
|
||||
return loadVolatile();
|
||||
}
|
||||
|
||||
void ImageFont::unload()
|
||||
{
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
bool ImageFont::loadVolatile()
|
||||
{
|
||||
love::image::pixel * pixels = (love::image::pixel *)(image->getData()->getData());
|
||||
|
||||
// Reading texture data begins
|
||||
size = (int)image->getHeight();
|
||||
|
||||
for(unsigned int i = 0; i < MAX_CHARS; i++) positions[i] = -1;
|
||||
|
||||
love::image::pixel spacer = pixels[0];
|
||||
unsigned int current = 0;
|
||||
int width = 0;
|
||||
int space = 0;
|
||||
|
||||
// Finds out where the first character starts
|
||||
int firstchar = 0;
|
||||
for(int i = 0; i != (int)image->getWidth(); i++)
|
||||
{
|
||||
if(spacer.r == pixels[i].r && spacer.g == pixels[i].g && spacer.b == pixels[i].b && spacer.a == pixels[i].a)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
firstchar = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = firstchar; i != (int)image->getWidth(); i++)
|
||||
{
|
||||
if(spacer.r == pixels[i].r && spacer.g == pixels[i].g && spacer.b == pixels[i].b && spacer.a == pixels[i].a)
|
||||
{
|
||||
if(width != 0) // this means we have found the end of our current character
|
||||
{
|
||||
if((unsigned int)glyphs[current] > MAX_CHARS)
|
||||
printf("Error reading texture font: Character '%c' is out of range.", glyphs[current]);
|
||||
else
|
||||
{
|
||||
widths[(int)glyphs[current]] = width - 1;
|
||||
positions[(int)glyphs[current]] = i - width;
|
||||
}
|
||||
|
||||
width = 0;
|
||||
//space++; // start counting the spacing
|
||||
}
|
||||
space++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(space != 0) // this means we have found the end of our spacing
|
||||
{
|
||||
if((unsigned int)spacing[current] > MAX_CHARS)
|
||||
printf("Error reading image font: Character '%c' is out of range.", glyphs[current]);
|
||||
else
|
||||
spacing[(int)glyphs[current]] = space;
|
||||
|
||||
current++;
|
||||
if(current == glyphs.size())
|
||||
i = (int)image->getWidth() - 1; // just to end it when the last character is found
|
||||
|
||||
space = 0;
|
||||
//width++; // start counting the width
|
||||
}
|
||||
width++;
|
||||
}
|
||||
}
|
||||
// Reading image data ends
|
||||
|
||||
// Replace spacer color with an empty pixel
|
||||
for(int i = 0; i < (int)(image->getWidth() * image->getHeight()); i++)
|
||||
{
|
||||
if(spacer.r == pixels[i].r && spacer.g == pixels[i].g && spacer.b == pixels[i].b && spacer.a == pixels[i].a)
|
||||
{
|
||||
pixels[i].r = 0;
|
||||
pixels[i].g = 0;
|
||||
pixels[i].b = 0;
|
||||
pixels[i].a = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Create display lists
|
||||
list = glGenLists(MAX_CHARS);
|
||||
|
||||
for(unsigned int i = 0; i < MAX_CHARS; i++)
|
||||
{
|
||||
glNewList(list + i, GL_COMPILE);
|
||||
|
||||
if(positions[i] != -1)
|
||||
{
|
||||
|
||||
float x = (float)positions[i] + 1;
|
||||
float y = 1.0;
|
||||
float w = (float)widths[i];
|
||||
float h = (float)size+1;
|
||||
|
||||
image->bind();
|
||||
|
||||
float xTex = x/(float)image->getWidth();
|
||||
float yTex = y/(float)image->getHeight();
|
||||
|
||||
float wTex = w/(float)image->getWidth();
|
||||
float hTex = h/(float)image->getHeight();
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(xTex,yTex); glVertex2f(0,0);
|
||||
glTexCoord2f(xTex,yTex+hTex); glVertex2f(0,h);
|
||||
glTexCoord2f(xTex+wTex,yTex+hTex); glVertex2f(w,h);
|
||||
glTexCoord2f(xTex+wTex,yTex); glVertex2f(w,0);
|
||||
glEnd();
|
||||
|
||||
glTranslatef((float)widths[i] + ((float)spacing[i] * mSpacing), 0, 0);
|
||||
}
|
||||
else
|
||||
glTranslatef((float)widths[(int)' '], 0, 0); // empty character are replaced with a whitespace
|
||||
|
||||
glEndList();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImageFont::unloadVolatile()
|
||||
{
|
||||
glDeleteLists(list, MAX_CHARS);
|
||||
}
|
||||
|
||||
inline int ImageFont::next_p2(int num)
|
||||
{
|
||||
int powered = 2;
|
||||
while(powered < num) powered <<= 1;
|
||||
return powered;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_OPENGL_IMAGE_FONT_H
|
||||
#define LOVE_OPENGL_IMAGE_FONT_H
|
||||
|
||||
#include <image/ImageData.h>
|
||||
#include "Font.h"
|
||||
#include "Image.h"
|
||||
|
||||
// STD
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* A class to handle OpenGL image fonts.
|
||||
*
|
||||
* @author Michael Enger
|
||||
* @date 2008-01-17
|
||||
**/
|
||||
class ImageFont : public Font
|
||||
{
|
||||
protected:
|
||||
|
||||
Image * image;
|
||||
|
||||
// List of glyphs.
|
||||
std::string glyphs;
|
||||
|
||||
// The position of each character.
|
||||
int positions[MAX_CHARS];
|
||||
|
||||
// OpenGL display lists.
|
||||
unsigned int list;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param file The image file.
|
||||
* @param glyphs A list of the characters as they appear in the image.
|
||||
**/
|
||||
ImageFont(Image * image, std::string glyphs);
|
||||
|
||||
/**
|
||||
* Calls unload().
|
||||
**/
|
||||
virtual ~ImageFont();
|
||||
|
||||
|
||||
// From Font
|
||||
virtual void print(std::string text, float x, float y) const;
|
||||
virtual void print(std::string text, float x, float y, float angle, float sx, float sy) const;
|
||||
virtual void print(char character, float x, float y) const;
|
||||
|
||||
// From Resource.
|
||||
bool load();
|
||||
void unload();
|
||||
|
||||
// From Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Returns the closest number to num which is a power of two.
|
||||
*
|
||||
* @param num The number to be 2powered.
|
||||
**/
|
||||
inline int next_p2(int num);
|
||||
|
||||
}; // ImageFont
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_OPENGL_IMAGE_FONT_H
|
||||
@@ -0,0 +1,497 @@
|
||||
/**
|
||||
* 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 "ParticleSystem.h"
|
||||
|
||||
#include <SDL_opengl.h>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
float calculate_variation(float inner, float outer, float var)
|
||||
{
|
||||
float low = inner - (outer/2.0f)*var;
|
||||
float high = inner + (outer/2.0f)*var;
|
||||
float r = (rand() / (float(RAND_MAX)+1));
|
||||
return low*(1-r)+high*r;
|
||||
}
|
||||
|
||||
|
||||
ParticleSystem::ParticleSystem(Image * sprite, unsigned int buffer) : pStart(0), pLast(0), pEnd(0), active(true), emissionRate(0),
|
||||
emitCounter(0), lifetime(-1), life(0), particleLifeMin(0), particleLifeMax(0),
|
||||
direction(0), spread(0), relative(false), speedMin(0), speedMax(0), gravityMin(0),
|
||||
gravityMax(0), radialAccelerationMin(0), radialAccelerationMax(0),
|
||||
tangentialAccelerationMin(0), tangentialAccelerationMax(0),
|
||||
sizeStart(1), sizeEnd(1), sizeVariation(0), rotationMin(0), rotationMax(0),
|
||||
spinStart(0), spinEnd(0), spinVariation(0)
|
||||
{
|
||||
this->sprite = sprite;
|
||||
sprite->retain();
|
||||
colorStart = Color(255, 255, 255, 255);
|
||||
colorEnd = Color(255, 255, 255, 255);
|
||||
setBufferSize(buffer);
|
||||
}
|
||||
|
||||
ParticleSystem::~ParticleSystem()
|
||||
{
|
||||
if(this->sprite != 0)
|
||||
{
|
||||
this->sprite->release();
|
||||
this->sprite = 0;
|
||||
}
|
||||
|
||||
if(pStart != 0)
|
||||
delete [] pStart;
|
||||
}
|
||||
|
||||
void ParticleSystem::add()
|
||||
{
|
||||
if(isFull()) return;
|
||||
|
||||
float min,max;
|
||||
|
||||
min = particleLifeMin;
|
||||
max = particleLifeMax;
|
||||
if(min == max)
|
||||
pLast->life = min;
|
||||
else
|
||||
pLast->life = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
|
||||
pLast->lifetime = pLast->life;
|
||||
|
||||
pLast->position[0] = position.getX();
|
||||
pLast->position[1] = position.getY();
|
||||
|
||||
min = direction - spread/2.0f;
|
||||
max = direction + spread/2.0f;
|
||||
pLast->direction = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
|
||||
|
||||
min = speedMin;
|
||||
max = speedMax;
|
||||
float speed = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
|
||||
pLast->speed = love::Vector(cos(pLast->direction), sin(pLast->direction));
|
||||
pLast->speed *= speed;
|
||||
|
||||
min = gravityMin;
|
||||
max = gravityMax;
|
||||
pLast->gravity = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
|
||||
|
||||
min = radialAccelerationMin;
|
||||
max = radialAccelerationMax;
|
||||
pLast->radialAcceleration = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
|
||||
|
||||
min = tangentialAccelerationMin;
|
||||
max = tangentialAccelerationMax;
|
||||
pLast->tangentialAcceleration = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
|
||||
|
||||
pLast->sizeStart = calculate_variation(sizeStart, sizeEnd, sizeVariation);
|
||||
pLast->sizeEnd = calculate_variation(sizeEnd, sizeStart, sizeVariation);
|
||||
pLast->size = pLast->sizeStart;
|
||||
|
||||
min = rotationMin;
|
||||
max = rotationMax;
|
||||
pLast->spinStart = calculate_variation(spinStart, spinEnd, spinVariation);
|
||||
pLast->spinEnd = calculate_variation(spinEnd, spinStart, spinVariation);
|
||||
pLast->rotation = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;;
|
||||
|
||||
pLast->color[0] = (float)colorStart.getRed() / 255;
|
||||
pLast->color[1] = (float)colorStart.getGreen() / 255;
|
||||
pLast->color[2] = (float)colorStart.getBlue() / 255;
|
||||
pLast->color[3] = (float)colorStart.getAlpha() / 255;
|
||||
|
||||
pLast++;
|
||||
}
|
||||
|
||||
void ParticleSystem::remove(particle * p)
|
||||
{
|
||||
if(!isEmpty())
|
||||
{
|
||||
*p = *(--pLast);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleSystem::setSprite(Image * image)
|
||||
{
|
||||
if(this->sprite != 0)
|
||||
{
|
||||
this->sprite->release();
|
||||
this->sprite = 0;
|
||||
}
|
||||
|
||||
this->sprite = image;
|
||||
}
|
||||
|
||||
void ParticleSystem::setBufferSize(unsigned int size)
|
||||
{
|
||||
// delete previous data
|
||||
delete [] pStart;
|
||||
|
||||
pLast = pStart = new particle[size];
|
||||
|
||||
pEnd = pStart + size;
|
||||
}
|
||||
|
||||
void ParticleSystem::setEmissionRate(int rate)
|
||||
{
|
||||
emissionRate = rate;
|
||||
}
|
||||
|
||||
void ParticleSystem::setLifetime(float life)
|
||||
{
|
||||
this->life = lifetime = life;
|
||||
}
|
||||
|
||||
void ParticleSystem::setParticleLife(float min, float max)
|
||||
{
|
||||
particleLifeMin = min;
|
||||
if(max == 0)
|
||||
particleLifeMax = min;
|
||||
else
|
||||
particleLifeMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::setPosition(float x, float y)
|
||||
{
|
||||
position = love::Vector(x, y);
|
||||
}
|
||||
|
||||
void ParticleSystem::setDirection(float direction)
|
||||
{
|
||||
this->direction = direction * LOVE_M_TORAD;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpread(float spread)
|
||||
{
|
||||
this->spread = spread * LOVE_M_TORAD;
|
||||
}
|
||||
|
||||
void ParticleSystem::setRelativeDirection(bool relative)
|
||||
{
|
||||
this->relative = relative;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpeed(float speed)
|
||||
{
|
||||
speedMin = speedMax = speed;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpeed(float min, float max)
|
||||
{
|
||||
speedMin = min;
|
||||
speedMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::setGravity(float gravity)
|
||||
{
|
||||
gravityMin = gravityMax = gravity;
|
||||
}
|
||||
|
||||
void ParticleSystem::setGravity(float min, float max)
|
||||
{
|
||||
gravityMin = min;
|
||||
gravityMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::setRadialAcceleration(float acceleration)
|
||||
{
|
||||
radialAccelerationMin = radialAccelerationMax = acceleration;
|
||||
}
|
||||
|
||||
void ParticleSystem::setRadialAcceleration(float min, float max)
|
||||
{
|
||||
radialAccelerationMin = min;
|
||||
radialAccelerationMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::setTangentialAcceleration(float acceleration)
|
||||
{
|
||||
tangentialAccelerationMin = tangentialAccelerationMax = acceleration;
|
||||
}
|
||||
|
||||
void ParticleSystem::setTangentialAcceleration(float min, float max)
|
||||
{
|
||||
tangentialAccelerationMin = min;
|
||||
tangentialAccelerationMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSize(float size)
|
||||
{
|
||||
sizeStart = size;
|
||||
sizeEnd = size;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSize(float start, float end)
|
||||
{
|
||||
sizeStart = start;
|
||||
sizeEnd = end;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSize(float start, float end, float variation)
|
||||
{
|
||||
sizeStart = start;
|
||||
sizeEnd = end;
|
||||
sizeVariation = variation;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSizeVariation(float variation)
|
||||
{
|
||||
sizeVariation = variation;
|
||||
}
|
||||
|
||||
void ParticleSystem::setRotation(float rotation)
|
||||
{
|
||||
rotationMin = rotationMax = rotation;
|
||||
}
|
||||
|
||||
void ParticleSystem::setRotation(float min, float max)
|
||||
{
|
||||
rotationMin = min;
|
||||
rotationMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpin(float spin)
|
||||
{
|
||||
spinStart = spin * LOVE_M_TORAD;
|
||||
spinEnd = spin * LOVE_M_TORAD;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpin(float start, float end)
|
||||
{
|
||||
spinStart = start * LOVE_M_TORAD;
|
||||
spinEnd = end * LOVE_M_TORAD;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpin(float start, float end, float variation)
|
||||
{
|
||||
spinStart = start * LOVE_M_TORAD;
|
||||
spinEnd = end * LOVE_M_TORAD;
|
||||
spinVariation = variation * LOVE_M_TORAD;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpinVariation(float variation)
|
||||
{
|
||||
spinVariation = variation * LOVE_M_TORAD;
|
||||
}
|
||||
|
||||
void ParticleSystem::setColor(Color * color)
|
||||
{
|
||||
colorStart = *color;
|
||||
colorEnd = *color;
|
||||
}
|
||||
|
||||
void ParticleSystem::setColor(Color * start, Color * end)
|
||||
{
|
||||
colorStart = *start;
|
||||
colorEnd = *end;
|
||||
}
|
||||
|
||||
float ParticleSystem::getX() const
|
||||
{
|
||||
return position.getX();
|
||||
}
|
||||
|
||||
float ParticleSystem::getY() const
|
||||
{
|
||||
return position.getY();
|
||||
}
|
||||
|
||||
float ParticleSystem::getDirection() const
|
||||
{
|
||||
return direction * LOVE_M_TODEG;
|
||||
}
|
||||
|
||||
float ParticleSystem::getSpread() const
|
||||
{
|
||||
return spread * LOVE_M_TODEG;
|
||||
}
|
||||
|
||||
int ParticleSystem::count() const
|
||||
{
|
||||
return (int)(pLast - pStart);
|
||||
}
|
||||
|
||||
void ParticleSystem::start()
|
||||
{
|
||||
active = true;
|
||||
}
|
||||
|
||||
void ParticleSystem::stop()
|
||||
{
|
||||
active = false;
|
||||
life = lifetime;
|
||||
emitCounter = 0;
|
||||
}
|
||||
|
||||
void ParticleSystem::pause()
|
||||
{
|
||||
active = false;
|
||||
}
|
||||
|
||||
void ParticleSystem::reset()
|
||||
{
|
||||
pLast = pStart;
|
||||
life = lifetime;
|
||||
emitCounter = 0;
|
||||
}
|
||||
|
||||
bool ParticleSystem::isActive() const
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
bool ParticleSystem::isEmpty() const
|
||||
{
|
||||
return pStart == pLast;
|
||||
}
|
||||
|
||||
bool ParticleSystem::isFull() const
|
||||
{
|
||||
return pLast == pEnd;
|
||||
}
|
||||
|
||||
void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const
|
||||
{
|
||||
if(sprite == 0) return; // just in case of failure
|
||||
|
||||
glPushMatrix();
|
||||
glPushAttrib(GL_CURRENT_BIT);
|
||||
|
||||
glTranslatef(x, y, 0);
|
||||
glRotatef(angle, 0, 0, 1.0f);
|
||||
glScalef(sx, sy, 1.0f);
|
||||
glTranslatef( ox, oy, 0);
|
||||
|
||||
particle * p = pStart;
|
||||
while(p != pLast)
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glColor4f(p->color[0],p->color[1],p->color[2],p->color[3]);
|
||||
glTranslatef(p->position[0],p->position[1],0.0f);
|
||||
glRotatef(p->rotation * 57.29578f, 0.0f, 0.0f, 1.0f); // rad * (180 / pi)
|
||||
glScalef(p->size,p->size,1.0f);
|
||||
sprite->draw(0,0, 0, 1, 1, 0, 0);
|
||||
|
||||
glPopMatrix();
|
||||
p++;
|
||||
}
|
||||
|
||||
glPopAttrib();
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void ParticleSystem::update(float dt)
|
||||
{
|
||||
// Traverse all particles and update.
|
||||
particle * p = pStart;
|
||||
|
||||
// Make some more particles.
|
||||
if(active)
|
||||
{
|
||||
float rate = 1.0f / emissionRate; // the amount of time between each particle emit
|
||||
emitCounter += dt;
|
||||
while(emitCounter > rate)
|
||||
{
|
||||
add();
|
||||
emitCounter -= rate;
|
||||
}
|
||||
/*int particles = (int)(emissionRate * dt);
|
||||
for(int i = 0; i != particles; i++)
|
||||
add();*/
|
||||
|
||||
life -= dt;
|
||||
if(lifetime != -1 && life < 0)
|
||||
stop();
|
||||
}
|
||||
|
||||
while(p != pLast)
|
||||
{
|
||||
// Decrease lifespan.
|
||||
p->life -= dt;
|
||||
|
||||
if(p->life > 0)
|
||||
{
|
||||
|
||||
// Temp variables.
|
||||
love::Vector radial, tangential, gravity(0, p->gravity);
|
||||
love::Vector ppos(p->position[0], p->position[1]);
|
||||
|
||||
// Get vector from particle center to particle.
|
||||
radial = ppos - position;
|
||||
radial.normalize();
|
||||
tangential = radial;
|
||||
|
||||
// Resize radial acceleration.
|
||||
radial *= p->radialAcceleration;
|
||||
|
||||
// Calculate tangential acceleration.
|
||||
{
|
||||
float a = tangential.getX();
|
||||
tangential.setX(-tangential.getY());
|
||||
tangential.setY(a);
|
||||
}
|
||||
|
||||
// Resize tangential.
|
||||
tangential *= p->tangentialAcceleration;
|
||||
|
||||
// Update position.
|
||||
p->speed += (radial+tangential+gravity)*dt;
|
||||
|
||||
// Modify position.
|
||||
ppos += p->speed * dt;
|
||||
|
||||
p->position[0] = ppos.getX();
|
||||
p->position[1] = ppos.getY();
|
||||
|
||||
const float t = p->life / p->lifetime;
|
||||
|
||||
// Change size.
|
||||
p->size = p->sizeEnd - ((p->sizeEnd - p->sizeStart) * t);
|
||||
|
||||
// Rotate.
|
||||
p->rotation += (p->spinStart*(1-t) + p->spinEnd*t)*dt;
|
||||
|
||||
// Update color.
|
||||
p->color[0] = (float)(colorEnd.getRed()*(1.0f-t) + colorStart.getRed() * t)/255.0f;
|
||||
p->color[1] = (float)(colorEnd.getGreen()*(1.0f-t) + colorStart.getGreen() * t)/255.0f;
|
||||
p->color[2] = (float)(colorEnd.getBlue()*(1.0f-t) + colorStart.getBlue() * t)/255.0f;
|
||||
p->color[3] = (float)(colorEnd.getAlpha()*(1.0f-t) + colorStart.getAlpha() * t)/255.0f;
|
||||
|
||||
// Next particle.
|
||||
p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
remove(p);
|
||||
|
||||
if(p >= pLast)
|
||||
return;
|
||||
} // else
|
||||
} // while
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,432 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H
|
||||
#define LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H
|
||||
|
||||
// LOVE
|
||||
|
||||
#include <common/math.h>
|
||||
#include <common/Vector.h>
|
||||
#include <common/constants.h>
|
||||
#include <graphics/Drawable.h>
|
||||
|
||||
#include "Color.h"
|
||||
#include "Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// Represents a single particle.
|
||||
struct particle
|
||||
{
|
||||
float lifetime;
|
||||
float life;
|
||||
|
||||
float position[2];
|
||||
float direction;
|
||||
|
||||
love::Vector speed;
|
||||
float gravity;
|
||||
float radialAcceleration;
|
||||
float tangentialAcceleration;
|
||||
|
||||
float size;
|
||||
float sizeStart;
|
||||
float sizeEnd;
|
||||
|
||||
float rotation;
|
||||
float spinStart;
|
||||
float spinEnd;
|
||||
|
||||
float color[4];
|
||||
};
|
||||
|
||||
/**
|
||||
* A class for creating, moving and drawing particles.
|
||||
* A big thanks to bobthebloke.org
|
||||
**/
|
||||
class ParticleSystem : public Drawable
|
||||
{
|
||||
protected:
|
||||
|
||||
// The max amount of particles.
|
||||
unsigned int bufferSize;
|
||||
|
||||
// Pointer to the first particle.
|
||||
particle * pStart;
|
||||
|
||||
// Pointer to the next available free space.
|
||||
particle * pLast;
|
||||
|
||||
// Pointer to the end of the memory allocation.
|
||||
particle * pEnd;
|
||||
|
||||
// The sprite to be drawn.
|
||||
Image * sprite;
|
||||
|
||||
// Whether the particle emitter is active.
|
||||
bool active;
|
||||
|
||||
// The emission rate (particles/sec).
|
||||
int emissionRate;
|
||||
|
||||
// Used to determine when a particle should be emitted.
|
||||
float emitCounter;
|
||||
|
||||
// The relative position of the particle emitter.
|
||||
love::Vector position;
|
||||
|
||||
// The lifetime of the particle emitter (-1 means infinite) and the life it has left.
|
||||
float lifetime;
|
||||
float life;
|
||||
|
||||
// The particle life.
|
||||
float particleLifeMin;
|
||||
float particleLifeMax;
|
||||
|
||||
// The direction (and spread) the particles will be emitted in. Measured in radians.
|
||||
float direction;
|
||||
float spread;
|
||||
|
||||
// Whether the direction should be relative to the emitter's movement.
|
||||
bool relative;
|
||||
|
||||
// The speed.
|
||||
float speedMin;
|
||||
float speedMax;
|
||||
|
||||
// Acceleration towards the bottom of the screen
|
||||
float gravityMin;
|
||||
float gravityMax;
|
||||
|
||||
// Acceleration towards the emitter's center
|
||||
float radialAccelerationMin;
|
||||
float radialAccelerationMax;
|
||||
|
||||
// Acceleration perpendicular to the particle's direction.
|
||||
float tangentialAccelerationMin;
|
||||
float tangentialAccelerationMax;
|
||||
|
||||
// Size.
|
||||
float sizeStart;
|
||||
float sizeEnd;
|
||||
float sizeVariation;
|
||||
|
||||
// Rotation
|
||||
float rotationMin;
|
||||
float rotationMax;
|
||||
|
||||
// Spin.
|
||||
float spinStart;
|
||||
float spinEnd;
|
||||
float spinVariation;
|
||||
|
||||
// Color.
|
||||
Color colorStart;
|
||||
Color colorEnd;
|
||||
|
||||
void add();
|
||||
void remove(particle * p);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a particle system with the specified buffersize and sprite.
|
||||
**/
|
||||
ParticleSystem(Image * sprite, unsigned int buffer);
|
||||
|
||||
/**
|
||||
* Deletes any allocated memory.
|
||||
**/
|
||||
virtual ~ParticleSystem();
|
||||
|
||||
/**
|
||||
* Sets the sprite used in the particle system.
|
||||
* @param sprite The new sprite.
|
||||
**/
|
||||
void setSprite(Image * image);
|
||||
|
||||
/**
|
||||
* Clears the current buffer and allocates the appropriate amount of space for the buffer.
|
||||
* @param size The new buffer size.
|
||||
**/
|
||||
void setBufferSize(unsigned int size);
|
||||
|
||||
/**
|
||||
* Sets the emission rate.
|
||||
* @param rate The amount of particles per second.
|
||||
**/
|
||||
void setEmissionRate(int rate);
|
||||
|
||||
/**
|
||||
* Sets the lifetime of the particle emitter (-1 means eternal)
|
||||
* @param life The lifetime (in seconds).
|
||||
**/
|
||||
void setLifetime(float life);
|
||||
|
||||
/**
|
||||
* Sets the life range of the particles.
|
||||
* @param lifeMin The minimum life.
|
||||
* @param lifeMax The maximum life (if 0, then becomes the same as minimum life).
|
||||
**/
|
||||
void setParticleLife(float min, float max = 0);
|
||||
|
||||
/**
|
||||
* Sets the position of the center of the emitter and the direction (if set to relative).
|
||||
* Used to move the emitter without changing the position of already existing particles.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
void setPosition(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the direction and the spread of the particle emitter.
|
||||
* @param direction The direction (in degrees).
|
||||
**/
|
||||
void setDirection(float direction);
|
||||
|
||||
/**
|
||||
* Sets the spread of the particle emitter.
|
||||
* @param spread The spread (in degrees).
|
||||
**/
|
||||
void setSpread(float spread);
|
||||
|
||||
/**
|
||||
* Sets whether the direction should be relative to the particle emitters movement. Used in conjunction with setPosition.
|
||||
* @param relative Whether to have relative direction.
|
||||
**/
|
||||
void setRelativeDirection(bool relative);
|
||||
|
||||
/**
|
||||
* Sets the speed of the particles.
|
||||
* @param speed The speed.
|
||||
**/
|
||||
void setSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Sets the speed of the particles.
|
||||
* @param min The minimum speed.
|
||||
* @param max The maximum speed.
|
||||
**/
|
||||
void setSpeed(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the gravity of the particles (the acceleration along the y-axis).
|
||||
* @param gravity The amount of gravity.
|
||||
**/
|
||||
void setGravity(float gravity);
|
||||
|
||||
/**
|
||||
* Sets the gravity of the particles (the acceleration along the y-axis).
|
||||
* @param min The minimum gravity.
|
||||
* @param max The maximum gravity.
|
||||
**/
|
||||
void setGravity(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the radial acceleration (the acceleration towards the particle emitter).
|
||||
* @param acceleration The amount of acceleration.
|
||||
**/
|
||||
void setRadialAcceleration(float acceleration);
|
||||
|
||||
/**
|
||||
* Sets the radial acceleration (the acceleration towards the particle emitter).
|
||||
* @param min The minimum acceleration.
|
||||
* @param max The maximum acceleration.
|
||||
**/
|
||||
void setRadialAcceleration(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the tangential acceleration (the acceleration perpendicular to the particle's direction).
|
||||
* @param acceleration The amount of acceleration.
|
||||
**/
|
||||
void setTangentialAcceleration(float acceleration);
|
||||
|
||||
/**
|
||||
* Sets the tangential acceleration (the acceleration perpendicular to the particle's direction).
|
||||
* @param min The minimum acceleration.
|
||||
* @param max The maximum acceleration.
|
||||
**/
|
||||
void setTangentialAcceleration(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the size of the sprite (1.0 being the default size).
|
||||
* @param size The size of the sprite.
|
||||
**/
|
||||
void setSize(float size);
|
||||
|
||||
/**
|
||||
* Sets the size of the sprite upon creation and upon death (1.0 being the default size).
|
||||
* @param start The size of the sprite upon creation
|
||||
* @param end The size of the sprite upon death.
|
||||
**/
|
||||
void setSize(float start, float end);
|
||||
|
||||
/**
|
||||
* Sets the size of the sprite upon creation and upon death (1.0 being the default size) and any variation.
|
||||
* @param start The size of the sprite upon creation
|
||||
* @param end The size of the sprite upon death.
|
||||
* @param variation The amount of variation on the starting size (0 being no variation and 1.0 a random size between start and end).
|
||||
**/
|
||||
void setSize(float start, float end, float variation);
|
||||
|
||||
/**
|
||||
* Sets the amount of variation to the sprite's beginning size (0 being no variation and 1.0 a random size between start and end).
|
||||
* @param variation The amount of variation.
|
||||
**/
|
||||
void setSizeVariation(float variation);
|
||||
|
||||
/**
|
||||
* Sets the amount of rotation a sprite starts out with.
|
||||
* @param rotation The amount of rotation.
|
||||
**/
|
||||
void setRotation(float rotation);
|
||||
|
||||
/**
|
||||
* Sets the amount of rotation a sprite starts out with (a random value between min and max).
|
||||
* @param min The minimum amount of rotation.
|
||||
* @param max The maximum amount of rotation.
|
||||
**/
|
||||
void setRotation(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite.
|
||||
* @param spin The spin of the sprite (in degrees).
|
||||
**/
|
||||
void setSpin(float spin);
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite upon particle creation and death.
|
||||
* @param start The spin of the sprite upon creation (in degrees).
|
||||
* @param end The spin of the sprite upon death (in degrees).
|
||||
**/
|
||||
void setSpin(float start, float end);
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite upon particle creation and death and the variation.
|
||||
* @param start The spin of the sprite upon creation (in degrees).
|
||||
* @param end The spin of the sprite upon death (in degrees).
|
||||
* @param variation The variation of the start spin (0 being no variation and 1 beign a random spin between start and end).
|
||||
**/
|
||||
void setSpin(float start, float end, float variation);
|
||||
|
||||
/**
|
||||
* Sets the variation of the start spin (0 being no variation and 1 beign a random spin between start and end).
|
||||
* @param variation The variation in degrees.
|
||||
**/
|
||||
void setSpinVariation(float variation);
|
||||
|
||||
/**
|
||||
* Sets the color of the particles.
|
||||
* @param color The color.
|
||||
**/
|
||||
void setColor(Color * color);
|
||||
|
||||
/**
|
||||
* Sets the color of the particles.
|
||||
* @param start The color of the particle when created.
|
||||
* @param end The color of the particle upon death.
|
||||
**/
|
||||
void setColor(Color * start, Color * end);
|
||||
|
||||
/**
|
||||
* Returns the x-coordinate of the emitter's position.
|
||||
**/
|
||||
float getX() const;
|
||||
|
||||
/**
|
||||
* Returns the y-coordinate of the emitter's position.
|
||||
**/
|
||||
float getY() const;
|
||||
|
||||
/**
|
||||
* Returns the direction of the emitter (in degrees).
|
||||
**/
|
||||
float getDirection() const;
|
||||
|
||||
/**
|
||||
* Returns the directional spread of the emitter (in degrees).
|
||||
**/
|
||||
float getSpread() const;
|
||||
|
||||
/**
|
||||
* Returns the amount of particles that are currently active in the system.
|
||||
**/
|
||||
int count() const;
|
||||
|
||||
/**
|
||||
* Starts/resumes the particle emitter.
|
||||
**/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* Stops the particle emitter and resets.
|
||||
**/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* Pauses the particle emitter.
|
||||
**/
|
||||
void pause();
|
||||
|
||||
/**
|
||||
* Resets the particle emitter.
|
||||
**/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Returns whether the particle emitter is active.
|
||||
**/
|
||||
bool isActive() const;
|
||||
|
||||
/**
|
||||
* Returns whether the particle system is empty of particles or not.
|
||||
**/
|
||||
bool isEmpty() const;
|
||||
|
||||
/**
|
||||
* Returns whether the amount of particles has reached the buffer limit or not.
|
||||
**/
|
||||
bool isFull() const;
|
||||
|
||||
/**
|
||||
* Draws the particle emitter at the specified position.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
|
||||
/**
|
||||
* Updates the particle system.
|
||||
* @param dt Time since last update.
|
||||
**/
|
||||
void update(float dt);
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* 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 "SpriteBatch.h"
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
|
||||
// LOVE
|
||||
#include "VertexBuffer.h"
|
||||
#include "Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
SpriteBatch::SpriteBatch(Image * image, int size, int usage)
|
||||
: size(size), next(0)
|
||||
{
|
||||
// Four vertices in one sprite.
|
||||
buffer = new VertexBuffer(image, size*6, TYPE_TRIANGLES, usage);
|
||||
}
|
||||
|
||||
SpriteBatch::~SpriteBatch()
|
||||
{
|
||||
buffer->release();
|
||||
}
|
||||
|
||||
void SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, float oy)
|
||||
{
|
||||
// Only do this if there's a free slot.
|
||||
if(next < size)
|
||||
{
|
||||
// Get a pointer to the correct insertion position.
|
||||
vertex * v = buffer->vertices + next*6;
|
||||
|
||||
// Fill vertices with ones (for white colors).
|
||||
memset(v, 0xff, sizeof(vertex)*6);
|
||||
|
||||
// Half-sizes.
|
||||
float w2 = buffer->image->getWidth()/2.0f;
|
||||
float h2 = buffer->image->getHeight()/2.0f;
|
||||
|
||||
// MASSIVE TODO: just copy vertices from image.
|
||||
|
||||
v[0].x = -w2; v[0].y = -h2;
|
||||
v[1].x = -w2; v[1].y = h2;
|
||||
v[2].x = w2; v[2].y = h2;
|
||||
v[3].x = w2; v[3].y = -h2;
|
||||
|
||||
v[0].s = 0; v[0].t = 0;
|
||||
v[1].s = 0; v[1].t = 1;
|
||||
v[2].s = 1; v[2].t = 1;
|
||||
v[3].s = 1; v[3].t = 0;
|
||||
|
||||
// Transform.
|
||||
Matrix t;
|
||||
t.translate(x, y);
|
||||
t.scale(sx, sy);
|
||||
t.rotate(a);
|
||||
t.transform(v, v, 4);
|
||||
|
||||
v[5] = v[3];
|
||||
v[4] = v[2];
|
||||
v[3] = v[0];
|
||||
|
||||
// Send the buffer to the GPU.
|
||||
buffer->update(next*6, 6);
|
||||
|
||||
// Increment counter.
|
||||
next++;
|
||||
}
|
||||
}
|
||||
|
||||
void SpriteBatch::clear()
|
||||
{
|
||||
// Reset the position of the next index.
|
||||
next = 0;
|
||||
|
||||
// Also reset the buffer.
|
||||
buffer->clear();
|
||||
}
|
||||
|
||||
void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const
|
||||
{
|
||||
// Let the buffer handle this.
|
||||
buffer->draw(x, y, angle, sx, sy, ox, oy);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
#define LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
|
||||
// C
|
||||
#include <cstring>
|
||||
|
||||
// LOVE
|
||||
#include <common/math.h>
|
||||
#include <common/Object.h>
|
||||
#include <common/Vector.h>
|
||||
#include <common/Matrix.h>
|
||||
#include <graphics/Drawable.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
// Forward declarations.
|
||||
class VertexBuffer;
|
||||
class Image;
|
||||
|
||||
class SpriteBatch : public Drawable
|
||||
{
|
||||
private:
|
||||
|
||||
// Max number of sprites in the batch.
|
||||
int size;
|
||||
|
||||
// The next free element.
|
||||
int next;
|
||||
|
||||
// Vertex Buffer.
|
||||
VertexBuffer * buffer;
|
||||
|
||||
public:
|
||||
|
||||
SpriteBatch(Image * image, int size, int usage);
|
||||
virtual ~SpriteBatch();
|
||||
|
||||
void add(float x, float y, float a, float sx, float sy, float ox, float oy);
|
||||
void clear();
|
||||
|
||||
// Implements Drawable.
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
|
||||
}; // SpriteBatch
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
@@ -0,0 +1,255 @@
|
||||
/**
|
||||
* 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 "TrueTypeFont.h"
|
||||
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
inline int TrueTypeFont::next_p2(int num)
|
||||
{
|
||||
int powered = 2;
|
||||
while(powered < num) powered <<= 1;
|
||||
return powered;
|
||||
}
|
||||
|
||||
inline void TrueTypeFont::pushScreenCoordinateMatrix()
|
||||
{
|
||||
glPushAttrib(GL_TRANSFORM_BIT);
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluOrtho2D(viewport[0],viewport[2],viewport[1],viewport[3]);
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
inline void TrueTypeFont::popProjectionMatrix()
|
||||
{
|
||||
glPushAttrib(GL_TRANSFORM_BIT);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
void TrueTypeFont::createList(FT_Face face, unsigned short character)
|
||||
{
|
||||
if( FT_Load_Glyph(face, FT_Get_Char_Index(face, character), FT_LOAD_DEFAULT) )
|
||||
std::cerr << "TrueTypeFont Loading vm->error: FT_Load_Glyph failed." << std::endl;
|
||||
|
||||
FT_Glyph glyph;
|
||||
if( FT_Get_Glyph(face->glyph, &glyph) )
|
||||
std::cerr << "TrueTypeFont Loading vm->error: FT_Get_Glyph failed." << std::endl;
|
||||
|
||||
FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1);
|
||||
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
|
||||
|
||||
FT_Bitmap& bitmap = bitmap_glyph->bitmap; //just to make things easier
|
||||
|
||||
widths[character] = face->glyph->advance.x >> 6;
|
||||
int w = next_p2(bitmap.width);
|
||||
int h = next_p2(bitmap.rows);
|
||||
|
||||
if(bitmap.rows > trueHeight)
|
||||
trueHeight = bitmap.rows;
|
||||
|
||||
GLubyte* expandedData = new GLubyte[ 2 * w * h];
|
||||
|
||||
for(int j = 0; j < h; j++) for(int i = 0; i < w; i++)
|
||||
{
|
||||
expandedData[2 * (i + j * w)] = MAX_CHARS-1;
|
||||
expandedData[2 * (i + j * w) + 1] = (i >= bitmap.width || j >= bitmap.rows) ? 0 : bitmap.buffer[i + bitmap.width * j];
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[character]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
// Rude adds:
|
||||
// (You're welcome, Mike.)
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expandedData);
|
||||
|
||||
|
||||
|
||||
delete [] expandedData; //no longer needed
|
||||
|
||||
glNewList(list + character, GL_COMPILE);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[character]);
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef((float)bitmap_glyph->left, -(float)bitmap_glyph->top, 0);
|
||||
//glTranslatef(0, (float)bitmap_glyph->top-bitmap.rows, 0);
|
||||
|
||||
float x=(float)bitmap.width / (float)w,
|
||||
y=(float)bitmap.rows / (float)h;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2d(0, 0); glVertex2f(0, 0);
|
||||
glTexCoord2d(0, y); glVertex2f(0, (float)bitmap.rows);
|
||||
glTexCoord2d(x, y); glVertex2f((float)bitmap.width, (float)bitmap.rows);
|
||||
glTexCoord2d(x, 0); glVertex2f((float)bitmap.width, 0);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
glTranslatef((float)(face->glyph->advance.x >> 6) ,0,0);
|
||||
|
||||
glEndList();
|
||||
|
||||
FT_Done_Glyph(glyph);
|
||||
}
|
||||
|
||||
TrueTypeFont::TrueTypeFont(love::filesystem::File * file, int size)
|
||||
: Font(size), file(file), textures(0), list(0)
|
||||
{
|
||||
file->retain();
|
||||
}
|
||||
|
||||
TrueTypeFont::~TrueTypeFont()
|
||||
{
|
||||
unload();
|
||||
file->release();
|
||||
}
|
||||
|
||||
void TrueTypeFont::print(string text, float x, float y) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(ceil(x), ceil(y), 0.0f); // + getHeight() to make the x,y coordiantes the top left corner
|
||||
GLuint TrueTypeFont = list;
|
||||
glListBase(TrueTypeFont);
|
||||
glCallLists((int)text.length(), GL_UNSIGNED_BYTE, text.c_str());
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void TrueTypeFont::print(std::string text, float x, float y, float angle, float sx, float sy) const
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef(ceil(x), ceil(y), 0.0f);
|
||||
glRotatef(angle, 0, 0, 1.0f);
|
||||
glScalef(sx, sy, 1.0f);
|
||||
|
||||
GLuint TrueTypeFont = list;
|
||||
glListBase(TrueTypeFont);
|
||||
glCallLists((int)text.length(), GL_UNSIGNED_BYTE, text.c_str());
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void TrueTypeFont::print(char character, float x, float y) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(ceil(x), ceil(y), 0.0f);
|
||||
GLuint TrueTypeFont = list;
|
||||
glListBase(TrueTypeFont);
|
||||
glCallList(list + (int)character);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
float TrueTypeFont::getHeight() const
|
||||
{
|
||||
return (float)trueHeight;
|
||||
}
|
||||
|
||||
float TrueTypeFont::getLineHeight() const
|
||||
{
|
||||
return Font::getLineHeight() * 1.25f;
|
||||
}
|
||||
|
||||
bool TrueTypeFont::load()
|
||||
{
|
||||
return loadVolatile();
|
||||
}
|
||||
|
||||
void TrueTypeFont::unload()
|
||||
{
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
bool TrueTypeFont::loadVolatile()
|
||||
{
|
||||
Data * data = file->read();
|
||||
|
||||
trueHeight = size;
|
||||
|
||||
|
||||
textures = (unsigned int *)(new GLuint[MAX_CHARS]);
|
||||
for(unsigned int i = 0; i != MAX_CHARS; i++) widths[i] = 0;
|
||||
|
||||
FT_Library library;
|
||||
if( FT_Init_FreeType(&library) )
|
||||
std::cerr << "TrueTypeFont Loading error: FT_Init_FreeType failed." << std::endl;
|
||||
|
||||
FT_Face face;
|
||||
if( FT_New_Memory_Face( library,
|
||||
(const FT_Byte *)data->getData(), /* first byte in memory */
|
||||
data->getSize(), /* size in bytes */
|
||||
0, /* face_index */
|
||||
&face ))
|
||||
std::cerr << "TrueTypeFont Loading error: FT_New_Face failed (there is probably a problem with your font file)." << std::endl;
|
||||
//FT_Set_Char_Size(face, size << 6, size << 6, 96, 96);
|
||||
FT_Set_Pixel_Sizes(face, size, size);
|
||||
|
||||
list = glGenLists(MAX_CHARS);
|
||||
glGenTextures(MAX_CHARS, (GLuint*)textures);
|
||||
for(unsigned short i = 0; i < MAX_CHARS; i++)
|
||||
createList(face, i);
|
||||
|
||||
FT_Done_Face(face);
|
||||
FT_Done_FreeType(library); //all done
|
||||
|
||||
// Free data.
|
||||
data->release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TrueTypeFont::unloadVolatile()
|
||||
{
|
||||
if(list != 0)
|
||||
glDeleteLists(list, MAX_CHARS);
|
||||
if(textures != 0)
|
||||
glDeleteTextures(MAX_CHARS, (const GLuint*)textures);
|
||||
|
||||
// Cleanup plz.
|
||||
if(textures != 0)
|
||||
delete [] textures;
|
||||
textures = 0;
|
||||
list = 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_TRUETYPE_FONT_H
|
||||
#define LOVE_GRAPHICS_OPENGL_TRUETYPE_FONT_H
|
||||
|
||||
// Module
|
||||
#include "Font.h"
|
||||
|
||||
// FreeType2
|
||||
#include <ft2build.h>
|
||||
#include <freetype/freetype.h>
|
||||
#include <freetype/ftglyph.h>
|
||||
#include <freetype/ftoutln.h>
|
||||
#include <freetype/fttrigon.h>
|
||||
|
||||
// STD
|
||||
#include <string>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* A class to handle TrueType fonts. Uses the library FreeType2
|
||||
* (available here: http://www.freetype.org/) and takes use of both
|
||||
* their local documentation and Sven's experience.
|
||||
*
|
||||
* @author Michael Enger (with great help from Sven C. Olsen)
|
||||
* @date 2007-01-15
|
||||
**/
|
||||
class TrueTypeFont : public Font
|
||||
{
|
||||
private:
|
||||
|
||||
love::filesystem::File * file;
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int * textures;
|
||||
unsigned int list;
|
||||
int trueHeight; // the true height of the font
|
||||
|
||||
/**
|
||||
* Returns the closest number to num which is a power of two.
|
||||
*
|
||||
* @param num The number to be 2powered.
|
||||
**/
|
||||
inline int next_p2(int num);
|
||||
|
||||
/**
|
||||
* As stated by Sven: A fairly straight forward function that pushes a projection matrix that will make object world coordinates identical to window coordinates.
|
||||
**/
|
||||
inline void pushScreenCoordinateMatrix();
|
||||
|
||||
/**
|
||||
* Pops the projection matrix without changing the current MatrixMode.
|
||||
**/
|
||||
inline void popProjectionMatrix();
|
||||
|
||||
/**
|
||||
* Creates an OpenGL display list for the character (for speedy execution).
|
||||
*
|
||||
* @param face The FT_Face containing information about the character.
|
||||
* @param character The character in question.
|
||||
**/
|
||||
void createList(FT_Face face, unsigned short character);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param file The file containing the TrueTypeFont data.
|
||||
* @param size The size of the TrueTypeFont.
|
||||
**/
|
||||
TrueTypeFont(love::filesystem::File * file, int size);
|
||||
|
||||
/**
|
||||
* Calls unload().
|
||||
**/
|
||||
virtual ~TrueTypeFont();
|
||||
|
||||
|
||||
// From Font
|
||||
//virtual float getHeight() const;
|
||||
virtual void print(std::string text, float x, float y) const;
|
||||
virtual void print(std::string text, float x, float y, float angle, float sx, float sy) const;
|
||||
virtual void print(char character, float x, float y) const;
|
||||
virtual float getHeight() const;
|
||||
virtual float getLineHeight() const;
|
||||
|
||||
// From Resource.
|
||||
bool load();
|
||||
void unload();
|
||||
|
||||
// From Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
}; // TrueTypeFont
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_TRUETYPE_FONT_H
|
||||
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
* 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 "VertexBuffer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
VertexBuffer::VertexBuffer(Image * image, int size, int type, int usage)
|
||||
: size(size), next(0), image(image), vbo_buf(0), type(type), gl_type(0), usage(usage), gl_usage(0)
|
||||
{
|
||||
if(image != 0)
|
||||
image->retain();
|
||||
|
||||
vertices = new vertex[size];
|
||||
|
||||
// If VBOs aren't supported, then we must use vertex arrays.
|
||||
if(!GLEE_ARB_vertex_buffer_object)
|
||||
usage = USAGE_ARRAY;
|
||||
|
||||
// Find out which OpenGL VBO usage hint to use.
|
||||
gl_usage = (usage == USAGE_DYNAMIC) ? GL_DYNAMIC_DRAW : gl_usage;
|
||||
gl_usage = (usage == USAGE_STATIC) ? GL_STATIC_DRAW : gl_usage;
|
||||
gl_usage = (usage == USAGE_STREAM) ? GL_STREAM_DRAW : gl_usage;
|
||||
|
||||
setType(type);
|
||||
|
||||
if(useVBO())
|
||||
{
|
||||
glGenBuffers(1, &vbo_buf);
|
||||
if(vbo_buf != 0)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_buf);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex)*size, vertices, gl_usage);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
else // FAIL. Use vertex arrays instead.
|
||||
usage = USAGE_ARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
VertexBuffer::~VertexBuffer()
|
||||
{
|
||||
if(image != 0)
|
||||
image->release();
|
||||
|
||||
delete [] vertices;
|
||||
|
||||
if(useVBO() && vbo_buf != 0)
|
||||
glDeleteBuffers(1, &vbo_buf);
|
||||
}
|
||||
|
||||
bool VertexBuffer::useVBO() const
|
||||
{
|
||||
return usage >= USAGE_DYNAMIC;
|
||||
}
|
||||
|
||||
void VertexBuffer::update(int pos, int size)
|
||||
{
|
||||
// Update VBO.
|
||||
if(useVBO())
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_buf);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, pos*sizeof(vertex), sizeof(vertex)*size, &vertices[pos]);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
// ... no need to update vertex arrays.
|
||||
|
||||
next += size;
|
||||
}
|
||||
|
||||
void VertexBuffer::setType(int type)
|
||||
{
|
||||
this->type = type;
|
||||
// Find out which OpenGL primitive type to use.
|
||||
gl_type = (type == TYPE_POINTS) ? GL_POINTS : gl_type;
|
||||
gl_type = (type == TYPE_LINES) ? GL_LINES : gl_type;
|
||||
gl_type = (type == TYPE_LINE_STRIP) ? GL_LINE_STRIP : gl_type;
|
||||
gl_type = (type == TYPE_TRIANGLES) ? GL_TRIANGLES : gl_type;
|
||||
gl_type = (type == TYPE_TRIANGLE_STRIP) ? GL_TRIANGLE_STRIP : gl_type;
|
||||
gl_type = (type == TYPE_TRIANGLE_FAN) ? GL_TRIANGLE_FAN : gl_type;
|
||||
}
|
||||
|
||||
int VertexBuffer::getType() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
void VertexBuffer::add(float x, float y, float s, float t, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
|
||||
{
|
||||
// Only do this if there's a free slot.
|
||||
if(next < size)
|
||||
{
|
||||
vertex & e = vertices[next];
|
||||
|
||||
e.x = x;
|
||||
e.y = y;
|
||||
e.s = s;
|
||||
e.t = t;
|
||||
e.r = r;
|
||||
e.g = g;
|
||||
e.b = b;
|
||||
e.a = a;
|
||||
|
||||
update(next, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexBuffer::add(float x, float y, float s, float t)
|
||||
{
|
||||
add(x, y, s, y, 255, 255, 255, 255);
|
||||
}
|
||||
|
||||
void VertexBuffer::clear()
|
||||
{
|
||||
// Reset the position of the next index.
|
||||
next = 0;
|
||||
}
|
||||
|
||||
void VertexBuffer::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, 0);
|
||||
|
||||
if(image == 0)
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
else
|
||||
image->bind();
|
||||
|
||||
// Enable vertex arrays.
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
if(useVBO())
|
||||
{
|
||||
// Bind the VBO buffer.
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_buf);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid*)0);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)(sizeof(unsigned char)*4));
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)(sizeof(unsigned char)*4+sizeof(float)*2));
|
||||
glDrawArrays(gl_type, 0, next);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid*)&vertices[0].r);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].s);
|
||||
glDrawArrays(gl_type, 0, next);
|
||||
}
|
||||
|
||||
// Disable vertex arrays.
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
// Enable textures again.
|
||||
if(image == 0)
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_VERTEX_BUFFER_H
|
||||
#define LOVE_GRAPHICS_OPENGL_VERTEX_BUFFER_H
|
||||
|
||||
// LOVE
|
||||
#include <common/constants.h>
|
||||
#include <common/math.h>
|
||||
#include <common/Object.h>
|
||||
#include <common/Vector.h>
|
||||
#include <common/Matrix.h>
|
||||
#include <graphics/Drawable.h>
|
||||
|
||||
// Module.
|
||||
#include "Image.h"
|
||||
|
||||
// OpenGL
|
||||
#include "GLee.h"
|
||||
#include <SDL/SDL_opengl.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
class VertexBuffer : public Drawable
|
||||
{
|
||||
friend class SpriteBatch;
|
||||
private:
|
||||
|
||||
vertex * vertices;
|
||||
|
||||
// Max number of vertices in the buffer.
|
||||
int size;
|
||||
|
||||
// The next free element.
|
||||
int next;
|
||||
|
||||
// The texture (optional).
|
||||
Image * image;
|
||||
|
||||
// Contains the vbo_buffer.
|
||||
GLuint vbo_buf;
|
||||
|
||||
// The uage hint for the vertex buffer.
|
||||
int usage;
|
||||
int gl_usage;
|
||||
|
||||
// The type of primitives we're drawing.
|
||||
int type;
|
||||
int gl_type;
|
||||
|
||||
private:
|
||||
|
||||
bool useVBO() const;
|
||||
void update(int pos, int size);
|
||||
|
||||
public:
|
||||
|
||||
VertexBuffer(Image * image, int size, int type, int usage);
|
||||
virtual ~VertexBuffer();
|
||||
|
||||
void setType(int type);
|
||||
int getType() const;
|
||||
|
||||
void add(float x, float y, float s, float t, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
||||
void add(float x, float y, float s, float t);
|
||||
void clear();
|
||||
|
||||
// Implements Drawable.
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
|
||||
}; // VertexBuffer
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_VERTEX_BUFFER_H
|
||||
@@ -0,0 +1,161 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Animation.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Animation * luax_checkanimation(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Animation>(L, idx, "Animation", LOVE_GRAPHICS_ANIMATION_BITS);
|
||||
}
|
||||
|
||||
int _wrap_Animation_addFrame(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float w = (float)luaL_checknumber(L, 4);
|
||||
float h = (float)luaL_checknumber(L, 5);
|
||||
float d = (float)luaL_checknumber(L, 6);
|
||||
t->addFrame(x, y, w, h, d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_play(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
t->play();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_stop(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
t->stop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_reset(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
t->reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_seek(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
int frame = luaL_checkint(L, 2);
|
||||
t->seek(frame);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_getCurrentFrame(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
lua_pushnumber(L, t->getCurrentFrame());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Animation_getSize(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
lua_pushnumber(L, t->getSize());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Animation_setDelay(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
int frame = luaL_checkint(L, 2);
|
||||
float delay = (float)luaL_checknumber(L, 3);
|
||||
t->setDelay(frame, delay);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_setSpeed(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
float speed = (float)luaL_checknumber(L, 2);
|
||||
t->setSpeed(speed);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_getSpeed(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
lua_pushnumber(L, t->getSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Animation_update(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
float dt = (float)luaL_checknumber(L, 2);
|
||||
t->update(dt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_getWidth(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
lua_pushnumber(L, t->getWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Animation_getHeight(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
lua_pushnumber(L, t->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Animation_functions[] = {
|
||||
{ "addFrame", _wrap_Animation_addFrame },
|
||||
{ "play", _wrap_Animation_play },
|
||||
{ "stop", _wrap_Animation_stop },
|
||||
{ "reset", _wrap_Animation_reset },
|
||||
{ "seek", _wrap_Animation_seek },
|
||||
{ "getCurrentFrame", _wrap_Animation_getCurrentFrame },
|
||||
{ "getSize", _wrap_Animation_getSize },
|
||||
{ "setDelay", _wrap_Animation_setDelay },
|
||||
{ "setSpeed", _wrap_Animation_setSpeed },
|
||||
{ "getSpeed", _wrap_Animation_getSpeed },
|
||||
{ "update", _wrap_Animation_update },
|
||||
{ "getWidth", _wrap_Animation_getWidth },
|
||||
{ "getHeight", _wrap_Animation_getHeight },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Animation_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Animation", wrap_Animation_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_ANIMATION_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_ANIMATION_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Animation.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Animation * luax_checkanimation(lua_State * L, int idx);
|
||||
int _wrap_Animation_addFrame(lua_State * L);
|
||||
int _wrap_Animation_play(lua_State * L);
|
||||
int _wrap_Animation_stop(lua_State * L);
|
||||
int _wrap_Animation_reset(lua_State * L);
|
||||
int _wrap_Animation_seek(lua_State * L);
|
||||
int _wrap_Animation_getCurrentFrame(lua_State * L);
|
||||
int _wrap_Animation_getSize(lua_State * L);
|
||||
int _wrap_Animation_setDelay(lua_State * L);
|
||||
int _wrap_Animation_setSpeed(lua_State * L);
|
||||
int _wrap_Animation_getSpeed(lua_State * L);
|
||||
int _wrap_Animation_update(lua_State * L);
|
||||
int _wrap_Animation_getWidth(lua_State * L);
|
||||
int _wrap_Animation_getHeight(lua_State * L);
|
||||
int wrap_Animation_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_ANIMATION_H
|
||||
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Color.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
// This macro makes checking for the correct type slightly more compact.
|
||||
Color * luax_checkcolor(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Color>(L, idx, "Color", LOVE_GRAPHICS_COLOR_BITS);
|
||||
}
|
||||
|
||||
int _wrap_Color_setRed(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
int arg = luaL_checkinteger(L, 2);
|
||||
t->setRed(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Color_setGreen(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
int arg = luaL_checkinteger(L, 2);
|
||||
t->setGreen(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Color_setBlue(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
int arg = luaL_checkinteger(L, 2);
|
||||
t->setBlue(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Color_setAlpha(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
int arg = luaL_checkinteger(L, 2);
|
||||
t->setAlpha(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Color_getRed(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
lua_pushinteger(L, t->getRed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Color_getGreen(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
lua_pushinteger(L, t->getGreen());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Color_getBlue(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
lua_pushinteger(L, t->getBlue());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Color_getAlpha(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
lua_pushinteger(L, t->getAlpha());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Color_functions[] = {
|
||||
{ "setRed", _wrap_Color_setRed },
|
||||
{ "setGreen", _wrap_Color_setGreen },
|
||||
{ "setBlue", _wrap_Color_setBlue },
|
||||
{ "setAlpha", _wrap_Color_setAlpha },
|
||||
{ "getRed", _wrap_Color_getRed },
|
||||
{ "getGreen", _wrap_Color_getGreen },
|
||||
{ "getBlue", _wrap_Color_getBlue },
|
||||
{ "getAlpha", _wrap_Color_getAlpha },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Color_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Color", wrap_Color_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_COLOR_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_COLOR_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Color.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Color * luax_checkcolor(lua_State * L, int idx);
|
||||
int _wrap_Color_setRed(lua_State * L);
|
||||
int _wrap_Color_setGreen(lua_State * L);
|
||||
int _wrap_Color_setBlue(lua_State * L);
|
||||
int _wrap_Color_setAlpha(lua_State * L);
|
||||
int _wrap_Color_getRed(lua_State * L);
|
||||
int _wrap_Color_getGreen(lua_State * L);
|
||||
int _wrap_Color_getBlue(lua_State * L);
|
||||
int _wrap_Color_getAlpha(lua_State * L);
|
||||
int wrap_Color_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_COLOR_H
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Font.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
// This macro makes checking for the correct type slightly more compact.
|
||||
Font * luax_checkfont(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Font>(L, idx, "Font", LOVE_GRAPHICS_FONT_BITS);
|
||||
}
|
||||
|
||||
int _wrap_Font_getHeight(lua_State * L)
|
||||
{
|
||||
Font * t = luax_checkfont(L, 1);
|
||||
lua_pushnumber(L, t->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Font_getWidth(lua_State * L)
|
||||
{
|
||||
Font * t = luax_checkfont(L, 1);
|
||||
const char * str = luaL_checkstring(L, 2);
|
||||
lua_pushnumber(L, t->getWidth(str));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Font_setLineHeight(lua_State * L)
|
||||
{
|
||||
Font * t = luax_checkfont(L, 1);
|
||||
float h = (float)luaL_checknumber(L, 2);
|
||||
t->setLineHeight(h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Font_getLineHeight(lua_State * L)
|
||||
{
|
||||
Font * t = luax_checkfont(L, 1);
|
||||
lua_pushnumber(L, t->getLineHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Font_functions[] = {
|
||||
{ "getHeight", _wrap_Font_getHeight },
|
||||
{ "getWidth", _wrap_Font_getWidth },
|
||||
{ "setLineHeight", _wrap_Font_setLineHeight },
|
||||
{ "getLineHeight", _wrap_Font_getLineHeight },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Font_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Font", wrap_Font_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Font.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Font * luax_checkfont(lua_State * L, int idx);
|
||||
int _wrap_Font_getHeight(lua_State * L);
|
||||
int _wrap_Font_getWidth(lua_State * L);
|
||||
int _wrap_Font_setLineHeight(lua_State * L);
|
||||
int _wrap_Font_getLineHeight(lua_State * L);
|
||||
int wrap_Font_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Frame.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Frame * luax_checkframe(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Frame>(L, idx, "Frame", LOVE_GRAPHICS_FRAME_BITS);
|
||||
}
|
||||
|
||||
int _wrap_Frame_flip(lua_State *L)
|
||||
{
|
||||
Frame *frame = luax_checktype<Frame>(L, 1, "Frame", LOVE_GRAPHICS_FRAME_BITS);
|
||||
frame->flip(luax_toboolean(L, 2), luax_toboolean(L, 3));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Frame_functions[] = {
|
||||
{ "flip", _wrap_Frame_flip },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Frame_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Frame", wrap_Frame_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_FRAME_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_FRAME_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Frame.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Frame * luax_checkframe(lua_State * L, int idx);
|
||||
int _wrap_Frame_flip(lua_State *L);
|
||||
int wrap_Frame_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_FRAME_H
|
||||
@@ -0,0 +1,850 @@
|
||||
/**
|
||||
* 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 "wrap_Graphics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
static Graphics * instance = 0;
|
||||
|
||||
int _wrap_checkMode(lua_State * L)
|
||||
{
|
||||
int w = luaL_checkint(L, 1);
|
||||
int h = luaL_checkint(L, 2);
|
||||
bool fs = luax_toboolean(L, 3);
|
||||
luax_pushboolean(L, instance->checkMode(w, h, fs));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setMode(lua_State * L)
|
||||
{
|
||||
int w = luaL_checkint(L, 1);
|
||||
int h = luaL_checkint(L, 2);
|
||||
bool fs = luax_optboolean(L, 3, false);
|
||||
bool vsync = luax_optboolean(L, 4, true);
|
||||
int fsaa = luaL_optint(L, 5, 0);
|
||||
luax_pushboolean(L, instance->setMode(w, h, fs, vsync, fsaa));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_toggleFullscreen(lua_State * L)
|
||||
{
|
||||
luax_pushboolean(L, instance->toggleFullscreen());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_reset(lua_State * L)
|
||||
{
|
||||
instance->reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_clear(lua_State * L)
|
||||
{
|
||||
instance->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_present(lua_State * L)
|
||||
{
|
||||
instance->present();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setCaption(lua_State * L)
|
||||
{
|
||||
const char * str = luaL_checkstring(L, 1);
|
||||
instance->setCaption(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getCaption(lua_State * L)
|
||||
{
|
||||
return instance->getCaption(L);
|
||||
}
|
||||
|
||||
int _wrap_getWidth(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getHeight(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_isCreated(lua_State * L)
|
||||
{
|
||||
luax_pushboolean(L, instance->isCreated());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getModes(lua_State * L)
|
||||
{
|
||||
return instance->getModes(L);
|
||||
}
|
||||
|
||||
int _wrap_setScissor(lua_State * L)
|
||||
{
|
||||
if(lua_gettop(L) == 0)
|
||||
{
|
||||
instance->setScissor();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int x = luaL_checkint(L, 1);
|
||||
int y = luaL_checkint(L, 2);
|
||||
int w = luaL_checkint(L, 3);
|
||||
int h = luaL_checkint(L, 4);
|
||||
|
||||
instance->setScissor(x, y, w, h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getScissor(lua_State * L)
|
||||
{
|
||||
return instance->getScissor(L);
|
||||
}
|
||||
|
||||
int _wrap_newColor(lua_State * L)
|
||||
{
|
||||
int r = luaL_checkinteger(L, 1);
|
||||
int g = luaL_checkinteger(L, 2);
|
||||
int b = luaL_checkinteger(L, 3);
|
||||
int a = luaL_optint(L, 4, 255);
|
||||
|
||||
Color * t = instance->newColor(r, g, b, a);
|
||||
|
||||
luax_newtype(L, "Color", LOVE_GRAPHICS_COLOR_BITS, (void*)t);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newImage(lua_State * L)
|
||||
{
|
||||
// Convert to File, if necessary.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_strtofile(L, 1);
|
||||
|
||||
// Convert to ImageData, if necessary.
|
||||
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
|
||||
luax_convobj(L, 1, "image", "newImageData");
|
||||
|
||||
love::image::ImageData * data = luax_checktype<love::image::ImageData>(L, 1, "ImageData", LOVE_IMAGE_IMAGE_DATA_BITS);
|
||||
|
||||
// Create the image.
|
||||
Image * image = instance->newImage(data);
|
||||
|
||||
if(image == 0)
|
||||
return luaL_error(L, "Could not load image.");
|
||||
|
||||
|
||||
// Push the type.
|
||||
luax_newtype(L, "Image", LOVE_GRAPHICS_IMAGE_BITS, (void*)image);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newFrame(lua_State * L)
|
||||
{
|
||||
int x = luaL_checkint(L, 1);
|
||||
int y = luaL_checkint(L, 2);
|
||||
int w = luaL_checkint(L, 3);
|
||||
int h = luaL_checkint(L, 4);
|
||||
int sw = luaL_checkint(L, 5);
|
||||
int sh = luaL_checkint(L, 6);
|
||||
|
||||
Frame * frame = instance->newFrame(x, y, w, h, sw, sh);
|
||||
|
||||
if (frame == 0)
|
||||
return luaL_error(L, "Could not create frame.");
|
||||
|
||||
luax_newtype(L, "Frame", LOVE_GRAPHICS_FRAME_BITS, (void*)frame);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newAnimation(lua_State * L)
|
||||
{
|
||||
// If string -> file
|
||||
if(lua_isstring(L, 1))
|
||||
luax_strtofile(L, 1);
|
||||
|
||||
// file -> imagedata
|
||||
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
|
||||
luax_convobj(L, 1, "image", "newImageData");
|
||||
|
||||
// imagedata -> image
|
||||
if(luax_istype(L, 1, LOVE_IMAGE_IMAGE_DATA_BITS))
|
||||
luax_convobj(L, 1, "graphics", "newImage");
|
||||
|
||||
// Check the value.
|
||||
Image * image = luax_checktype<Image>(L, 1, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
|
||||
Animation * animation = 0;
|
||||
|
||||
if(lua_gettop(L) == 1)
|
||||
{
|
||||
animation = instance->newAnimation(image);
|
||||
}
|
||||
else
|
||||
{
|
||||
float fw = (float)luaL_checknumber(L, 2);
|
||||
float fh = (float)luaL_checknumber(L, 3);
|
||||
float delay = (float)luaL_checknumber(L, 4);
|
||||
int num = luaL_optint(L, 5, 0);
|
||||
animation = instance->newAnimation(image, fw, fh, delay, num);
|
||||
}
|
||||
|
||||
if(animation == 0)
|
||||
return luaL_error(L, "Could not load the Animation");
|
||||
|
||||
luax_newtype(L, "Animation", LOVE_GRAPHICS_ANIMATION_BITS, (void*)animation);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newFont(lua_State * L)
|
||||
{
|
||||
// Convert to File, if necessary.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_strtofile(L, 1);
|
||||
|
||||
// Check the value.
|
||||
love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", LOVE_FILESYSTEM_FILE_BITS);
|
||||
|
||||
// Second optional parameter can be a number:
|
||||
int size = luaL_optint(L, 2, 12);
|
||||
|
||||
Font * font = instance->newFont(file, size);
|
||||
|
||||
if(font == 0)
|
||||
return luaL_error(L, "Could not load the font");
|
||||
|
||||
luax_newtype(L, "Font", LOVE_GRAPHICS_FONT_BITS, (void*)font);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newImageFont(lua_State * L)
|
||||
{
|
||||
// Convert to File, if necessary.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_strtofile(L, 1);
|
||||
|
||||
// Convert to Image, if necessary.
|
||||
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
|
||||
luax_convobj(L, 1, "graphics", "newImage");
|
||||
|
||||
// Check the value.
|
||||
Image * image = luax_checktype<Image>(L, 1, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
|
||||
const char * glyphs = luaL_checkstring(L, 2);
|
||||
|
||||
Font * font = instance->newImageFont(image, glyphs);
|
||||
|
||||
if(font == 0)
|
||||
return luaL_error(L, "Could not load the font");
|
||||
|
||||
luax_newtype(L, "Font", LOVE_GRAPHICS_FONT_BITS, (void*)font);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newSpriteBatch(lua_State * L)
|
||||
{
|
||||
Image * image = luax_checktype<Image>(L, 1, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
int size = luaL_optint(L, 2, 1000);
|
||||
int usage = luaL_optint(L, 3, USAGE_ARRAY);
|
||||
SpriteBatch * t = instance->newSpriteBatch(image, size, usage);
|
||||
luax_newtype(L, "SpriteBatch", LOVE_GRAPHICS_SPRITE_BATCH_BITS, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newVertexBuffer(lua_State * L)
|
||||
{
|
||||
|
||||
Image * image;
|
||||
int type, usage, size;
|
||||
|
||||
if(luax_istype(L, 1, LOVE_GRAPHICS_IMAGE_BITS))
|
||||
{
|
||||
image = luax_checktype<Image>(L, 1, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
size = luaL_optint(L, 2, 100);
|
||||
type = luaL_optint(L, 3, TYPE_TRIANGLES);
|
||||
usage = luaL_optint(L, 4, USAGE_ARRAY);
|
||||
}
|
||||
else if(lua_isnumber(L, 1))
|
||||
{
|
||||
image = 0;
|
||||
size = luaL_optint(L, 1, 100);
|
||||
type = luaL_optint(L, 2, TYPE_TRIANGLES);
|
||||
usage = luaL_optint(L, 3, USAGE_ARRAY);
|
||||
}
|
||||
else return luaL_error(L, "Expected type image or number");
|
||||
|
||||
VertexBuffer * t = instance->newVertexBuffer(image, size, type, usage);
|
||||
luax_newtype(L, "VertexBuffer", LOVE_GRAPHICS_VERTEX_BUFFER_BITS, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setColor(lua_State * L)
|
||||
{
|
||||
if(luax_istype(L, 1, LOVE_GRAPHICS_COLOR_BITS))
|
||||
{
|
||||
Color * color = luax_checktype<Color>(L, 1, "Color", LOVE_GRAPHICS_COLOR_BITS);
|
||||
instance->setColor(color);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int r = luaL_checkint(L, 1);
|
||||
int g = luaL_checkint(L, 2);
|
||||
int b = luaL_checkint(L, 3);
|
||||
int a = luaL_optint(L, 4, 255);
|
||||
|
||||
instance->setColor(r, g, b, a);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getColor(lua_State * L)
|
||||
{
|
||||
Color * color = instance->getColor();
|
||||
luax_newtype(L, "Color", LOVE_GRAPHICS_COLOR_BITS, (void*)color);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setBackgroundColor(lua_State * L)
|
||||
{
|
||||
if(luax_istype(L, 1, LOVE_GRAPHICS_COLOR_BITS))
|
||||
{
|
||||
Color * color = luax_checktype<Color>(L, 1, "Color", LOVE_GRAPHICS_COLOR_BITS);
|
||||
instance->setBackgroundColor(color);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int r = luaL_checkint(L, 1);
|
||||
int g = luaL_checkint(L, 1);
|
||||
int b = luaL_checkint(L, 1);
|
||||
|
||||
instance->setBackgroundColor(r, g, b);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getBackgroundColor(lua_State * L)
|
||||
{
|
||||
Color * color = instance->getBackgroundColor();
|
||||
luax_newtype(L, "Color", LOVE_GRAPHICS_COLOR_BITS, (void*)color);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setFont(lua_State * L)
|
||||
{
|
||||
// The second parameter is an optional int.
|
||||
int size = luaL_optint(L, 2, 12);
|
||||
|
||||
// If the first parameter is a string, convert it to a file.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_strtofile(L, 1);
|
||||
|
||||
// If the first parameter is a File, use another setFont function.
|
||||
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
|
||||
{
|
||||
love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", LOVE_FILESYSTEM_FILE_BITS);
|
||||
instance->setFont(file, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Font * font = luax_checktype<Font>(L, 1, "Font", LOVE_GRAPHICS_FONT_BITS);
|
||||
instance->setFont(font);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getFont(lua_State * L)
|
||||
{
|
||||
Font * f = instance->getFont();
|
||||
|
||||
if(f == 0)
|
||||
return 0;
|
||||
|
||||
f->retain();
|
||||
luax_newtype(L, "Font", LOVE_GRAPHICS_FONT_BITS, (void*)f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setBlendMode(lua_State * L)
|
||||
{
|
||||
int mode = luaL_checkint(L, 1);
|
||||
instance->setBlendMode(mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setColorMode(lua_State * L)
|
||||
{
|
||||
int mode = luaL_checkint(L, 1);
|
||||
instance->setColorMode(mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getBlendMode(lua_State * L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getBlendMode());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getColorMode(lua_State * L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getColorMode());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setLineWidth(lua_State * L)
|
||||
{
|
||||
float width = (float)luaL_checknumber(L, 1);
|
||||
instance->setLineWidth(width);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setLineStyle(lua_State * L)
|
||||
{
|
||||
int style = luaL_checkint(L, 1);
|
||||
instance->setLineStyle(style);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setLine(lua_State * L)
|
||||
{
|
||||
float width = (float)luaL_checknumber(L, 1);
|
||||
int style = luaL_optint(L, 2, LINE_SMOOTH);
|
||||
instance->setLine(width, style);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setLineStipple(lua_State * L)
|
||||
{
|
||||
if(lua_gettop(L) == 0)
|
||||
{
|
||||
instance->setLineStipple();
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned short pattern = (unsigned short)luaL_checkint(L, 1);
|
||||
int repeat = luaL_optint(L, 2, 1);
|
||||
instance->setLineStipple(pattern, repeat);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getLineWidth(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getLineWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getLineStyle(lua_State * L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getLineStyle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getLineStipple(lua_State * L)
|
||||
{
|
||||
return instance->getLineStipple(L);
|
||||
}
|
||||
|
||||
int _wrap_setPointSize(lua_State * L)
|
||||
{
|
||||
float size = (float)luaL_checknumber(L, 1);
|
||||
instance->setPointSize(size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setPointStyle(lua_State * L)
|
||||
{
|
||||
int style = luaL_checkint(L, 1);
|
||||
instance->setPointStyle(style);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setPoint(lua_State * L)
|
||||
{
|
||||
float size = (float)luaL_checknumber(L, 1);
|
||||
int style = luaL_optint(L, 2, POINT_SMOOTH);
|
||||
instance->setPoint(size, style);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getPointSize(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getPointSize());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getPointStyle(lua_State * L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getPointStyle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getMaxPointSize(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getMaxPointSize());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws an Image at the specified coordinates, with rotation and
|
||||
* scaling along both axes.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
* @param sx The scale factor along the x-axis. (1 = normal).
|
||||
* @param sy The scale factor along the y-axis. (1 = normal).
|
||||
* @param ox The offset along the x-axis.
|
||||
* @param oy The offset along the y-axis.
|
||||
**/
|
||||
int _wrap_draw(lua_State * L)
|
||||
{
|
||||
Drawable * drawable = luax_checktype<Drawable>(L, 1, "Drawable", LOVE_GRAPHICS_DRAWABLE_BITS);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
float ox = (float)luaL_optnumber(L, 7, 0);
|
||||
float oy = (float)luaL_optnumber(L, 8, 0);
|
||||
drawable->draw(x, y, angle, sx, sy, ox, oy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws an Image at the specified coordinates, with rotation and
|
||||
* scaling along both axes.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
* @param sx The scale factor along the x-axis. (1 = normal).
|
||||
* @param sy The scale factor along the y-axis. (1 = normal).
|
||||
* @param ox The offset along the x-axis.
|
||||
* @param oy The offset along the y-axis.
|
||||
* @param rx The upper-left corner of the source rectangle along the x-axis.
|
||||
* @param ry The upper-left corner of the source rectangle along the y-axis.
|
||||
* @param rw The width of the source rectangle.
|
||||
* @param rw The height of the source rectangle.
|
||||
**/
|
||||
int _wrap_draws(lua_State * L)
|
||||
{
|
||||
Image * image = luax_checktype<Image>(L, 1, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
float ox = (float)luaL_optnumber(L, 7, 0);
|
||||
float oy = (float)luaL_optnumber(L, 8, 0);
|
||||
float rx = (float)luaL_optnumber(L, 9, 0);
|
||||
float ry = (float)luaL_optnumber(L, 10, 0);
|
||||
float rw = (float)luaL_optnumber(L, 11, image->getWidth());
|
||||
float rh = (float)luaL_optnumber(L, 12, image->getHeight());
|
||||
image->draws(x, y, angle, sx, sy, ox, oy, rx, ry, rw, rh);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_drawTest(lua_State * L)
|
||||
{
|
||||
Image * image = luax_checktype<Image>(L, 1, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
float ox = (float)luaL_optnumber(L, 7, 0);
|
||||
float oy = (float)luaL_optnumber(L, 8, 0);
|
||||
instance->drawTest(image, x, y, angle, sx, sy, ox, oy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_print(lua_State * L)
|
||||
{
|
||||
const char * str = luaL_checkstring(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
|
||||
switch(lua_gettop(L))
|
||||
{
|
||||
case 3:
|
||||
instance->print(str, x, y);
|
||||
break;
|
||||
case 4:
|
||||
instance->print(str, x, y, angle);
|
||||
break;
|
||||
case 5:
|
||||
instance->print(str, x, y, angle, sx);
|
||||
break;
|
||||
case 6:
|
||||
instance->print(str, x, y, angle, sx, sy);
|
||||
break;
|
||||
default:
|
||||
return luaL_error(L, "Incorrect number of parameters");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_printf(lua_State * L)
|
||||
{
|
||||
const char * str = luaL_checkstring(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float wrap = (float)luaL_checknumber(L, 4);
|
||||
int align = luaL_optint(L, 5, 0);
|
||||
instance->printf(str, x, y, wrap, align);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_point(lua_State * L)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
instance->point(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_line(lua_State * L)
|
||||
{
|
||||
float x1 = (float)luaL_checknumber(L, 1);
|
||||
float y1 = (float)luaL_checknumber(L, 2);
|
||||
float x2 = (float)luaL_checknumber(L, 3);
|
||||
float y2 = (float)luaL_checknumber(L, 4);
|
||||
instance->line(x1, y1, x2, y2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_triangle(lua_State * L)
|
||||
{
|
||||
int type = luaL_checkint(L, 1);
|
||||
float x1 = (float)luaL_checknumber(L, 2);
|
||||
float y1 = (float)luaL_checknumber(L, 3);
|
||||
float x2 = (float)luaL_checknumber(L, 4);
|
||||
float y2 = (float)luaL_checknumber(L, 5);
|
||||
float x3 = (float)luaL_checknumber(L, 6);
|
||||
float y3 = (float)luaL_checknumber(L, 7);
|
||||
instance->triangle(type, x1, y1, x2, y2, x3, y3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_rectangle(lua_State * L)
|
||||
{
|
||||
int type = luaL_checkint(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float w = (float)luaL_checknumber(L, 4);
|
||||
float h = (float)luaL_checknumber(L, 5);
|
||||
instance->rectangle(type, x, y, w, h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_quad(lua_State * L)
|
||||
{
|
||||
int type = luaL_checkint(L, 1);
|
||||
float x1 = (float)luaL_checknumber(L, 2);
|
||||
float y1 = (float)luaL_checknumber(L, 3);
|
||||
float x2 = (float)luaL_checknumber(L, 4);
|
||||
float y2 = (float)luaL_checknumber(L, 5);
|
||||
float x3 = (float)luaL_checknumber(L, 6);
|
||||
float y3 = (float)luaL_checknumber(L, 7);
|
||||
float x4 = (float)luaL_checknumber(L, 6);
|
||||
float y4 = (float)luaL_checknumber(L, 7);
|
||||
instance->quad(type, x1, y1, x2, y2, x3, y3, x4, y4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_circle(lua_State * L)
|
||||
{
|
||||
int type = luaL_checkint(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float radius = (float)luaL_checknumber(L, 4);
|
||||
int points = luaL_optint(L, 5, 10);
|
||||
instance->circle(type, x, y, radius, points);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_polygon(lua_State * L)
|
||||
{
|
||||
return instance->polygon(L);
|
||||
}
|
||||
|
||||
int _wrap_push(lua_State * L)
|
||||
{
|
||||
instance->push();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_pop(lua_State * L)
|
||||
{
|
||||
instance->pop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_rotate(lua_State * L)
|
||||
{
|
||||
float deg = (float)luaL_checknumber(L, 1);
|
||||
instance->rotate(deg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_scale(lua_State * L)
|
||||
{
|
||||
float sx = (float)luaL_optnumber(L, 1, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 2, sx);
|
||||
instance->scale(sx, sy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_translate(lua_State * L)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
instance->translate(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg wrap_Graphics_functions[] = {
|
||||
{ "checkMode", _wrap_checkMode },
|
||||
{ "setMode", _wrap_setMode },
|
||||
{ "toggleFullscreen", _wrap_toggleFullscreen },
|
||||
{ "reset", _wrap_reset },
|
||||
{ "clear", _wrap_clear },
|
||||
{ "present", _wrap_present },
|
||||
|
||||
{ "newColor", _wrap_newColor },
|
||||
{ "newImage", _wrap_newImage },
|
||||
{ "newFrame", _wrap_newFrame },
|
||||
{ "newAnimation", _wrap_newAnimation },
|
||||
{ "newFont", _wrap_newFont },
|
||||
{ "newImageFont", _wrap_newImageFont },
|
||||
{ "newSpriteBatch", _wrap_newSpriteBatch },
|
||||
{ "newVertexBuffer", _wrap_newVertexBuffer },
|
||||
|
||||
{ "setColor", _wrap_setColor },
|
||||
{ "getColor", _wrap_getColor },
|
||||
{ "setBackgroundColor", _wrap_setBackgroundColor },
|
||||
{ "getBackgroundColor", _wrap_getBackgroundColor },
|
||||
|
||||
{ "setFont", _wrap_setFont },
|
||||
|
||||
{ "setBlendMode", _wrap_setBlendMode },
|
||||
{ "setColorMode", _wrap_setColorMode },
|
||||
{ "getBlendMode", _wrap_getBlendMode },
|
||||
{ "getColorMode", _wrap_getColorMode },
|
||||
{ "setLineWidth", _wrap_setLineWidth },
|
||||
{ "setLineStyle", _wrap_setLineStyle },
|
||||
{ "setLine", _wrap_setLine },
|
||||
{ "setLineStipple", _wrap_setLineStipple },
|
||||
{ "getLineWidth", _wrap_getLineWidth },
|
||||
{ "getLineStyle", _wrap_getLineStyle },
|
||||
{ "getLineStipple", _wrap_getLineStipple },
|
||||
{ "setPointSize", _wrap_setPointSize },
|
||||
{ "setPointStyle", _wrap_setPointStyle },
|
||||
{ "setPoint", _wrap_setPoint },
|
||||
{ "getPointSize", _wrap_getPointSize },
|
||||
{ "getPointStyle", _wrap_getPointStyle },
|
||||
{ "getMaxPointSize", _wrap_getMaxPointSize },
|
||||
|
||||
{ "draw", _wrap_draw },
|
||||
{ "draws", _wrap_draws },
|
||||
{ "drawTest", _wrap_drawTest },
|
||||
|
||||
{ "print", _wrap_print },
|
||||
{ "printf", _wrap_printf },
|
||||
|
||||
{ "setCaption", _wrap_setCaption },
|
||||
{ "getCaption", _wrap_getCaption },
|
||||
|
||||
{ "getWidth", _wrap_getWidth },
|
||||
{ "getHeight", _wrap_getHeight },
|
||||
|
||||
{ "isCreated", _wrap_isCreated },
|
||||
|
||||
{ "getModes", _wrap_getModes },
|
||||
|
||||
{ "setScissor", _wrap_setScissor },
|
||||
{ "getScissor", _wrap_getScissor },
|
||||
|
||||
{ "point", _wrap_point },
|
||||
{ "line", _wrap_line },
|
||||
{ "triangle", _wrap_triangle },
|
||||
{ "rectangle", _wrap_rectangle },
|
||||
{ "quad", _wrap_quad },
|
||||
{ "circle", _wrap_circle },
|
||||
|
||||
{ "polygon", _wrap_polygon },
|
||||
|
||||
{ "push", _wrap_push },
|
||||
{ "pop", _wrap_pop },
|
||||
{ "rotate", _wrap_rotate },
|
||||
{ "scale", _wrap_scale },
|
||||
{ "translate", _wrap_translate },
|
||||
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
// Types for this module.
|
||||
const lua_CFunction wrap_Graphics_types[] = {
|
||||
wrap_Color_open,
|
||||
wrap_Font_open,
|
||||
wrap_Image_open,
|
||||
wrap_Frame_open,
|
||||
wrap_Animation_open,
|
||||
wrap_ParticleSystem_open,
|
||||
wrap_SpriteBatch_open,
|
||||
wrap_VertexBuffer_open,
|
||||
0
|
||||
};
|
||||
|
||||
int wrap_Graphics_open(lua_State * L)
|
||||
{
|
||||
if(instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = new Graphics();
|
||||
}
|
||||
catch(Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, "love.graphics", instance);
|
||||
|
||||
return luax_register_module(L, wrap_Graphics_functions, wrap_Graphics_types);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Color.h"
|
||||
#include "wrap_Font.h"
|
||||
#include "wrap_Image.h"
|
||||
#include "wrap_Animation.h"
|
||||
#include "wrap_ParticleSystem.h"
|
||||
#include "wrap_SpriteBatch.h"
|
||||
#include "wrap_VertexBuffer.h"
|
||||
#include "wrap_Frame.h"
|
||||
#include "Graphics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
int _wrap_checkMode(lua_State * L);
|
||||
int _wrap_setMode(lua_State * L);
|
||||
int _wrap_toggleFullscreen(lua_State * L);
|
||||
int _wrap_reset(lua_State * L);
|
||||
int _wrap_clear(lua_State * L);
|
||||
int _wrap_present(lua_State * L);
|
||||
int _wrap_setCaption(lua_State * L);
|
||||
int _wrap_getCaption(lua_State * L);
|
||||
int _wrap_getWidth(lua_State * L);
|
||||
int _wrap_getHeight(lua_State * L);
|
||||
int _wrap_isCreated(lua_State * L);
|
||||
int _wrap_setScissor(lua_State * L);
|
||||
int _wrap_getScissor(lua_State * L);
|
||||
int _wrap_newColor(lua_State * L);
|
||||
int _wrap_newImage(lua_State * L);
|
||||
int _wrap_newFrame(lua_State * L);
|
||||
int _wrap_newAnimation(lua_State * L);
|
||||
int _wrap_newFont(lua_State * L);
|
||||
int _wrap_newImageFont(lua_State * L);
|
||||
int _wrap_newSpriteBatch(lua_State * L);
|
||||
int _wrap_newVertexBuffer(lua_State * L);
|
||||
int _wrap_setColor(lua_State * L);
|
||||
int _wrap_getColor(lua_State * L);
|
||||
int _wrap_setBackgroundColor(lua_State * L);
|
||||
int _wrap_getBackgroundColor(lua_State * L);
|
||||
int _wrap_setFont(lua_State * L);
|
||||
int _wrap_getFont(lua_State * L);
|
||||
int _wrap_setBlendMode(lua_State * L);
|
||||
int _wrap_setColorMode(lua_State * L);
|
||||
int _wrap_getBlendMode(lua_State * L);
|
||||
int _wrap_getColorMode(lua_State * L);
|
||||
int _wrap_setLineWidth(lua_State * L);
|
||||
int _wrap_setLineStyle(lua_State * L);
|
||||
int _wrap_setLine(lua_State * L);
|
||||
int _wrap_setLineStipple(lua_State * L);
|
||||
int _wrap_getLineWidth(lua_State * L);
|
||||
int _wrap_getLineStyle(lua_State * L);
|
||||
int _wrap_getLineStipple(lua_State * L);
|
||||
int _wrap_setPointSize(lua_State * L);
|
||||
int _wrap_setPointStyle(lua_State * L);
|
||||
int _wrap_setPoint(lua_State * L);
|
||||
int _wrap_getPointSize(lua_State * L);
|
||||
int _wrap_getPointStyle(lua_State * L);
|
||||
int _wrap_getMaxPointSize(lua_State * L);
|
||||
int _wrap_draw(lua_State * L);
|
||||
int _wrap_draws(lua_State * L);
|
||||
int _wrap_drawTest(lua_State * L);
|
||||
int _wrap_print(lua_State * L);
|
||||
int _wrap_printf(lua_State * L);
|
||||
int _wrap_point(lua_State * L);
|
||||
int _wrap_line(lua_State * L);
|
||||
int _wrap_triangle(lua_State * L);
|
||||
int _wrap_rectangle(lua_State * L);
|
||||
int _wrap_quad(lua_State * L);
|
||||
int _wrap_circle(lua_State * L);
|
||||
int _wrap_push(lua_State * L);
|
||||
int _wrap_pop(lua_State * L);
|
||||
int _wrap_rotate(lua_State * L);
|
||||
int _wrap_scale(lua_State * L);
|
||||
int _wrap_translate(lua_State * L);
|
||||
int wrap_Graphics_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Image * luax_checkimage(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Image>(L, idx, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
}
|
||||
|
||||
int _wrap_Image_getWidth(lua_State * L)
|
||||
{
|
||||
Image * t = luax_checkimage(L, 1);
|
||||
lua_pushnumber(L, t->getWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Image_getHeight(lua_State * L)
|
||||
{
|
||||
Image * t = luax_checkimage(L, 1);
|
||||
lua_pushnumber(L, t->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Image_setFilter(lua_State * L)
|
||||
{
|
||||
Image * t = luax_checkimage(L, 1);
|
||||
int min = luaL_checkint(L, 2);
|
||||
int mag = luaL_checkint(L, 3);
|
||||
t->setFilter(min, mag);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Image_functions[] = {
|
||||
{ "getWidth", _wrap_Image_getWidth },
|
||||
{ "getHeight", _wrap_Image_getHeight },
|
||||
{ "setFilter", _wrap_Image_setFilter },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Image_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Image", wrap_Image_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Image * luax_checkimage(lua_State * L, int idx);
|
||||
int _wrap_Image_getWidth(lua_State * L);
|
||||
int _wrap_Image_getHeight(lua_State * L);
|
||||
int _wrap_Image_setFIlter(lua_State * L);
|
||||
int wrap_Image_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
@@ -0,0 +1,334 @@
|
||||
/**
|
||||
* 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 "wrap_ParticleSystem.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
ParticleSystem * luax_checkparticlesystem(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<ParticleSystem>(L, idx, "ParticleSystem", LOVE_GRAPHICS_PARTICLE_SYSTEM_BITS);
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSprite(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
Image * i = luax_checkimage(L, 2);
|
||||
t->setSprite(i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setBufferSize(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
int arg1 = luaL_checkint(L, 2);
|
||||
t->setBufferSize((unsigned int)arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setEmissionRate(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
int arg1 = luaL_checkint(L, 2);
|
||||
t->setEmissionRate((unsigned int)arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setLifetime(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLifetime(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setParticleLife(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setParticleLife(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setPosition(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setPosition(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setDirection(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDirection(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSpread(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpread(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setRelativeDirection(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
bool arg1 = (bool)luax_toboolean(L, 2);
|
||||
t->setRelativeDirection(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSpeed(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setSpeed(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setGravity(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setGravity(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setRadialAcceleration(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setRadialAcceleration(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setTangentialAcceleration(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setTangentialAcceleration(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSize(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
float arg3 = (float)luaL_optnumber(L, 3, 0);
|
||||
t->setSize(arg1, arg2, arg3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSizeVariation(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSizeVariation(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setRotation(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setRotation(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSpin(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
float arg3 = (float)luaL_optnumber(L, 3, 0);
|
||||
t->setSpin(arg1, arg2, arg3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSpinVariation(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpinVariation(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setColor(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
Color * start = luax_checkcolor(L, 2);
|
||||
Color * end = (lua_gettop(L) == 3) ? luax_checkcolor(L, 3) : start;
|
||||
t->setColor(start, end);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_getX(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getX());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_getY(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getY());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_getDirection(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getDirection());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_getSpread(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getSpread());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_count(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->count());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_start(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
t->start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_stop(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
t->stop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_pause(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
t->pause();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_reset(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
t->reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_isActive(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
luax_pushboolean(L, t->isActive());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_isEmpty(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
luax_pushboolean(L, t->isEmpty());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_isFull(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
luax_pushboolean(L, t->isFull());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_update(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float dt = (float)luaL_checknumber(L, 2);
|
||||
t->update(dt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_ParticleSystem_functions[] = {
|
||||
{ "setSprite", _wrap_ParticleSystem_setSprite },
|
||||
{ "setBufferSize", _wrap_ParticleSystem_setBufferSize },
|
||||
{ "setEmissionRate", _wrap_ParticleSystem_setEmissionRate },
|
||||
{ "setLifeTime", _wrap_ParticleSystem_setLifetime },
|
||||
{ "setParticleLife", _wrap_ParticleSystem_setParticleLife },
|
||||
{ "setPosition", _wrap_ParticleSystem_setPosition },
|
||||
{ "setDirection", _wrap_ParticleSystem_setDirection },
|
||||
{ "setSpread", _wrap_ParticleSystem_setSpread },
|
||||
{ "setRelativeDirection", _wrap_ParticleSystem_setRelativeDirection },
|
||||
{ "setSpeed", _wrap_ParticleSystem_setSpeed },
|
||||
{ "setGravity", _wrap_ParticleSystem_setGravity },
|
||||
{ "setRadialAcceleration", _wrap_ParticleSystem_setRadialAcceleration },
|
||||
{ "setTangentialAcceleration", _wrap_ParticleSystem_setTangentialAcceleration },
|
||||
{ "setSize", _wrap_ParticleSystem_setSize },
|
||||
{ "setSizeVariation", _wrap_ParticleSystem_setSizeVariation },
|
||||
{ "setRotation", _wrap_ParticleSystem_setRotation },
|
||||
{ "setSpin", _wrap_ParticleSystem_setSpin },
|
||||
{ "setSpinVariation", _wrap_ParticleSystem_setSpinVariation },
|
||||
{ "setColor", _wrap_ParticleSystem_setColor },
|
||||
{ "getX", _wrap_ParticleSystem_getX },
|
||||
{ "getY", _wrap_ParticleSystem_getY },
|
||||
{ "getDirection", _wrap_ParticleSystem_getDirection },
|
||||
{ "getSpread", _wrap_ParticleSystem_getSpread },
|
||||
{ "count", _wrap_ParticleSystem_count },
|
||||
{ "start", _wrap_ParticleSystem_start },
|
||||
{ "stop", _wrap_ParticleSystem_stop },
|
||||
{ "pause", _wrap_ParticleSystem_pause },
|
||||
{ "reset", _wrap_ParticleSystem_reset },
|
||||
{ "isActive", _wrap_ParticleSystem_isActive },
|
||||
{ "isEmpty", _wrap_ParticleSystem_isEmpty },
|
||||
{ "isFull", _wrap_ParticleSystem_isFull },
|
||||
{ "update", _wrap_ParticleSystem_update },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_ParticleSystem_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "ParticleSystem", wrap_ParticleSystem_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_PARTICLE_SYSTEM_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_PARTICLE_SYSTEM_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Image.h"
|
||||
#include "wrap_Color.h"
|
||||
#include "ParticleSystem.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
ParticleSystem * luax_checkparticlesystem(lua_State * L, int idx);
|
||||
int _wrap_ParticleSystem_setSprite(lua_State * L);
|
||||
int _wrap_ParticleSystem_setBufferSize(lua_State * L);
|
||||
int _wrap_ParticleSystem_setEmissionRate(lua_State * L);
|
||||
int _wrap_ParticleSystem_setLifetime(lua_State * L);
|
||||
int _wrap_ParticleSystem_setParticleLife(lua_State * L);
|
||||
int _wrap_ParticleSystem_setPosition(lua_State * L);
|
||||
int _wrap_ParticleSystem_setDirection(lua_State * L);
|
||||
int _wrap_ParticleSystem_setSpread(lua_State * L);
|
||||
int _wrap_ParticleSystem_setRelativeDirection(lua_State * L);
|
||||
int _wrap_ParticleSystem_setSpeed(lua_State * L);
|
||||
int _wrap_ParticleSystem_setGravity(lua_State * L);
|
||||
int _wrap_ParticleSystem_setRadialAcceleration(lua_State * L);
|
||||
int _wrap_ParticleSystem_setTangentialAcceleration(lua_State * L);
|
||||
int _wrap_ParticleSystem_setSize(lua_State * L);
|
||||
int _wrap_ParticleSystem_setSizeVariation(lua_State * L);
|
||||
int _wrap_ParticleSystem_setRotation(lua_State * L);
|
||||
int _wrap_ParticleSystem_setSpin(lua_State * L);
|
||||
int _wrap_ParticleSystem_setSpinVariation(lua_State * L);
|
||||
int _wrap_ParticleSystem_setColor(lua_State * L);
|
||||
int _wrap_ParticleSystem_getX(lua_State * L);
|
||||
int _wrap_ParticleSystem_getY(lua_State * L);
|
||||
int _wrap_ParticleSystem_getDirection(lua_State * L);
|
||||
int _wrap_ParticleSystem_getSpread(lua_State * L);
|
||||
int _wrap_ParticleSystem_count(lua_State * L);
|
||||
int _wrap_ParticleSystem_start(lua_State * L);
|
||||
int _wrap_ParticleSystem_stop(lua_State * L);
|
||||
int _wrap_ParticleSystem_pause(lua_State * L);
|
||||
int _wrap_ParticleSystem_reset(lua_State * L);
|
||||
int _wrap_ParticleSystem_isActive(lua_State * L);
|
||||
int _wrap_ParticleSystem_isEmpty(lua_State * L);
|
||||
int _wrap_ParticleSystem_isFull(lua_State * L);
|
||||
int _wrap_ParticleSystem_update(lua_State * L);
|
||||
int wrap_ParticleSystem_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_PARTICLE_SYSTEM_H
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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 "wrap_SpriteBatch.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
SpriteBatch * luax_checkspritebatch(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<SpriteBatch>(L, idx, "SpriteBatch", LOVE_GRAPHICS_SPRITE_BATCH_BITS);
|
||||
}
|
||||
|
||||
int _wrap_SpriteBatch_add(lua_State * L)
|
||||
{
|
||||
SpriteBatch * t = luax_checkspritebatch(L, 1);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
float ox = (float)luaL_optnumber(L, 7, 0);
|
||||
float oy = (float)luaL_optnumber(L, 8, 0);
|
||||
t->add(x, y, angle, sx, sy, ox, oy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_SpriteBatch_clear(lua_State * L)
|
||||
{
|
||||
SpriteBatch * t = luax_checkspritebatch(L, 1);
|
||||
t->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_SpriteBatch_functions[] = {
|
||||
{ "add", _wrap_SpriteBatch_add },
|
||||
{ "clear", _wrap_SpriteBatch_clear },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_SpriteBatch_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "SpriteBatch", wrap_SpriteBatch_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
|
||||
|
||||
#include <common/runtime.h>
|
||||
#include "SpriteBatch.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
SpriteBatch * luax_checkspritebatch(lua_State * L, int idx);
|
||||
int _wrap_SpriteBatch_add(lua_State * L);
|
||||
int _wrap_SpriteBatch_clear(lua_State * L);
|
||||
int wrap_SpriteBatch_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
|
||||
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* 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 "wrap_VertexBuffer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
VertexBuffer * luax_checkvertexbuffer(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<VertexBuffer>(L, idx, "VertexBuffer", LOVE_GRAPHICS_VERTEX_BUFFER_BITS);
|
||||
}
|
||||
|
||||
int _wrap_VertexBuffer_setType(lua_State * L)
|
||||
{
|
||||
VertexBuffer * t = luax_checkvertexbuffer(L, 1);
|
||||
int type = luaL_checkint(L, 2);
|
||||
t->setType(type);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_VertexBuffer_getType(lua_State * L)
|
||||
{
|
||||
VertexBuffer * t = luax_checkvertexbuffer(L, 1);
|
||||
lua_pushnumber(L, t->getType());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_VertexBuffer_add(lua_State * L)
|
||||
{
|
||||
VertexBuffer * vb = luax_checkvertexbuffer(L, 1);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float s = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float t = (float)luaL_optnumber(L, 5, 0.0f);
|
||||
unsigned char r = (unsigned char)luaL_optnumber(L, 6, 255);
|
||||
unsigned char g = (unsigned char)luaL_optnumber(L, 7, 255);
|
||||
unsigned char b = (unsigned char)luaL_optnumber(L, 8, 255);
|
||||
unsigned char a = (unsigned char)luaL_optnumber(L, 9, 255);
|
||||
vb->add(x, y, s, t, r, g, b, a);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_VertexBuffer_clear(lua_State * L)
|
||||
{
|
||||
VertexBuffer * t = luax_checkvertexbuffer(L, 1);
|
||||
t->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg wrap_VertexBuffer_functions[] = {
|
||||
{ "setType", _wrap_VertexBuffer_setType },
|
||||
{ "getType", _wrap_VertexBuffer_getType },
|
||||
{ "add", _wrap_VertexBuffer_add },
|
||||
{ "clear", _wrap_VertexBuffer_clear },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_VertexBuffer_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "VertexBuffer", wrap_VertexBuffer_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_VERTEX_BUFFER_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_VERTEX_BUFFER_H
|
||||
|
||||
#include <common/runtime.h>
|
||||
#include "VertexBuffer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
VertexBuffer * luax_checkvertexbuffer(lua_State * L, int idx);
|
||||
int _wrap_VertexBuffer_setType(lua_State * L);
|
||||
int _wrap_VertexBuffer_getType(lua_State * L);
|
||||
int _wrap_VertexBuffer_add(lua_State * L);
|
||||
int _wrap_VertexBuffer_clear(lua_State * L);
|
||||
int wrap_VertexBuffer_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_VERTEX_BUFFER_H
|
||||
Reference in New Issue
Block a user