aboutsummaryrefslogtreecommitdiff
path: root/src/libjin
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin')
-rw-r--r--src/libjin/ai/je_behavior_tree.h4
-rw-r--r--src/libjin/audio/SDL/je_sdl_source.h4
-rw-r--r--src/libjin/audio/je_source.h4
-rw-r--r--src/libjin/common/je_exception.h5
-rw-r--r--src/libjin/common/je_noncopyable.h4
-rw-r--r--src/libjin/common/je_object.h4
-rw-r--r--src/libjin/common/je_pool.hpp4
-rw-r--r--src/libjin/common/je_singleton.hpp4
-rw-r--r--src/libjin/common/je_stringmap.hpp4
-rw-r--r--src/libjin/common/je_temporary.h4
-rw-r--r--src/libjin/common/je_utf8.h2
-rw-r--r--src/libjin/filesystem/je_asset_database.h2
-rw-r--r--src/libjin/game/je_entity.cpp0
-rw-r--r--src/libjin/game/je_entity.h27
-rw-r--r--src/libjin/game/je_gameobject.cpp2
-rw-r--r--src/libjin/game/je_gameobject.h48
-rw-r--r--src/libjin/game/je_scene.cpp0
-rw-r--r--src/libjin/game/je_scene.h73
-rw-r--r--src/libjin/graphics/animations/je_animation.h4
-rw-r--r--src/libjin/graphics/animations/je_animator.h3
-rw-r--r--src/libjin/graphics/fonts/je_decoder.h4
-rw-r--r--src/libjin/graphics/fonts/je_font.h2
-rw-r--r--src/libjin/graphics/fonts/je_text.h4
-rw-r--r--src/libjin/graphics/fonts/je_ttf.h4
-rw-r--r--src/libjin/graphics/je_bitmap.h2
-rw-r--r--src/libjin/graphics/je_gl.cpp110
-rw-r--r--src/libjin/graphics/je_gl.h127
-rw-r--r--src/libjin/graphics/je_graphic.h3
-rw-r--r--src/libjin/graphics/je_image.h3
-rw-r--r--src/libjin/graphics/je_mesh.h1
-rw-r--r--src/libjin/graphics/je_sprite.h2
-rw-r--r--src/libjin/graphics/je_sprite_batch.h4
-rw-r--r--src/libjin/graphics/je_window.cpp9
-rw-r--r--src/libjin/math/je_percentage.h36
-rw-r--r--src/libjin/math/je_ranged_value.cpp71
-rw-r--r--src/libjin/math/je_ranged_value.h57
-rw-r--r--src/libjin/math/je_transform.h2
-rw-r--r--src/libjin/math/je_vector2.hpp5
38 files changed, 457 insertions, 191 deletions
diff --git a/src/libjin/ai/je_behavior_tree.h b/src/libjin/ai/je_behavior_tree.h
index 173df80..982e89e 100644
--- a/src/libjin/ai/je_behavior_tree.h
+++ b/src/libjin/ai/je_behavior_tree.h
@@ -14,12 +14,12 @@ namespace JinEngine
///
///
///
- class BehaviorTree
+ class BehaviorTree : public Object
{
public:
BehaviorTree(void* userData) : mUserData(userData){}
- class Node
+ class Node : public Object
{
public:
enum Type
diff --git a/src/libjin/audio/SDL/je_sdl_source.h b/src/libjin/audio/SDL/je_sdl_source.h
index bbc8c7a..07333ae 100644
--- a/src/libjin/audio/SDL/je_sdl_source.h
+++ b/src/libjin/audio/SDL/je_sdl_source.h
@@ -189,7 +189,7 @@ namespace JinEngine
///
/// Source manager.
///
- class SDLSourceManager
+ class SDLSourceManager : public Object
{
public:
///
@@ -255,7 +255,7 @@ namespace JinEngine
};
- class SourceException : public std::exception
+ class SourceException : public Object, public std::exception
{
const char* what() const throw ()
{
diff --git a/src/libjin/audio/je_source.h b/src/libjin/audio/je_source.h
index f60daf9..9b7bff0 100644
--- a/src/libjin/audio/je_source.h
+++ b/src/libjin/audio/je_source.h
@@ -3,6 +3,8 @@
#include "../core/je_configuration.h"
#if defined(jin_audio)
+#include "../common/je_object.h"
+
#include "SDL2/SDL.h"
namespace JinEngine
@@ -23,7 +25,7 @@ namespace JinEngine
///
/// Audio source.
///
- class Source
+ class Source : public Object
{
public:
///
diff --git a/src/libjin/common/je_exception.h b/src/libjin/common/je_exception.h
index c319ebd..71caa5a 100644
--- a/src/libjin/common/je_exception.h
+++ b/src/libjin/common/je_exception.h
@@ -4,16 +4,17 @@
#include <exception>
#include <string>
+#include "je_object.h"
+
namespace JinEngine
{
///
/// Jin Exception.
///
- class Exception : public std::exception
+ class Exception : public Object, public std::exception
{
public:
-
///
/// Creates a new Exception according to printf-rules.
///
diff --git a/src/libjin/common/je_noncopyable.h b/src/libjin/common/je_noncopyable.h
index eff7121..dab74a4 100644
--- a/src/libjin/common/je_noncopyable.h
+++ b/src/libjin/common/je_noncopyable.h
@@ -1,13 +1,15 @@
#ifndef __JE_NONCOPYABLE_H__
#define __JE_NONCOPYABLE_H__
+#include "je_object.h"
+
namespace JinEngine
{
///
/// Class inherites this could not be copied.
///
- class Noncopyable
+ class Noncopyable : public Object
{
public:
Noncopyable(void) { }
diff --git a/src/libjin/common/je_object.h b/src/libjin/common/je_object.h
index fb8221f..677b474 100644
--- a/src/libjin/common/je_object.h
+++ b/src/libjin/common/je_object.h
@@ -5,10 +5,12 @@ namespace JinEngine
{
///
- /// Base class of all objects in Jin.
+ /// Base class of all classes in libjin.
///
class Object
{
+ public:
+ virtual ~Object() {};
};
} // namespace JinEngine
diff --git a/src/libjin/common/je_pool.hpp b/src/libjin/common/je_pool.hpp
index cb96c5b..0758b97 100644
--- a/src/libjin/common/je_pool.hpp
+++ b/src/libjin/common/je_pool.hpp
@@ -12,7 +12,7 @@
namespace JinEngine
{
- class DefaultMemoryAllocator
+ class DefaultMemoryAllocator : public Object
{
public:
static inline void *Allocate(size_t size)
@@ -26,7 +26,7 @@ namespace JinEngine
};
template<typename T, class TMemoryAllocator = DefaultMemoryAllocator>
- class Pool
+ class Pool : public Object
{
private:
struct _Node
diff --git a/src/libjin/common/je_singleton.hpp b/src/libjin/common/je_singleton.hpp
index 2f387df..ba13b80 100644
--- a/src/libjin/common/je_singleton.hpp
+++ b/src/libjin/common/je_singleton.hpp
@@ -1,6 +1,8 @@
#ifndef __JE_SINGLETON_H__
#define __JE_SINGLETON_H__
+#include "je_object.h"
+
namespace JinEngine
{
@@ -8,7 +10,7 @@ namespace JinEngine
/// Singleton base class.
///
template<class T>
- class Singleton
+ class Singleton : public Object
{
public:
///
diff --git a/src/libjin/common/je_stringmap.hpp b/src/libjin/common/je_stringmap.hpp
index 7a3bd80..b4cdccf 100644
--- a/src/libjin/common/je_stringmap.hpp
+++ b/src/libjin/common/je_stringmap.hpp
@@ -1,11 +1,13 @@
#ifndef __JE_COMMON_SREINGMAP_H__
#define __JE_COMMON_SREINGMAP_H__
+#include "je_object.h"
+
namespace JinEngine
{
template<typename T, unsigned SIZE>
- class StringMap
+ class StringMap : public Object
{
private:
diff --git a/src/libjin/common/je_temporary.h b/src/libjin/common/je_temporary.h
index 647bfba..b89a601 100644
--- a/src/libjin/common/je_temporary.h
+++ b/src/libjin/common/je_temporary.h
@@ -1,13 +1,15 @@
#ifndef __JE_TEMPORARY_H__
#define __JE_TEMPORARY_H__
+#include "je_object.h"
+
namespace JinEngine
{
///
/// Class inherites this clound only be created on stack or static zone.
///
- class Temporary
+ class Temporary : public Object
{
public:
Temporary() {};
diff --git a/src/libjin/common/je_utf8.h b/src/libjin/common/je_utf8.h
index d840b75..a720640 100644
--- a/src/libjin/common/je_utf8.h
+++ b/src/libjin/common/je_utf8.h
@@ -31,4 +31,4 @@ namespace JinEngine
#endif // jin_os == jin_os_windows
-#endif // __JE_COMMON_UTF8_H__
+#endif // __JE_COMMON_UTF8_H__ \ No newline at end of file
diff --git a/src/libjin/filesystem/je_asset_database.h b/src/libjin/filesystem/je_asset_database.h
index e8b1bd1..2e029ff 100644
--- a/src/libjin/filesystem/je_asset_database.h
+++ b/src/libjin/filesystem/je_asset_database.h
@@ -18,7 +18,7 @@ namespace JinEngine
///
/// Assets managment.
///
- class AssetDatabase
+ class AssetDatabase : public Object
{
public:
///
diff --git a/src/libjin/game/je_entity.cpp b/src/libjin/game/je_entity.cpp
deleted file mode 100644
index e69de29..0000000
--- a/src/libjin/game/je_entity.cpp
+++ /dev/null
diff --git a/src/libjin/game/je_entity.h b/src/libjin/game/je_entity.h
deleted file mode 100644
index 80c6ff3..0000000
--- a/src/libjin/game/je_entity.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef __JE_ENTITY_H__
-#define __JE_ENTITY_H__
-
-#include "je_gameobject.h"
-
-namespace JinEngine
-{
- namespace Game
- {
-/*
- ///
- ///
- ///
- class Entity : public GameObject
- {
- public:
- Entity();
-
- private:
-
-
- };
-*/
- } // namespace Game
-} // namespace JinEngine
-
-#endif \ No newline at end of file
diff --git a/src/libjin/game/je_gameobject.cpp b/src/libjin/game/je_gameobject.cpp
index 1396518..731f3a7 100644
--- a/src/libjin/game/je_gameobject.cpp
+++ b/src/libjin/game/je_gameobject.cpp
@@ -1,4 +1,4 @@
-#include "je_entity.h"
+#include "je_gameobject.h"
namespace JinEngine
{
diff --git a/src/libjin/game/je_gameobject.h b/src/libjin/game/je_gameobject.h
index 7c6ec2b..e434caf 100644
--- a/src/libjin/game/je_gameobject.h
+++ b/src/libjin/game/je_gameobject.h
@@ -9,14 +9,13 @@
#include <set>
#include "../common/je_object.h"
-#include "../common/je_types.h"
-#include "../graphics/je_sprite.h"
+#include "../math/je_transform.h"
namespace JinEngine
{
namespace Game
{
- /*
+
///
/// Game object base class.
///
@@ -27,54 +26,13 @@ namespace JinEngine
///
///
///
- virtual ~GameObject();
-
- ///
- ///
- ///
- void lifecycle();
-
- ///
- ///
- ///
- void setVisible(bool isVisible);
-
- ///
- ///
- ///
- void setActive(bool isActive);
-
- ///
- ///
- ///
- void setOrder(uint32 order);
+ virtual ~GameObject() {};
protected:
- virtual void onAlive();
- virtual void onUpdate(float dt);
- virtual void onDraw();
- virtual void onDestroy();
-
- uint32 mLayer; // layer where entity belongs
- uint32 mOrder; // render index in layer
- uint32 mTag; // tag of entity, support 32 tags now
- bool mIsVisible; // if the entity is visible or not
- bool mIsActive; // if the entity is joined into the logic
-
Math::Transform mTransform;
};
- ///
- /// Entity list. For quickly adding and removing entities.
- ///
- typedef std::list<GameObject*> EntityList;
-
- ///
- /// Entity set. For searching and keeps entities unique and sorted.
- ///
- typedef std::set<GameObject*> EntitySet;
- */
} // namespace Game
} // namespace JinEngine
diff --git a/src/libjin/game/je_scene.cpp b/src/libjin/game/je_scene.cpp
deleted file mode 100644
index e69de29..0000000
--- a/src/libjin/game/je_scene.cpp
+++ /dev/null
diff --git a/src/libjin/game/je_scene.h b/src/libjin/game/je_scene.h
deleted file mode 100644
index 811d1a8..0000000
--- a/src/libjin/game/je_scene.h
+++ /dev/null
@@ -1,73 +0,0 @@
-#ifndef __JE_GAME_SCENE_H__
-#define __JE_GAME_SCENE_H__
-
-#include "../core/je_configuration.h"
-#if defined(jin_game)
-
-#include <map>
-#include <list>
-
-#include "je_entity.h"
-
-namespace JinEngine
-{
- namespace Game
- {
-
- ///
- /// Handle all entities.
- ///
- class Scene
- {
- public:
- ///
- ///
- ///
- void addEntity(Entity* entity);
-
- ///
- ///
- ///
- EntityList& getEntitiesByTag(uint32 tag);
-
- ///
- ///
- ///
- EntityList& getEntitiesByLayer(uint32 layer);
-
- ///
- ///
- ///
- void setEntitiesActiveByTag(uint32 tag);
-
- ///
- ///
- ///
- void setEntitiesActiveByLayer(uint32 layer);
-
- ///
- ///
- ///
- void removeEntitiesByLayer(uint32 layer);
-
- ///
- ///
- ///
- void removeEntitiesByTag(uint32 tag);
-
- protected:
- // all entities
- EntitySet entities;
- // all entities grouped by layer, render order
- std::map<uint32, EntityList> layers;
- // all entities grouped by tag
- std::map<uint32, EntityList> tags;
-
- };
-
- } // namespace Game
-} // namespace JinEngine
-
-#endif // jin_game
-
-#endif \ No newline at end of file
diff --git a/src/libjin/graphics/animations/je_animation.h b/src/libjin/graphics/animations/je_animation.h
index 4037721..fd22049 100644
--- a/src/libjin/graphics/animations/je_animation.h
+++ b/src/libjin/graphics/animations/je_animation.h
@@ -4,6 +4,8 @@
#include <vector>
#include <string>
+#include "../../common/je_object.h"
+
#include "../je_sprite.h"
namespace JinEngine
@@ -16,7 +18,7 @@ namespace JinEngine
///
/// Animation clip with key.
///
- class Animation
+ class Animation : public Object
{
public:
Animation();
diff --git a/src/libjin/graphics/animations/je_animator.h b/src/libjin/graphics/animations/je_animator.h
index d3fdbae..bee3d7d 100644
--- a/src/libjin/graphics/animations/je_animator.h
+++ b/src/libjin/graphics/animations/je_animator.h
@@ -3,6 +3,7 @@
#include <string>
+#include "../../common/je_object.h"
#include "../../utils/je_log.h"
#include "je_animation.h"
@@ -14,7 +15,7 @@ namespace JinEngine
namespace Animations
{
- class Animator : public IRenderable
+ class Animator : public Object, public IRenderable
{
public:
Animator();
diff --git a/src/libjin/graphics/fonts/je_decoder.h b/src/libjin/graphics/fonts/je_decoder.h
index 840cada..0c785af 100644
--- a/src/libjin/graphics/fonts/je_decoder.h
+++ b/src/libjin/graphics/fonts/je_decoder.h
@@ -3,6 +3,8 @@
#include <vector>
+#include "../../common/je_object.h"
+
#include "je_text.h"
namespace JinEngine
@@ -15,7 +17,7 @@ namespace JinEngine
///
/// Text decoder.
///
- class Decoder
+ class Decoder : public Object
{
public:
diff --git a/src/libjin/graphics/fonts/je_font.h b/src/libjin/graphics/fonts/je_font.h
index e72ef6b..3f72a13 100644
--- a/src/libjin/graphics/fonts/je_font.h
+++ b/src/libjin/graphics/fonts/je_font.h
@@ -25,7 +25,7 @@ namespace JinEngine
///
/// Base Font class.
///
- class Font : public IRenderable
+ class Font : public Object, public IRenderable
{
public:
///
diff --git a/src/libjin/graphics/fonts/je_text.h b/src/libjin/graphics/fonts/je_text.h
index 6e6f8b0..319ee4d 100644
--- a/src/libjin/graphics/fonts/je_text.h
+++ b/src/libjin/graphics/fonts/je_text.h
@@ -3,6 +3,8 @@
#include <vector>
+#include "../../common/je_object.h"
+
namespace JinEngine
{
namespace Graphics
@@ -30,7 +32,7 @@ namespace JinEngine
///
/// Decoded text. Saved as unicode codepoints.
///
- class Text
+ class Text : public Object
{
public:
///
diff --git a/src/libjin/graphics/fonts/je_ttf.h b/src/libjin/graphics/fonts/je_ttf.h
index 28260f6..c2766b4 100644
--- a/src/libjin/graphics/fonts/je_ttf.h
+++ b/src/libjin/graphics/fonts/je_ttf.h
@@ -34,7 +34,7 @@ namespace JinEngine
// .
// .
//
- class TTFData
+ class TTFData : public Object
{
public:
@@ -289,4 +289,4 @@ namespace JinEngine
#endif // defined(jin_graphics)
-#endif // __JE_FONT_H__
+#endif // __JE_FONT_H__ \ No newline at end of file
diff --git a/src/libjin/graphics/je_bitmap.h b/src/libjin/graphics/je_bitmap.h
index 5ab11ca..e9c214e 100644
--- a/src/libjin/graphics/je_bitmap.h
+++ b/src/libjin/graphics/je_bitmap.h
@@ -24,7 +24,7 @@ namespace JinEngine
/// texture is a renderable hard ware side structure which could be handled with GPU. For instance, opengl
/// create texture and store it in GPU memory for rendering them onto hdc.
///
- class Bitmap
+ class Bitmap : public Object
{
public:
///
diff --git a/src/libjin/graphics/je_gl.cpp b/src/libjin/graphics/je_gl.cpp
index c58f0ac..68678e2 100644
--- a/src/libjin/graphics/je_gl.cpp
+++ b/src/libjin/graphics/je_gl.cpp
@@ -12,14 +12,80 @@ namespace JinEngine
OpenGL gl;
OpenGL::OpenGL()
- : ogl2d::OpenGL()
+ : mBlendMode(BlendMode::NONE)
{
+ memset(&mColor, 0xff, sizeof(mColor));
+ memset(&mPrecolor, 0xff, sizeof(mPrecolor));
+ // Set default modelview matrix.
mModelViewMatrices.push_back(Matrix());
mModelViewMatrix.setIdentity();
for (Matrix& m : mModelViewMatrices)
mModelViewMatrix *= m;
}
+ OpenGL::~OpenGL()
+ {
+ }
+
+ void OpenGL::pushColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a)
+ {
+ memcpy(&mPrecolor, &mColor, sizeof(mPrecolor));
+ mColor.r = r;
+ mColor.g = g;
+ mColor.b = b;
+ mColor.a = a;
+ glColor4ub(r, g, b, a);
+ }
+
+ void OpenGL::popColor()
+ {
+ memcpy(&mColor, &mPrecolor, sizeof(mPrecolor));
+ glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a);
+ }
+
+ void OpenGL::flushError()
+ {
+ while (glGetError() != GL_NO_ERROR);
+ }
+
+ GLuint OpenGL::genTexture()
+ {
+ GLuint t;
+ glGenTextures(1, &t);
+ return t;
+ }
+
+ void OpenGL::bindTexture(GLuint texture)
+ {
+ glBindTexture(GL_TEXTURE_2D, texture);
+ }
+
+ void OpenGL::deleteTexture(GLuint texture)
+ {
+ glDeleteTextures(1, &texture);
+ }
+
+ void OpenGL::setTexParameter(GLenum pname, GLint param)
+ {
+ glTexParameteri(GL_TEXTURE_2D, pname, param);
+ }
+
+ void OpenGL::texImage(GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
+ {
+ glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, type, pixels);
+ }
+
+ void OpenGL::texSubImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
+ {
+ glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, width, height, format, type, pixels);
+ }
+
+ void OpenGL::activeTexUnit(unsigned int unit)
+ {
+ // glActiveTexture selects which texture unit subsequent texture state calls will affect.
+ glActiveTexture(GL_TEXTURE0 + unit);
+ }
+
void OpenGL::setColor(Channel r, Channel g, Channel b, Channel a)
{
setColor(Color(r, g, b, a));
@@ -43,12 +109,12 @@ namespace JinEngine
mModelViewMatrix.setIdentity();
}
- void OpenGL::push()
+ void OpenGL::pushMatrix()
{
mModelViewMatrices.push_back(Matrix());
}
- void OpenGL::pop()
+ void OpenGL::popMatrix()
{
if (mModelViewMatrices.size() == 1)
return;
@@ -112,5 +178,43 @@ namespace JinEngine
mProjectionMatrix.setOrtho(l, r, b, t, n, f);
}
+ OpenGL::BlendMode OpenGL::getBlendMode()
+ {
+ return mBlendMode;
+ }
+
+ void OpenGL::setBlendMode(BlendMode mode)
+ {
+ if (mBlendMode == mode)
+ return;
+ mBlendMode = mode;
+
+ GLenum func = GL_FUNC_ADD;
+ GLenum srcRGB = GL_ONE;
+ GLenum srcA = GL_ONE;
+ GLenum dstRGB = GL_ZERO;
+ GLenum dstA = GL_ZERO;
+
+ switch (mode)
+ {
+ case BlendMode::ADDITIVE:
+ srcRGB = GL_SRC_ALPHA;
+ dstRGB = GL_ONE;
+ break;
+ case BlendMode::PREMULTIPLIEDALPHA:
+ srcRGB = srcA = GL_ONE;
+ dstRGB = dstA = GL_ONE_MINUS_SRC_ALPHA;
+ break;
+ case BlendMode::ALPHA:
+ default:
+ srcRGB = srcA = GL_SRC_ALPHA;
+ dstRGB = dstA = GL_ONE_MINUS_SRC_ALPHA;
+ break;
+ }
+
+ glBlendEquation(func);
+ glBlendFuncSeparate(srcRGB, dstRGB, srcA, dstA);
+ }
+
} // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/graphics/je_gl.h b/src/libjin/graphics/je_gl.h
index 134cfee..60b2396 100644
--- a/src/libjin/graphics/je_gl.h
+++ b/src/libjin/graphics/je_gl.h
@@ -7,7 +7,6 @@
#include "../math/je_transform.h"
#include "GLee/GLee.h"
-#include "ogl/OpenGL.h"
#include "je_color.h"
@@ -16,18 +15,112 @@ namespace JinEngine
namespace Graphics
{
- /*class Canvas;
+ // Wrap OpenGL API.
+/*
+ class Canvas;
class Shader;
class Font;
*/
- class OpenGL
- : public ogl2d::OpenGL
+
+ class OpenGL
{
public:
///
+ /// Blend mode.
+ /// https://www.andersriggelsen.dk/glblendfunc.php
///
- ///
+ enum class BlendMode
+ {
+ NONE = 0,
+ ALPHA,
+ ADDITIVE,
+ PREMULTIPLIEDALPHA,
+ };
+
OpenGL();
+ ~OpenGL();
+
+ inline void enable(GLenum cap)
+ {
+ glEnable(cap);
+ }
+
+ inline void disable(GLenum cap)
+ {
+ glDisable(cap);
+ }
+/*
+ inline void setBlendFunc(GLenum sfactor, GLenum dfactor)
+ {
+ glBlendFunc(sfactor, dfactor);
+ }
+*/
+ inline void setClearColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a)
+ {
+ glClearColor(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
+ }
+
+ void pushColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a = 255);
+ void popColor();
+ void flushError();
+ GLuint genTexture();
+ void deleteTexture(GLuint texture);
+ void bindTexture(GLuint texture = 0);
+ inline GLuint curTexture()
+ {
+ return mTexture;
+ }
+ void setTexParameter(GLenum pname, GLint param);
+ void texImage(GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels = NULL);
+ void texSubImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
+ void activeTexUnit(unsigned int unit = 0);
+
+ inline void drawArrays(GLenum mode, GLint first, GLsizei count)
+ {
+ glDrawArrays(mode, first, count);
+ }
+
+ inline void drawBuffer(GLenum mode)
+ {
+
+ }
+
+ inline void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
+ {
+
+ }
+
+ inline void enableClientState(GLenum arr)
+ {
+ glEnableClientState(arr);
+ }
+
+ inline void disableClientState(GLenum arr)
+ {
+ glDisableClientState(arr);
+ }
+
+ inline GLuint genFrameBuffer()
+ {
+ GLuint fbo;
+ glGenFramebuffers(1, &fbo);
+ return fbo;
+ }
+
+ inline void bindFrameBuffer(GLuint fbo)
+ {
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ }
+
+ inline void ortho(int w, float radio)
+ {
+ glOrtho(0, w, w*radio, 0, -1, 1);
+ }
+
+ inline void orthox(int w, int h)
+ {
+ glOrtho(0, w, h, 0, -1, 1);
+ }
void setColor(Channel r, Channel g, Channel b, Channel a);
@@ -37,7 +130,7 @@ namespace JinEngine
void clearMatrix();
- void push();
+ void pushMatrix();
void translate(float x, float y);
@@ -45,7 +138,7 @@ namespace JinEngine
void rotate(float r);
- void pop();
+ void popMatrix();
///
///
@@ -92,6 +185,16 @@ namespace JinEngine
///
void unUseShader();
+ ///
+ ///
+ ///
+ void setBlendMode(BlendMode mode);
+
+ ///
+ ///
+ ///
+ BlendMode getBlendMode();
+
private:
///
@@ -113,6 +216,16 @@ namespace JinEngine
///
///
Color mCurrentColor;
+
+ ///
+ ///
+ ///
+ BlendMode mBlendMode;
+
+ struct { GLubyte r, g, b, a; } mColor; // current draw color
+ struct { GLubyte r, g, b, a; } mPrecolor; // previous draw color
+ GLuint mTexture; // current binded texture
+
/*
///
///
diff --git a/src/libjin/graphics/je_graphic.h b/src/libjin/graphics/je_graphic.h
index 58de7ec..d48ba3c 100644
--- a/src/libjin/graphics/je_graphic.h
+++ b/src/libjin/graphics/je_graphic.h
@@ -3,6 +3,7 @@
#include "../core/je_configuration.h"
#if defined(jin_graphics)
+#include "../common/je_object.h"
#include "../math/je_quad.h"
#include "../math/je_vector2.hpp"
#include "../math/je_transform.h"
@@ -20,7 +21,7 @@ namespace JinEngine
/// Class inherites Graphic doesn't keep any state such as origin, scale and other properties. Very low
/// level visualized resources.
///
- class Graphic : public IRenderable
+ class Graphic : public Object, public IRenderable
{
public:
///
diff --git a/src/libjin/graphics/je_image.h b/src/libjin/graphics/je_image.h
index 971ac18..15baed3 100644
--- a/src/libjin/graphics/je_image.h
+++ b/src/libjin/graphics/je_image.h
@@ -13,8 +13,7 @@ namespace JinEngine
///
/// Just like bitmap but only from image file. The pixels data is readonly.
///
- class Image
- : public Bitmap
+ class Image : public Bitmap
{
public:
///
diff --git a/src/libjin/graphics/je_mesh.h b/src/libjin/graphics/je_mesh.h
index 27c0cb7..4327424 100644
--- a/src/libjin/graphics/je_mesh.h
+++ b/src/libjin/graphics/je_mesh.h
@@ -20,7 +20,6 @@ namespace JinEngine
private:
const Graphic* mGraphic;
-
};
} // namespace Graphics
diff --git a/src/libjin/graphics/je_sprite.h b/src/libjin/graphics/je_sprite.h
index c7c5a8b..de2117e 100644
--- a/src/libjin/graphics/je_sprite.h
+++ b/src/libjin/graphics/je_sprite.h
@@ -16,7 +16,7 @@ namespace JinEngine
///
/// A sprite is unit of rendering. Animation is based on sprite, but not texture or other graphic stuff.
///
- class Sprite : public IRenderable
+ class Sprite : public Object, public IRenderable
{
public:
diff --git a/src/libjin/graphics/je_sprite_batch.h b/src/libjin/graphics/je_sprite_batch.h
index 64f9805..d58489c 100644
--- a/src/libjin/graphics/je_sprite_batch.h
+++ b/src/libjin/graphics/je_sprite_batch.h
@@ -1,12 +1,14 @@
#ifndef __JE_GRAPHICS_SPRITE_BATCH_H__
#define __JE_GRAPHICS_SPRITE_BATCH_H__
+#include "../common/je_object.h"
+
namespace JinEngine
{
namespace Graphics
{
- class SpriteBatch
+ class SpriteBatch : public Object
{
public:
diff --git a/src/libjin/graphics/je_window.cpp b/src/libjin/graphics/je_window.cpp
index c14d290..f08e816 100644
--- a/src/libjin/graphics/je_window.cpp
+++ b/src/libjin/graphics/je_window.cpp
@@ -86,20 +86,21 @@ namespace JinEngine
return false;
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
SDL_GL_MakeCurrent(mWnd, ctx);
- // Default configuration
+ // Default configuration.
gl.setClearColor(0, 0, 0, 0xff);
glClear(GL_COLOR_BUFFER_BIT);
gl.pushColor(0xff, 0xff, 0xff, 0xff);
gl.enable(GL_BLEND);
gl.enable(GL_TEXTURE_2D);
- gl.setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- // Bind to default canvas
+ // Default blend function.
+ gl.setBlendMode(OpenGL::BlendMode::ALPHA);
+ // Bind to default canvas.
Canvas::unbind();
Shader::unuse();
// Avoid white blinnk.
swapBuffers();
- return true;
+ return true;
}
void Window::quitSystem()
diff --git a/src/libjin/math/je_percentage.h b/src/libjin/math/je_percentage.h
new file mode 100644
index 0000000..2440072
--- /dev/null
+++ b/src/libjin/math/je_percentage.h
@@ -0,0 +1,36 @@
+#ifndef __JE_PERCENTAGE_H__
+#define __JE_PERCENTAGE_H__
+
+#include "je_math.h"
+
+namespace JinEngine
+{
+ namespace Math
+ {
+
+ class Percentage
+ {
+ public:
+ Percentage(float v)
+ {
+ value = clamp<float>(v, 0, 1);
+ }
+
+ Percentage(const Percentage& p)
+ {
+ value = p.value;
+ }
+
+ void operator = (const Percentage& p)
+ {
+ value = p.value;
+ }
+
+ float value;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/libjin/math/je_ranged_value.cpp b/src/libjin/math/je_ranged_value.cpp
new file mode 100644
index 0000000..b28e72b
--- /dev/null
+++ b/src/libjin/math/je_ranged_value.cpp
@@ -0,0 +1,71 @@
+#include "je_ranged_value.h"
+
+namespace JinEngine
+{
+ namespace Math
+ {
+
+ RangedValue::RangedValue()
+ : mCount(0)
+ {
+ }
+
+ RangedValue::RangedValue(float* points, uint n)
+ : mCount(n)
+ {
+ for (uint i = 0; i < n; ++i)
+ {
+ float x = points[2*i];
+ float y = points[2*i + 1];
+ mXAxis.push_back(x);
+ mYAxis.push_back(y);
+ }
+ }
+
+ void RangedValue::addPoint(float x, float y)
+ {
+ mXAxis.push_back(x);
+ mYAxis.push_back(y);
+ ++mCount;
+ }
+
+ void RangedValue::removePoint(uint i)
+ {
+ mXAxis.erase(mXAxis.begin() + i);
+ mYAxis.erase(mYAxis.begin() + i);
+ --mCount;
+ }
+
+ void RangedValue::insertPoint(uint i, float x, float y)
+ {
+ mXAxis.insert(mXAxis.begin() + i, x);
+ mYAxis.insert(mYAxis.begin() + i, y);
+ ++mCount;
+ }
+
+ float RangedValue::getValue(float x)
+ {
+ int endIndex = -1;
+ int n = mCount;
+ for (int i = 1; i < n; i++) {
+ float t = mXAxis[i];
+ if (t > x) {
+ endIndex = i;
+ break;
+ }
+ }
+ if (endIndex == -1) return mYAxis[n - 1];
+ int startIndex = endIndex - 1;
+ float startValue = mYAxis[startIndex];
+ float startX = mXAxis[startIndex];
+ return startValue + (mYAxis[endIndex] - startValue) * ((x - startX) / (mXAxis[endIndex] - startX));
+ }
+
+ void RangedValue::clear()
+ {
+ mXAxis.clear();
+ mYAxis.clear();
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/libjin/math/je_ranged_value.h b/src/libjin/math/je_ranged_value.h
new file mode 100644
index 0000000..4749e91
--- /dev/null
+++ b/src/libjin/math/je_ranged_value.h
@@ -0,0 +1,57 @@
+#ifndef __JE_RANGED_VALUE_H__
+#define __JE_RANGED_VALUE_H__
+
+#include "../common/je_types.h"
+
+#include <vector>
+
+namespace JinEngine
+{
+ namespace Math
+ {
+ /*
+ * y ^
+ * |-------- _
+ * | \ / \
+ * | --- \
+ * | \
+ * | \
+ * +----------------------> x
+ */
+ class RangedValue
+ {
+ public:
+ RangedValue();
+
+ ///
+ /// Points of ranged value.
+ ///
+ /// @param points Points.
+ /// @param n Number of points.
+ ///
+ RangedValue(float* points, uint n);
+
+ virtual ~RangedValue() {}
+
+ virtual void addPoint(float x, float y);
+
+ virtual void removePoint(uint i);
+
+ virtual void insertPoint(uint i, float x, float y);
+
+ virtual float getValue(float x);
+
+ virtual void clear();
+
+ private:
+ std::vector<float> mXAxis;
+ std::vector<float> mYAxis;
+
+ uint mCount;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/libjin/math/je_transform.h b/src/libjin/math/je_transform.h
index 45f26e0..35a1a13 100644
--- a/src/libjin/math/je_transform.h
+++ b/src/libjin/math/je_transform.h
@@ -40,7 +40,7 @@ namespace JinEngine
Vector2<float> mPosition;
Vector2<float> mOrigin;
Vector2<float> mScale;
- float mRotation;
+ float mRotation;
};
diff --git a/src/libjin/math/je_vector2.hpp b/src/libjin/math/je_vector2.hpp
index b4cab44..0a1a1e8 100644
--- a/src/libjin/math/je_vector2.hpp
+++ b/src/libjin/math/je_vector2.hpp
@@ -48,6 +48,11 @@ namespace JinEngine
data[1] = _y;
}
+ bool isZero()
+ {
+ return data[0] == 0 && data[1] == 0;
+ }
+
T &x = data[0], &y = data[1]; // xy
T &w = data[0], &h = data[1]; // wh
T &colum = data[0], &row = data[1]; // colum row