Move everything from global namespace to "sp" namespace
When writing the X11 (linux) implementation there was a problem with X11 defining a "Display" type and we also have a Display class in the engine. So to fix that problem and minimize the risk for running into other name conflicts. We move everything from global namespace.
This commit is contained in:
parent
9da8addeb2
commit
e10daeaaa6
120 changed files with 551 additions and 105 deletions
|
|
@ -1,27 +1,30 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <Spectre/Graphics/BatchRenderer2D.h>
|
||||
#include <Spectre/Input/InputModule.h>
|
||||
#include <Spectre/Graphics/Font.h>
|
||||
#include <Spectre/Graphics/Text.h>
|
||||
#include "Game.h"
|
||||
|
||||
Font smallFont;
|
||||
Font myFont;
|
||||
Font fntLarge;
|
||||
sp::Font smallFont;
|
||||
sp::Font myFont;
|
||||
sp::Font fntLarge;
|
||||
|
||||
Text myText;
|
||||
Text txtLarge;
|
||||
Text txtKerning;
|
||||
Text fpsText;
|
||||
Text txtSmall;
|
||||
sp::Text myText;
|
||||
sp::Text txtLarge;
|
||||
sp::Text txtKerning;
|
||||
sp::Text fpsText;
|
||||
sp::Text txtSmall;
|
||||
|
||||
Camera2D guiCamera;
|
||||
sp::Camera2D guiCamera;
|
||||
|
||||
BatchRenderer2D *renderer;
|
||||
sp::BatchRenderer2D *renderer;
|
||||
|
||||
void TextExample::init()
|
||||
{
|
||||
Graphics* g = getGraphics();
|
||||
sp::Graphics* g = getGraphics();
|
||||
|
||||
std::cout << g->getVersion() << std::endl;
|
||||
|
||||
g->setClearColor(52.0f / 255.0f, 58.0f / 255.0f, 80.0f / 255.0f);
|
||||
|
||||
|
|
@ -30,18 +33,18 @@ void TextExample::init()
|
|||
fntLarge.loadFromFile("assets/fonts/OPTIBelwe-Medium.otf");
|
||||
|
||||
myText.setFont(myFont);
|
||||
myText.setColor(Color::Green);
|
||||
myText.setColor(sp::Color::Green);
|
||||
myText.setString("Hello");
|
||||
myText.setPosition(25.0f, 50.0f);
|
||||
|
||||
txtLarge.setFont(myFont);
|
||||
txtLarge.setColor(Color(200, 100, 0));
|
||||
txtLarge.setColor(sp::Color(200, 100, 0));
|
||||
txtLarge.setString("Large Text, Looks good?");
|
||||
txtLarge.setPosition(300.0f, 150.0f);
|
||||
txtLarge.setScale(2.0f);
|
||||
|
||||
txtKerning.setFont(fntLarge);
|
||||
txtKerning.setColor(Color(150, 0, 230));
|
||||
txtKerning.setColor(sp::Color(150, 0, 230));
|
||||
txtKerning.setString("Kerning: VA Ta");
|
||||
txtKerning.setPosition(150.0f, 200.0f);
|
||||
|
||||
|
|
@ -53,23 +56,23 @@ void TextExample::init()
|
|||
fpsText.setString("FPS: 0");
|
||||
fpsText.setPosition(10.0f, 10.0f);
|
||||
|
||||
renderer = new BatchRenderer2D();
|
||||
renderer = new sp::BatchRenderer2D();
|
||||
}
|
||||
|
||||
void TextExample::update(double dt)
|
||||
{
|
||||
InputModule* input = getInput();
|
||||
sp::InputModule* input = getInput();
|
||||
input->update();
|
||||
|
||||
if (getFpsCounter().update()) {
|
||||
std::string str = "FPS: " + core::to_string(getFpsCounter().getFPS(), 0);
|
||||
std::string str = "FPS: " + sp::core::to_string(getFpsCounter().getFPS(), 0);
|
||||
fpsText.setString(str);
|
||||
}
|
||||
}
|
||||
|
||||
void TextExample::render()
|
||||
{
|
||||
Graphics* g = getGraphics();
|
||||
sp::Graphics* g = getGraphics();
|
||||
|
||||
g->clearBuffer();
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include <Spectre/Input/InputListener.h>
|
||||
#include <Spectre/Game.h>
|
||||
|
||||
class TextExample : public Game, public InputListener
|
||||
class TextExample : public sp::Game, public sp::InputListener
|
||||
{
|
||||
protected :
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#ifndef SPECTRE_CORE_NONCOPYABLE_H
|
||||
#define SPECTRE_CORE_NONCOPYABLE_H
|
||||
|
||||
namespace sp {
|
||||
|
||||
class NonCopyable
|
||||
{
|
||||
protected :
|
||||
|
|
@ -15,4 +17,6 @@ private :
|
|||
NonCopyable& operator =(const NonCopyable&);
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_CORE_NONCOPYABLE_H */
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
namespace core
|
||||
namespace sp { namespace core
|
||||
{
|
||||
// Convertion functions from standard c/c++ types.
|
||||
|
||||
|
|
@ -15,6 +15,6 @@ namespace core
|
|||
std::string to_string(float value);
|
||||
|
||||
std::string to_string(float value, unsigned int precision);
|
||||
};
|
||||
} } // namespace sp::core
|
||||
|
||||
#endif /* SPECTRE_CORE_STRING_H */
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
#include <Spectre/System/SystemEvent.h>
|
||||
#include <string>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class PlatformDisplay;
|
||||
class GLContext;
|
||||
|
||||
|
|
@ -73,4 +75,6 @@ protected :
|
|||
GLContext* m_context;
|
||||
};
|
||||
|
||||
} // namepsace sp
|
||||
|
||||
#endif /* SPECTRE_DISPLAY_DISPLAY_H */
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@
|
|||
|
||||
#include "DisplayMode.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
namespace DisplayDecorate {
|
||||
|
||||
|
||||
enum Type {
|
||||
None = 0,
|
||||
Menu = 1 << 0,
|
||||
|
|
@ -27,4 +29,6 @@ public :
|
|||
unsigned int decoration;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_DISPLAY_DISPLAYDESCRIPTION_H */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class DisplayMode
|
||||
{
|
||||
public :
|
||||
|
|
@ -16,7 +18,7 @@ public :
|
|||
|
||||
inline bool operator==(const DisplayMode& other)
|
||||
{
|
||||
return width == other.width
|
||||
return width == other.width
|
||||
&& height == other.height
|
||||
&& bpp == other.bpp;
|
||||
}
|
||||
|
|
@ -32,4 +34,6 @@ public :
|
|||
unsigned int bpp; /* Bits per pixel. */
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_DISPLAY_DISPLAYMODE_H */
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <Spectre/Math/Vector2.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class PlatformDisplay;
|
||||
|
||||
// Platform independant interface for OpenGL Contexts.
|
||||
|
|
@ -43,4 +45,6 @@ public :
|
|||
virtual void swapBuffers() = 0;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* DISPLAY_GLCONTEXT_H */
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ class MessageQueue;
|
|||
class MessageHandler;
|
||||
class PlatformApplication;
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Game
|
||||
{
|
||||
public :
|
||||
|
|
@ -60,4 +62,6 @@ private :
|
|||
bool m_running;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* SPECTRE_GAME_H */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
// Simple FPS counter.
|
||||
|
||||
namespace sp {
|
||||
|
||||
class FPSCounter
|
||||
{
|
||||
public :
|
||||
|
|
@ -29,7 +31,7 @@ private :
|
|||
|
||||
// Frame counter.
|
||||
unsigned int m_count;
|
||||
|
||||
|
||||
// time (in ms)
|
||||
unsigned int m_time;
|
||||
|
||||
|
|
@ -40,4 +42,6 @@ private :
|
|||
float m_fps;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_FPS_COUNTER_H */
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
#ifndef SPECTRE_GAME_TIME_H
|
||||
#define SPECTRE_GAME_TIME_H
|
||||
|
||||
namespace sp {
|
||||
|
||||
class GameTime
|
||||
{
|
||||
public :
|
||||
|
|
@ -42,4 +44,6 @@ protected :
|
|||
bool m_inLoop;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GAME_TIME_H */
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <Spectre/Display/Display.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class PlatformApplication;
|
||||
|
||||
class Graphics
|
||||
|
|
@ -48,4 +50,6 @@ protected :
|
|||
Display *m_display;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* GRAPHICS_H */
|
||||
|
|
|
|||
|
|
@ -10,8 +10,9 @@
|
|||
#include <Spectre/Math/Matrix4.h>
|
||||
#include <vector>
|
||||
|
||||
class ShaderProgram;
|
||||
namespace sp {
|
||||
|
||||
class ShaderProgram;
|
||||
class Texture;
|
||||
|
||||
class BatchRenderer2D : public Renderer2D
|
||||
|
|
@ -70,4 +71,6 @@ protected :
|
|||
ShaderProgram m_spriteShader;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif /* SPECTRE_BATCH_RENDERER2D_H */
|
||||
|
|
@ -5,6 +5,8 @@
|
|||
#include <vector>
|
||||
#include "Renderer2D.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class DefaultRenderer2D : public Renderer2D
|
||||
{
|
||||
public :
|
||||
|
|
@ -22,4 +24,6 @@ protected :
|
|||
ShaderProgram m_shader;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif /* SPECTRE_DEFAULT_RENDERER2D_H */
|
||||
|
|
@ -10,6 +10,8 @@
|
|||
#include <Spectre/Math/Vector2.h>
|
||||
#include <Spectre/Graphics/Texture.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class FontDriver;
|
||||
|
||||
// TODO: Fixup this api :)
|
||||
|
|
@ -73,4 +75,6 @@ protected :
|
|||
std::vector<unsigned char> m_rawData;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* SPECTRE_GRAPHCIS_FONT_H */
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
#include <Spectre/Math/Vector2.h>
|
||||
#include <Spectre/Graphics/PixelFormat.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Image
|
||||
{
|
||||
public :
|
||||
|
|
@ -59,4 +61,6 @@ private :
|
|||
std::vector<unsigned char> m_pixels;
|
||||
};
|
||||
|
||||
} //namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_IMAGE_H */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef SPECTRE_GRAPHICS_PIXELFORMAT_H
|
||||
#define SPECTRE_GRAPHICS_PIXELFORMAT_H
|
||||
|
||||
namespace sp {
|
||||
|
||||
enum PixelFormat
|
||||
{
|
||||
PF_Unknown = 0,
|
||||
|
|
@ -9,4 +11,6 @@ enum PixelFormat
|
|||
PF_Alpha = 3, // 1 byte alpha channel.
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_PIXELFORMAT_H */
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#ifndef SPECTRE_GRAPHICS_RENDERSTATE_H
|
||||
#define SPECTRE_GRAPHICS_RENDERSTATE_H
|
||||
|
||||
namespace sp {
|
||||
|
||||
class ShaderProgram;
|
||||
class Texture;
|
||||
|
||||
|
|
@ -24,4 +26,6 @@ protected :
|
|||
const ShaderProgram *m_shader;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_RENDERSTATE_H */
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
#include <Spectre/Math/Vector2.h>
|
||||
#include <vector>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Renderer2D;
|
||||
class ShaderProgram;
|
||||
class Texture;
|
||||
|
|
@ -43,4 +45,6 @@ protected :
|
|||
unsigned char m_zorder;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHCIS_RENDERABLE_H */
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
#include <Spectre/Graphics/ShaderProgram.h>
|
||||
#include <Spectre/Scene/Camera2D.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Renderer2D
|
||||
{
|
||||
public :
|
||||
|
|
@ -28,4 +30,6 @@ protected :
|
|||
const Camera2D* m_camera;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_RENDERER2D_H */
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Shader
|
||||
{
|
||||
public :
|
||||
|
|
@ -51,4 +53,6 @@ protected :
|
|||
std::string m_error;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_SHADER_H */
|
||||
|
|
@ -6,6 +6,8 @@
|
|||
#include <Spectre/Math/Matrix4.h>
|
||||
#include "Shader.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
struct Color;
|
||||
|
||||
class ShaderProgram
|
||||
|
|
@ -83,4 +85,6 @@ protected :
|
|||
mutable std::string m_error;
|
||||
};
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_SHADER_PROGRAM_H */
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_SHADER_PROGRAM_H */
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
#include "Vertex2D.h"
|
||||
#include "Renderable.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Texture;
|
||||
|
||||
class Sprite : public Renderable2D
|
||||
|
|
@ -46,4 +48,6 @@ protected :
|
|||
const Texture* m_texture;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_SPRITE_H */
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
#include <Spectre/Graphics/Transformable.h>
|
||||
#include <Spectre/Graphics/Renderable.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Text : public Renderable2D
|
||||
{
|
||||
public :
|
||||
|
|
@ -88,4 +90,6 @@ private :
|
|||
mutable std::vector<Vertex2D> m_vertices;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_TEXT_H */
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
// Basic OpenGL Texture object.
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Texture : public NonCopyable
|
||||
{
|
||||
public:
|
||||
|
|
@ -88,4 +90,6 @@ protected :
|
|||
PixelFormat m_format;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_TEXTURE_H */
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <Spectre/Math/Transform.h>
|
||||
#include <Spectre/Math/Vector2.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Transformable
|
||||
{
|
||||
public :
|
||||
|
|
@ -56,4 +58,6 @@ private :
|
|||
mutable Transform m_transform;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_TRANSFORMABLE_H */
|
||||
|
|
@ -5,6 +5,8 @@
|
|||
#include <Spectre/Math/Vector2.h>
|
||||
#include <Spectre/Math/Vector4.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
// Based on https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php
|
||||
enum VertexAttrib
|
||||
{
|
||||
|
|
@ -27,4 +29,6 @@ struct Vertex2D
|
|||
Vertex2D(Vector2f pos, Vector4f color, Vector2f uv = 0.0f);
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_VERTEX2D_H */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "InputModule.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class InputDevice
|
||||
{
|
||||
friend class InputModule;
|
||||
|
|
@ -18,4 +20,6 @@ protected :
|
|||
virtual void update(InputModule *input) = 0;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_INTPUT_DEVICE_H */
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace sp {
|
||||
|
||||
namespace MouseButton {
|
||||
|
||||
enum Type {
|
||||
|
|
@ -120,7 +122,7 @@ typedef struct InputEvent
|
|||
MousePosition
|
||||
};
|
||||
|
||||
struct KeyEvent {
|
||||
struct KeyEvent {
|
||||
Key::Type code;
|
||||
bool pressed; /* true if pressed, false if released. */
|
||||
|
||||
|
|
@ -150,4 +152,6 @@ typedef struct InputEvent
|
|||
|
||||
} InputEvent;
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_INPUT_EVENT_H */
|
||||
|
|
|
|||
|
|
@ -4,10 +4,14 @@
|
|||
|
||||
#include "InputEvent.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class InputListener
|
||||
{
|
||||
public :
|
||||
virtual void onInputEvent(const InputEvent& event);
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_INPUT_LISTENER_H */
|
||||
|
|
@ -8,6 +8,8 @@
|
|||
#include "InputListener.h"
|
||||
#include "InputEvent.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Mouse;
|
||||
class Keyboard;
|
||||
class InputDevice;
|
||||
|
|
@ -38,7 +40,7 @@ public :
|
|||
protected :
|
||||
|
||||
void dispatch();
|
||||
|
||||
|
||||
typedef std::vector<InputDevice*> InputDeviceVec;
|
||||
InputDeviceVec m_devices;
|
||||
|
||||
|
|
@ -54,4 +56,6 @@ protected :
|
|||
PlatformInput *m_platform;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_INPUT_MODULE_H */
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
#include "InputEvent.h"
|
||||
#include "InputDevice.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Keyboard : public InputDevice
|
||||
{
|
||||
public :
|
||||
|
|
@ -16,4 +18,6 @@ public :
|
|||
static std::string getKeyName(Key::Type key);
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_INPUT_KEYBOARD_H */
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#include "InputEvent.h"
|
||||
#include "InputDevice.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Mouse : public InputDevice
|
||||
{
|
||||
public :
|
||||
|
|
@ -22,4 +24,6 @@ public :
|
|||
static std::string getButtonName(MouseButton::Type button);
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_INPUT_MOUSE_H */
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include "Vector3.h"
|
||||
#include "Vector4.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
// Basic structure representing a color in 32bit RGBA
|
||||
struct Color
|
||||
{
|
||||
|
|
@ -62,4 +64,6 @@ Color operator -(const Color& a, unsigned int s);
|
|||
Color operator /(const Color& a, unsigned int s);
|
||||
Color operator *(const Color& a, unsigned int s);
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_MATH_COLOR_H */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include "Vector2.h"
|
||||
#include "Matrix4.h"
|
||||
|
||||
namespace math
|
||||
namespace sp { namespace math
|
||||
{
|
||||
float rand(float min, float max);
|
||||
|
||||
|
|
@ -28,13 +28,13 @@ namespace math
|
|||
// ------------------------------
|
||||
|
||||
// Create a orthographic projection matrix.
|
||||
Matrix4f orthoProjection(float left, float right,
|
||||
float bottom, float top,
|
||||
Matrix4f orthoProjection(float left, float right,
|
||||
float bottom, float top,
|
||||
float zNear = -1.0f, float zFar = 1.0f);
|
||||
|
||||
// Create a 2D rotation matrix. (rotation around Z-axis)
|
||||
Matrix4f rotation(float theta);
|
||||
|
||||
|
||||
// Create a 2D translation matrix.
|
||||
Matrix4f translate(const Vector2f& v);
|
||||
|
||||
|
|
@ -47,6 +47,7 @@ namespace math
|
|||
Vector3f getUpVector(const Matrix4f matrix);
|
||||
|
||||
Vector3f getForwardVector(const Matrix4f matrix);
|
||||
};
|
||||
|
||||
} } // namespace sp
|
||||
|
||||
#endif /* SPECTRE_MATH_MATH_H */
|
||||
|
|
@ -7,6 +7,8 @@
|
|||
#include <iostream>
|
||||
#include <Spectre/Math/Vector2.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
template<typename T>
|
||||
struct Matrix3
|
||||
{
|
||||
|
|
@ -20,7 +22,7 @@ struct Matrix3
|
|||
| 0 3 6 |
|
||||
| 1 4 7 |
|
||||
| 2 5 8 |
|
||||
|_ _|
|
||||
|_ _|
|
||||
*/
|
||||
T v[9];
|
||||
};
|
||||
|
|
@ -77,6 +79,8 @@ typedef Matrix3<double> Matrix3d;
|
|||
typedef Matrix3<int> Matrix3i;
|
||||
typedef Matrix3<unsigned> Matrix3u;
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#include "Matrix3.inl"
|
||||
|
||||
#endif /* SPECTRE_MATH_MATRIX3_H */
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
#include <string>
|
||||
#include "Matrix3.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
template <>
|
||||
Matrix3f Matrix3f::Identity(
|
||||
1, 0, 0,
|
||||
|
|
@ -120,3 +122,5 @@ inline std::ostream& operator<<(std::ostream &s, const Matrix3<T>& mat)
|
|||
<< mat.v[1] << " " << mat.v[4] << " " << mat.v[7] << std::endl
|
||||
<< mat.v[2] << " " << mat.v[5] << " " << mat.v[8] << std::endl;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include <Spectre/Math/Vector3.h>
|
||||
#include <Spectre/Math/Vector2.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
template<typename T>
|
||||
struct Matrix4
|
||||
{
|
||||
|
|
@ -100,10 +102,11 @@ typedef Matrix4<double> mat4d;
|
|||
typedef Matrix4<int> mat4i;
|
||||
typedef Matrix4<unsigned> mat4u;
|
||||
|
||||
} // namespace sp
|
||||
|
||||
// ----------------
|
||||
// Implementation
|
||||
// ----------------
|
||||
|
||||
#include "Matrix4.inl"
|
||||
|
||||
#endif /* SPECTRE_MATH_MATRIX4_H */
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
#include <string.h>
|
||||
#include "Matrix4.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
template<typename T>
|
||||
const Matrix4<T> Matrix4<T>::Identity(
|
||||
1, 0, 0, 0,
|
||||
|
|
@ -152,3 +154,5 @@ inline std::ostream& operator<<(std::ostream &s, const Matrix4<T>& mat)
|
|||
{
|
||||
return s << mat.toString();
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -5,6 +5,8 @@
|
|||
#include "Vector2.h"
|
||||
#include "Matrix4.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
// Class representing a transformation matrix.
|
||||
|
||||
class Transform
|
||||
|
|
@ -75,4 +77,6 @@ Transform& operator*=(Transform& a, const Transform& b);
|
|||
|
||||
Vector2f operator*(const Transform& t, const Vector2f& v);
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_MATH_TRANSFORM_H */
|
||||
|
|
@ -5,11 +5,13 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace sp {
|
||||
|
||||
template <typename T>
|
||||
struct Vector2
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
struct {
|
||||
T x, y;
|
||||
};
|
||||
T v[2];
|
||||
|
|
@ -111,7 +113,7 @@ template <typename T>
|
|||
inline Vector2<T> operator+(T s, const Vector2<T>& v);
|
||||
|
||||
template <typename T>
|
||||
inline Vector2<T> operator-(const Vector2<T>& v,T s);
|
||||
inline Vector2<T> operator-(const Vector2<T>& v, T s);
|
||||
|
||||
template <typename T>
|
||||
inline Vector2<T> operator-(T s, const Vector2<T>& v);
|
||||
|
|
@ -132,7 +134,7 @@ template <typename T>
|
|||
inline Vector2<T>& operator+=(Vector2<T>& v, T s);
|
||||
|
||||
template <typename T>
|
||||
inline Vector2<T>& operator-=(Vector2<T>& v,T s);
|
||||
inline Vector2<T>& operator-=(Vector2<T>& v, T s);
|
||||
|
||||
template <typename T>
|
||||
inline Vector2<T>& operator/=(Vector2<T>& v, T s);
|
||||
|
|
@ -190,6 +192,8 @@ typedef Vector2<int> vec2i;
|
|||
typedef Vector2<unsigned> vec2u;
|
||||
typedef Vector2<unsigned char> vec2b;
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#include "Vector2.inl"
|
||||
|
||||
#endif /* SPECTRE_MATH_VECTOR2_H */
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
#include <math.h>
|
||||
#include "Vector2.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
template <typename T>
|
||||
Vector2<T>::Vector2()
|
||||
{
|
||||
|
|
@ -314,3 +316,5 @@ inline std::ostream& operator<<(std::ostream &s, const Vector2<T>& v)
|
|||
{
|
||||
return s << "(" << v.x << "," << v.y << ")";
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -5,6 +5,8 @@
|
|||
#include "Vector2.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace sp {
|
||||
|
||||
template <typename T>
|
||||
struct Vector3
|
||||
{
|
||||
|
|
@ -167,6 +169,8 @@ typedef Vector3<int> vec3i;
|
|||
typedef Vector3<unsigned> vec3u;
|
||||
typedef Vector3<unsigned char> vec3b;
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#include "Vector3.inl"
|
||||
|
||||
#endif /* SPECTRE_MATH_VECTOR3_H */
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include <math.h>
|
||||
#include "Vector3.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
template <typename T>
|
||||
Vector3<T>::Vector3()
|
||||
{
|
||||
|
|
@ -265,3 +267,5 @@ inline std::ostream& operator<<(std::ostream &s, const Vector3<T>& v)
|
|||
{
|
||||
return s << "(" << v.x << "," << v.y << "," << v.z << ")";
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
namespace sp {
|
||||
|
||||
template <typename T>
|
||||
struct Vector4
|
||||
{
|
||||
|
|
@ -153,6 +155,8 @@ typedef Vector4<int> vec4i;
|
|||
typedef Vector4<unsigned> vec4u;
|
||||
typedef Vector4<unsigned char> vec4b;
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#include "Vector4.inl"
|
||||
|
||||
#endif /* SPECTRE_MATH_VECTOR4_H */
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include <math.h>
|
||||
#include "Vector4.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
template <typename T>
|
||||
Vector4<T>::Vector4()
|
||||
{
|
||||
|
|
@ -252,3 +254,5 @@ inline std::ostream& operator<<(std::ostream &s, const Vector4<T>& v)
|
|||
{
|
||||
return s << "(" << v.x << "," << v.y << "," << v.z << "," << v.w << ")";
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
// TODO: Zoom is implemented using a scale matrix.
|
||||
// It's abit weird to control. Must be a better solution.
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Camera2D : public ICamera
|
||||
{
|
||||
public :
|
||||
|
|
@ -29,7 +31,7 @@ public :
|
|||
|
||||
void move(float x, float y);
|
||||
void move(const Vector2f& vec);
|
||||
|
||||
|
||||
void moveUp(float delta);
|
||||
void moveRight(float delta);
|
||||
|
||||
|
|
@ -80,4 +82,6 @@ protected :
|
|||
mutable bool m_projViewNeedsUpdate;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_SCENE_CAMERA2D_H */
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <Spectre/Math/Matrix4.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
// Camera interface.
|
||||
class ICamera
|
||||
{
|
||||
|
|
@ -17,4 +19,6 @@ public :
|
|||
virtual const Matrix4f& getProjectionViewMatrix() const = 0;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_SCENE_ICAMERA_H */
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace File
|
||||
namespace sp { namespace file
|
||||
{
|
||||
std::string getBasename(const std::string& path);
|
||||
|
||||
|
|
@ -14,6 +14,6 @@ namespace File
|
|||
std::string getPathname(const std::string& path);
|
||||
|
||||
std::vector<unsigned char> read(const std::string& path);
|
||||
};
|
||||
} }
|
||||
|
||||
#endif /* SPECTRE_SYSTEM_FILE_H */
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@
|
|||
#ifndef SYSTEM_LOG_H
|
||||
#define SYSTEM_LOG_H
|
||||
|
||||
void log(const char *fmt, ...);
|
||||
namespace sp {
|
||||
|
||||
void log(const char *fmt, ...);
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SYSTEM_LOG_H */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "SystemEvent.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Display;
|
||||
|
||||
class MessageHandler
|
||||
|
|
@ -12,4 +14,6 @@ public :
|
|||
virtual void onSizeChanged(Display* display, int width, int height);
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_SYSTEM_MESSAGEHANDLER_H */
|
||||
|
|
@ -5,6 +5,8 @@
|
|||
#include <Spectre/System/SystemEvent.h>
|
||||
#include <queue>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class MessageQueue
|
||||
{
|
||||
public :
|
||||
|
|
@ -18,4 +20,6 @@ protected :
|
|||
std::deque<SysEvent> m_queue;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_MESSAGE_QUEUE_H */
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@
|
|||
#ifndef SPECTRE_SYSTEM_SYSTEM_H
|
||||
#define SPECTRE_SYSTEM_SYSTEM_H
|
||||
|
||||
namespace System
|
||||
namespace sp { namespace system
|
||||
{
|
||||
unsigned long getMilliseconds();
|
||||
|
||||
void sleep(int milliseconds);
|
||||
};
|
||||
|
||||
} } // namespace sp::system
|
||||
|
||||
#endif /* SPECTRE_SYSTEM_SYSTEM_H */
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#ifndef SYSTEM_EVENT_H
|
||||
#define SYSTEM_EVENT_H
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Display;
|
||||
|
||||
struct SysEvent
|
||||
|
|
@ -32,7 +34,8 @@ public :
|
|||
// Helper methods
|
||||
|
||||
static SysEvent sizeEvent(Display *display, int width, int height);
|
||||
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SYSTEM_EVENT_H */
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
#include <cstdio>
|
||||
#include <Spectre/Core/String.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
std::string core::to_string(unsigned int value)
|
||||
{
|
||||
char buf[32];
|
||||
|
|
@ -23,3 +25,5 @@ std::string core::to_string(float value, unsigned int precision)
|
|||
sprintf(buf, format.c_str(), value);
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
} // namespace sp::core
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <Spectre/System/SystemEvent.h>
|
||||
#include <Platform/PlatformDisplay.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
#define CAPTION_DEFAULT "Spectre"
|
||||
#define ICON_DEFAULT "./assets/app.ico"
|
||||
|
||||
|
|
@ -147,4 +149,6 @@ void Display::onReshape(int width, int height)
|
|||
{
|
||||
// Resize context if the windows resizes.
|
||||
m_context->setSize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Display/DisplayDescription.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
DisplayDescription::DisplayDescription() :
|
||||
mode (),
|
||||
decoration (DisplayDecorate::Default)
|
||||
|
|
@ -11,4 +13,6 @@ DisplayDescription::DisplayDescription(DisplayMode mode, unsigned decoration) :
|
|||
mode (mode),
|
||||
decoration (decoration)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,9 +3,11 @@
|
|||
#include <Platform/PlatformMisc.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace sp {
|
||||
|
||||
struct DisplayModeCmp
|
||||
{
|
||||
inline bool operator() (const DisplayMode& a, const DisplayMode& b)
|
||||
inline bool operator() (const DisplayMode& a, const DisplayMode& b)
|
||||
{
|
||||
if (a.bpp == b.bpp) {
|
||||
if (a.width == b.width) {
|
||||
|
|
@ -51,4 +53,6 @@ std::vector<DisplayMode> DisplayMode::getFullscreenModes()
|
|||
DisplayMode DisplayMode::getDesktopMode()
|
||||
{
|
||||
return PlatformMisc::GetDesktopMode();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,11 +3,13 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
#include <Platform/Win32/Win32GLContext.h>
|
||||
typedef Win32GLContext ContextType;
|
||||
typedef sp::Win32GLContext ContextType;
|
||||
#else
|
||||
#error "No GLContext implementation exists"
|
||||
#endif
|
||||
|
||||
namespace sp {
|
||||
|
||||
GLContext* GLContext::create()
|
||||
{
|
||||
return new ContextType();
|
||||
|
|
@ -17,3 +19,5 @@ GLContext::~GLContext()
|
|||
{
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include <Platform/Win32/Win32Application.h>
|
||||
#include <Spectre/Game.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Game::Game()
|
||||
{
|
||||
m_platform = new Win32Application();
|
||||
|
|
@ -64,7 +66,7 @@ void Game::gameLoop()
|
|||
m_fpsCounter.addFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Game::processEvents()
|
||||
{
|
||||
|
|
@ -107,3 +109,5 @@ FPSCounter& Game::getFpsCounter()
|
|||
{
|
||||
return m_fpsCounter;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include <Spectre/Game/FPSCounter.h>
|
||||
#include <Spectre/System/System.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
FPSCounter::FPSCounter() :
|
||||
m_fps (60.0f),
|
||||
m_updateRate (2000)
|
||||
|
|
@ -34,7 +36,7 @@ void FPSCounter::setUpdateRate(unsigned int ups)
|
|||
|
||||
bool FPSCounter::update()
|
||||
{
|
||||
unsigned int current = System::getMilliseconds();
|
||||
unsigned int current = system::getMilliseconds();
|
||||
unsigned int elapsed = current - m_time;
|
||||
|
||||
if (elapsed >= m_updateRate) {
|
||||
|
|
@ -50,6 +52,8 @@ bool FPSCounter::update()
|
|||
|
||||
void FPSCounter::reset()
|
||||
{
|
||||
m_time = System::getMilliseconds();
|
||||
m_time = system::getMilliseconds();
|
||||
m_count = 0;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@
|
|||
#include <Spectre/Game/GameTime.h>
|
||||
#include <Spectre/System/System.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
GameTime::GameTime(unsigned long updates_per_sec)
|
||||
{
|
||||
m_acc = 0;
|
||||
m_current = System::getMilliseconds();
|
||||
m_current = system::getMilliseconds();
|
||||
m_lastUpdate = m_current;
|
||||
setTimeStep(updates_per_sec);
|
||||
}
|
||||
|
|
@ -67,10 +69,12 @@ void GameTime::accumulateTime()
|
|||
|
||||
void GameTime::updateTime()
|
||||
{
|
||||
m_current = System::getMilliseconds();
|
||||
m_current = system::getMilliseconds();
|
||||
|
||||
// Just to be safe. check so we don't get a negative interval.
|
||||
if (m_current < m_lastUpdate) {
|
||||
m_lastUpdate = m_current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
namespace sp {
|
||||
|
||||
static bool compare_renderable(const Renderable2D* a, const Renderable2D* b) {
|
||||
|
||||
if (a->getZOrder() != b->getZOrder()) {
|
||||
|
|
@ -256,4 +258,6 @@ void BatchRenderer2D::drawBatch(Batch& batch)
|
|||
if (batch.type == RenderType_UI) {
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include <Spectre/Graphics/Renderable.h>
|
||||
#include <Spectre/Graphics/DefaultRenderer2D.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
DefaultRenderer2D::DefaultRenderer2D()
|
||||
{
|
||||
m_shader.create();
|
||||
|
|
@ -69,4 +71,6 @@ void DefaultRenderer2D::render()
|
|||
|
||||
m_shader.disable();
|
||||
m_queue.clear();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -7,6 +7,8 @@
|
|||
#include <Spectre/Math/Math.h>
|
||||
#include "Font/FreeTypeDriver.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
Font::Font() :
|
||||
m_driver (new FreeTypeDriver())
|
||||
{
|
||||
|
|
@ -124,3 +126,5 @@ const Texture* Font::getTexture() const
|
|||
{
|
||||
return &m_cacheTextureA.texture;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "FontDriver.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
FontDriver::FontDriver() :
|
||||
m_hinting (true)
|
||||
{
|
||||
|
|
@ -9,4 +11,6 @@ m_hinting (true)
|
|||
void FontDriver::setHinting(bool value)
|
||||
{
|
||||
m_hinting = value;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -6,6 +6,8 @@
|
|||
#include <Spectre/Graphics/Image.h>
|
||||
#include <Spectre/Graphics/Font.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class FontDriver
|
||||
{
|
||||
public :
|
||||
|
|
@ -28,4 +30,6 @@ protected :
|
|||
bool m_hinting;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_FONT_FONTDRIVER_H */
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include "FreeTypeError.h"
|
||||
#include "FreeTypeDriver.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class LibWrapper
|
||||
{
|
||||
public :
|
||||
|
|
@ -165,4 +167,6 @@ Font::Glyph FreeTypeDriver::loadGlyph(unsigned int codepoint, Image& img, unsign
|
|||
std::string FreeTypeDriver::getName()
|
||||
{
|
||||
return m_face->family_name;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
@ -5,8 +5,11 @@
|
|||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
#include <string>
|
||||
#include "FontDriver.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class FreeTypeDriver : public FontDriver
|
||||
{
|
||||
public:
|
||||
|
|
@ -26,4 +29,6 @@ private :
|
|||
FT_Face m_face;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_FONT_FREETYPEDRIVER_H */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include <Spectre/Graphics/Image.h>
|
||||
#include "ImageLoader.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
static ImageLoader _loader;
|
||||
|
||||
Image::Image() :
|
||||
|
|
@ -207,3 +209,5 @@ const unsigned char* Image::getPixels() const
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -21,6 +21,8 @@
|
|||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
namespace sp {
|
||||
|
||||
bool ImageLoader::loadFromFile(const char *filename, Image& img)
|
||||
{
|
||||
FILE *fd = fopen(filename, "rb");
|
||||
|
|
@ -59,7 +61,7 @@ bool ImageLoader::loadFromMemory(const void *data, unsigned size, Image& img)
|
|||
// TODO: Support more formats.
|
||||
bool ImageLoader::saveToFile(const Image& img, const char *filename)
|
||||
{
|
||||
std::string ext = File::getExtension(filename);
|
||||
std::string ext = file::getExtension(filename);
|
||||
std::vector<unsigned char> encoded_data;
|
||||
|
||||
if (ext == "png") {
|
||||
|
|
@ -129,3 +131,5 @@ bool ImageLoader::encodePNG(const Image& img, std::vector<unsigned char>& data)
|
|||
m_error = stbi_failure_reason();
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
#include <Spectre/Math/Vector2.h>
|
||||
#include <vector>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class ImageLoader
|
||||
{
|
||||
public :
|
||||
|
|
@ -30,4 +32,6 @@ protected :
|
|||
std::string m_error;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_IMAGE_LOADER_H */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include <Spectre/Graphics/Texture.h>
|
||||
#include <Spectre/Graphics/RenderState.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
RenderState::RenderState() :
|
||||
m_texture (0),
|
||||
m_shader (0)
|
||||
|
|
@ -45,4 +47,6 @@ void RenderState::cleanup()
|
|||
if (m_shader) {
|
||||
m_shader->disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Graphics/Renderable.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Renderable2D::Renderable2D() :
|
||||
m_zorder (0)
|
||||
{
|
||||
|
|
@ -24,4 +26,6 @@ unsigned char Renderable2D::getZOrder() const
|
|||
void Renderable2D::setZOrder(unsigned char value)
|
||||
{
|
||||
m_zorder = value;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
#include <Spectre/Graphics/Renderer2D.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Renderer2D::Renderer2D() :
|
||||
m_camera (NULL)
|
||||
{
|
||||
|
|
@ -13,3 +15,5 @@ void Renderer2D::setCamera(const Camera2D& camera)
|
|||
{
|
||||
m_camera = &camera;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
#include <Spectre/Graphics/OpenGL.h>
|
||||
#include <Spectre/Graphics/Shader.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Shader::Shader(Type type, const std::string& name) :
|
||||
m_name (name)
|
||||
{
|
||||
|
|
@ -35,7 +37,7 @@ bool Shader::loadFromFile(const std::string& file)
|
|||
|
||||
// If this shader does not have a name, pick the filename.
|
||||
if (m_name.length() < 1) {
|
||||
m_name = File::getBasename(file);
|
||||
m_name = file::getBasename(file);
|
||||
}
|
||||
|
||||
// Load file into memory.
|
||||
|
|
@ -98,3 +100,5 @@ std::string Shader::fetchErrorLog()
|
|||
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
#include <Spectre/Graphics/ShaderProgram.h>
|
||||
#include <Spectre/System/File.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
ShaderProgram::ShaderProgram() :
|
||||
m_id (0)
|
||||
{
|
||||
|
|
@ -36,7 +38,7 @@ void ShaderProgram::addShader(const Shader& shader)
|
|||
|
||||
bool ShaderProgram::loadFromFile(const std::string& filename)
|
||||
{
|
||||
std::string extension = File::getExtension(filename);
|
||||
std::string extension = file::getExtension(filename);
|
||||
|
||||
// Meta file. load real shaders.
|
||||
if (extension == "shader.glsl") {
|
||||
|
|
@ -191,3 +193,5 @@ std::string ShaderProgram::fetchErrorLog()
|
|||
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
#include <Spectre/Graphics/Texture.h>
|
||||
#include <Spectre/Graphics/Sprite.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Sprite::Sprite() :
|
||||
m_texture (NULL)
|
||||
{
|
||||
|
|
@ -114,4 +116,6 @@ void Sprite::updateGeometry()
|
|||
void Sprite::render(Renderer2D& renderer) const
|
||||
{
|
||||
renderer.draw(this);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
#include <Spectre/Graphics/Renderer2D.h>
|
||||
#include <Spectre/Graphics/Text.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Text::Text() :
|
||||
m_font (NULL),
|
||||
m_size (22),
|
||||
|
|
@ -173,4 +175,6 @@ void Text::updateGeometry() const
|
|||
void Text::render(Renderer2D& renderer) const
|
||||
{
|
||||
renderer.draw(this);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
#include <Spectre/Graphics/OpenGL.h>
|
||||
#include <Spectre/Graphics/Texture.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
namespace {
|
||||
|
||||
GLint pixelFormatToInternal(enum PixelFormat format) {
|
||||
|
|
@ -252,3 +254,5 @@ bool Texture::operator!=(const Texture* other) const
|
|||
{
|
||||
return m_id != other->m_id;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Graphics/Transformable.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Transformable::Transformable() :
|
||||
m_position (0.0f, 0.0f),
|
||||
m_scale (1.0f, 1.0f),
|
||||
|
|
@ -92,4 +94,6 @@ const Transform& Transformable::getTransform() const
|
|||
m_transformNeedsUpdate = false;
|
||||
}
|
||||
return m_transform;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Graphics/Vertex2D.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Vertex2D::Vertex2D() :
|
||||
position (0.0f),
|
||||
color (1.0f),
|
||||
|
|
@ -28,3 +30,5 @@ color (_color),
|
|||
uv (_uv)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
#include <Spectre/Graphics/OpenGL.h>
|
||||
#include <string>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Graphics::Graphics(PlatformApplication *platform)
|
||||
{
|
||||
m_width = 800;
|
||||
|
|
@ -87,3 +89,5 @@ void Graphics::swapBuffers()
|
|||
{
|
||||
m_display->swapBuffers();
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Input/InputDevice.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
InputDevice::~InputDevice()
|
||||
{
|
||||
}
|
||||
|
|
@ -8,3 +10,5 @@ InputDevice::~InputDevice()
|
|||
void InputDevice::init()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
#include <Spectre/Input/Keyboard.h>
|
||||
#include <Spectre/Input/InputEvent.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
InputEvent::InputEvent(Type type) :
|
||||
type (type)
|
||||
{
|
||||
|
|
@ -17,3 +19,5 @@ std::string InputEvent::MouseButtonEvent::getName() const
|
|||
{
|
||||
return Mouse::getButtonName(button);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
|
||||
#include <Spectre/Input/InputListener.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
void InputListener::onInputEvent(const InputEvent& event)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -6,6 +6,8 @@
|
|||
#include <Spectre/Input/InputDevice.h>
|
||||
#include <Spectre/Input/InputModule.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
InputModule::InputModule(PlatformInput *platform) :
|
||||
m_platform (platform)
|
||||
{
|
||||
|
|
@ -94,3 +96,5 @@ void InputModule::dispatch()
|
|||
|
||||
m_buffer.clear();
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Input/Keyboard.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
struct keyentry
|
||||
{
|
||||
Key::Type type;
|
||||
|
|
@ -110,3 +112,5 @@ std::string Keyboard::getKeyName(Key::Type key)
|
|||
}
|
||||
return table[key].name;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Input/Mouse.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Mouse::~Mouse()
|
||||
{
|
||||
}
|
||||
|
|
@ -18,3 +20,5 @@ std::string Mouse::getButtonName(MouseButton::Type button)
|
|||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Math/Color.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
const Color Color::Black (0 , 0 , 0 , 255);
|
||||
const Color Color::White (255, 255, 255, 255);
|
||||
const Color Color::Red (255, 0 , 0 , 255);
|
||||
|
|
@ -126,3 +128,5 @@ Color operator *(const Color& c, unsigned int s)
|
|||
{
|
||||
return Color(c.r * s, c.g * s, c.b * s, c.a * s);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,18 +3,18 @@
|
|||
#include <cstdlib>
|
||||
#include <Spectre/Math/Math.h>
|
||||
|
||||
namespace math {
|
||||
namespace sp {
|
||||
|
||||
#define LOG2INBASE10 0.30102999566f
|
||||
#define LOG2INBASE10 0.30102999566f
|
||||
|
||||
double log(double base, double value) {
|
||||
double math::log(double base, double value) {
|
||||
|
||||
return log10(value) / log10(base);
|
||||
}
|
||||
return ::log10(value) / ::log10(base);
|
||||
}
|
||||
|
||||
double log2(double value) {
|
||||
double math::log2(double value) {
|
||||
|
||||
return log10(value) / LOG2INBASE10;
|
||||
}
|
||||
return ::log10(value) / LOG2INBASE10;
|
||||
}
|
||||
|
||||
}; // namespace math
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
#include <cstdlib>
|
||||
#include <Spectre/Math/Math.h>
|
||||
|
||||
namespace math {
|
||||
|
||||
namespace sp { namespace math
|
||||
{
|
||||
float rand(float min, float max) {
|
||||
|
||||
float r = ((float) ::rand()) / RAND_MAX;
|
||||
|
|
@ -50,8 +50,8 @@ namespace math {
|
|||
Matrix4f rotation(float theta) {
|
||||
|
||||
float r = deg2rad(theta);
|
||||
float s = std::sin(r);
|
||||
float c = std::cos(r);
|
||||
float s = ::std::sin(r);
|
||||
float c = ::std::cos(r);
|
||||
|
||||
return Matrix4f(
|
||||
c, -s, 0.0f, 0.0f,
|
||||
|
|
@ -94,4 +94,5 @@ namespace math {
|
|||
|
||||
return Vector3f(matrix.e[8], matrix.e[9], matrix.e[10]);
|
||||
}
|
||||
};
|
||||
|
||||
} } // namespace sp::math
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include <Spectre/Math/Math.h>
|
||||
#include <Spectre/Math/Transform.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Transform::Transform() :
|
||||
m_matrix (Matrix4f::Identity)
|
||||
{
|
||||
|
|
@ -155,4 +157,6 @@ Transform& operator*=(Transform& a, const Transform& other)
|
|||
Vector2f operator*(const Transform& transform, const Vector2f& vec)
|
||||
{
|
||||
return transform.transformPoint(vec);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#ifndef SPECTRE_PLATFORM_H
|
||||
#define SPECTRE_PLATFORM_H
|
||||
|
||||
namespace sp {
|
||||
|
||||
class PlatformInput;
|
||||
class PlatformDisplay;
|
||||
class MessageQueue;
|
||||
|
|
@ -22,4 +24,6 @@ public :
|
|||
virtual void update() = 0;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_PLATFORM_H */
|
||||
|
|
@ -4,11 +4,13 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
#include <Platform/Win32/Win32Display.h>
|
||||
typedef Win32Display DisplayType;
|
||||
typedef sp::Win32Display DisplayType;
|
||||
#else
|
||||
#error "No Display implementation exists"
|
||||
#endif
|
||||
|
||||
namespace sp {
|
||||
|
||||
PlatformDisplay* PlatformDisplay::make(Display* parent)
|
||||
{
|
||||
DisplayType* disp = new DisplayType();
|
||||
|
|
@ -29,4 +31,6 @@ void PlatformDisplay::onReshape(int width, int height)
|
|||
{
|
||||
// Forward to parent.
|
||||
m_parent->onReshape(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -8,6 +8,8 @@
|
|||
// Low-level platform dependant API.
|
||||
#include <string>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Display;
|
||||
|
||||
class PlatformDisplay
|
||||
|
|
@ -46,7 +48,9 @@ protected :
|
|||
|
||||
private :
|
||||
|
||||
Display* m_parent;
|
||||
Display * m_parent;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_PLATFORM_DISPLAY_H */
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
#ifndef PLATFORM_INPUT_H
|
||||
#define PLATFORM_INPUT_H
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Keyboard;
|
||||
class Mouse;
|
||||
|
||||
|
|
@ -15,4 +17,6 @@ public :
|
|||
virtual void update() = 0;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* PLATFORM_INPUT_H */
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
#define PLATFORM_MISC_H
|
||||
|
||||
#include <Spectre/Display/DisplayMode.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class DisplayMode;
|
||||
|
||||
class PlatformMisc
|
||||
|
|
@ -16,4 +17,6 @@ public:
|
|||
static DisplayMode GetDesktopMode();
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* PLATFORM_MISC_H */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include "Win32Mouse.h"
|
||||
#include "Win32Application.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
void Win32Application::init()
|
||||
{
|
||||
}
|
||||
|
|
@ -94,3 +96,5 @@ LRESULT Win32Application::processMessage(MSG msg)
|
|||
// Message was not intercepted. Pass down to window.
|
||||
return DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -9,6 +9,8 @@
|
|||
#include <Spectre/System/MessageQueue.h>
|
||||
#include <Platform/PlatformApplication.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Win32Application : public PlatformApplication
|
||||
{
|
||||
public :
|
||||
|
|
@ -35,4 +37,6 @@ protected :
|
|||
MessageQueue m_messageQueue;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* WIN32_PLATFORM_H */
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue