aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2018-02-03 00:55:26 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2018-02-03 00:55:26 +0800
commit1eb88d4f5d5cb05d62be1d4a0c88c7399f7c0de0 (patch)
tree4daf8fa3f4e8fff38a61b8e2da752df8b519f232 /include
parent6f955e10a71e364f527ea654156ea83785e9ada8 (diff)
downloadSMELT-1eb88d4f5d5cb05d62be1d4a0c88c7399f7c0de0.tar.xz
Added the GL 3.2+ port.
Fixed poor performance of the truetype renderer. (Partially) Fixed texture locking. Minor addition and fixes to the math library.
Diffstat (limited to 'include')
-rw-r--r--include/smmath.hpp31
-rw-r--r--include/smttfont.hpp33
2 files changed, 34 insertions, 30 deletions
diff --git a/include/smmath.hpp b/include/smmath.hpp
index 84ef315..d5ed80e 100644
--- a/include/smmath.hpp
+++ b/include/smmath.hpp
@@ -81,7 +81,7 @@ public:
friend smvec4d operator -(smvec4d a,smvec4d b){return smvec4d(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w);}
friend smvec4d operator +(smvec4d a,smvec4d b){return smvec4d(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w);}
friend double operator |(smvec4d a,smvec4d b){return a.x*b.x+a.y*b.y+a.z*b.z+a.w*b.w;}
- //Note: this doesn't do a real cross product.
+ //Note: this doesn't do a real 4d cross product.
friend smvec4d operator *(smvec4d a,smvec4d b){return smvec4d(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x,1);}
friend smvec4d operator *(double a,smvec4d b){return smvec4d(a*b.x,a*b.y,a*b.z,a*b.w);}
friend smvec4d operator *(smvec4d a,double b){return smvec4d(b*a.x,b*a.y,b*a.z,b*a.w);}
@@ -103,6 +103,12 @@ public:
double* operator [](int s){if(s>=0&&s<4)return m+s*4;else return NULL;}
void clear(){for(int i=0;i<16;++i)m[i]=.0;}
void loadIdentity(){clear();m[0]=m[5]=m[10]=m[15]=1.;}
+ void translate(double x,double y,double z)
+ {
+ smMatrix tmp;tmp.loadIdentity();
+ tmp.m[12]=x;tmp.m[13]=y;tmp.m[14]=z;
+ *this=*this*tmp;
+ }
void rotate(double a,double x,double y,double z)
{
if(smvec3d(x,y,z).l()<=EPS)return;
@@ -112,16 +118,17 @@ public:
x=a.x;y=a.y;z=a.z;
}
smMatrix tmp;
- tmp[0][0]=x*x*(1-cos(a))+cos(a);
- tmp[1][0]=x*y*(1-cos(a))-z*sin(a);
- tmp[2][0]=x*z*(1-cos(a))+y*sin(a);
- tmp[0][1]=y*x*(1-cos(a))+z*sin(a);
- tmp[1][1]=y*y*(1-cos(a))+cos(a);
- tmp[2][1]=y*z*(1-cos(a))-x*sin(a);
- tmp[0][2]=x*z*(1-cos(a))-y*sin(a);
- tmp[1][2]=y*z*(1-cos(a))+x*sin(a);
- tmp[2][2]=z*z*(1-cos(a))+cos(a);
- tmp[3][3]=1;
+ double c=cos(a),s=sin(a);
+ tmp.m[ 0]=x*x*(1-c)+c;
+ tmp.m[ 4]=x*y*(1-c)-z*s;
+ tmp.m[ 8]=x*z*(1-c)+y*s;
+ tmp.m[ 1]=y*x*(1-c)+z*s;
+ tmp.m[ 5]=y*y*(1-c)+c;
+ tmp.m[ 9]=y*z*(1-c)-x*s;
+ tmp.m[ 2]=x*z*(1-c)-y*s;
+ tmp.m[ 6]=y*z*(1-c)+x*s;
+ tmp.m[10]=z*z*(1-c)+c;
+ tmp.m[15]=1;
*this=*this*tmp;
}
void lookat(smvec3d eye,smvec3d at,smvec3d up)
@@ -139,7 +146,7 @@ public:
for(int i=0;i<4;++i)
for(int j=0;j<4;++j)
for(int k=0;k<4;++k)
- ret[i][j]+=a[i][k]*b[k][j];
+ ret[j][i]+=a[k][i]*b[j][k];
return ret;
}
friend smvec3d operator *(smMatrix a,smvec3d b)
diff --git a/include/smttfont.hpp b/include/smttfont.hpp
index 08860ce..c0865f2 100644
--- a/include/smttfont.hpp
+++ b/include/smttfont.hpp
@@ -13,6 +13,8 @@
#include "smelt.hpp"
#include <cwchar>
#include <map>
+#include <utility>
+#include <vector>
#include <ft2build.h>
#include FT_FREETYPE_H
@@ -22,32 +24,26 @@
#define ALIGN_CENTER 2
#endif
-class smTTChar
-{
-private:
- smQuad quad;
- int rw,rh,_w,_h,xofs,yofs;
- static SMELT *sm;
-public:
- float w(){return (float)_w;}
- float h(){return (float)_h;}
- void free();
- bool setChar(wchar_t c,FT_Face ttface);
- void render(float x,float y,float z,DWORD col,float scalex,float scaley,bool rtl);
-};
+struct _smTexState;
+class _smTTChar;
class smTTFont
{
-protected:
+private:
FT_Library ftlib;
FT_Face ttface;
-private:
wchar_t buf[1025];
- std::map<wchar_t,smTTChar> chars;
+ std::map<wchar_t,_smTTChar*> chars;
+ std::vector<_smTexState*> textures;
float w,h;
+ int mx,my,texw,texh;
+ unsigned _npot(unsigned x);
+ std::pair<SMTEX,std::pair<int,int>> _allocate_char(int rw,int rh);
+ static SMELT* sm;
public:
- bool loadTTF(const char* path,int pt);
- bool loadTTFFromMemory(char* ptr,DWORD size,int pt);
+ ~smTTFont();
+ bool loadTTF(const char* path,int pt,int cachesize_x=16,int cachesize_y=16);
+ bool loadTTFFromMemory(char* ptr,DWORD size,int pt,int cachesize_x=16,int cachesize_y=16);
void releaseTTF();
float getWidth(){return w;}
float getHeight(){return h;}
@@ -55,5 +51,6 @@ public:
void render(float x,float y,float z,DWORD col,int align,float scalex=1,float scaley=1);
DWORD getCacheSize();
void clearCache();
+ friend class _smTTChar;
};
#endif