Hi everyone,
- GLXMATRIX projection
- GLXMATRIX translate
Then I initialized them as Identity matrices and I uploaded perspective data to projection matrix and scaling data to translation matrix:
- GLXMatrixPerspectiveCM(&projection, 45.0f, 800.0f/600.0f, 0.1f, 100.0f);
- GLXMatrixScaling(&translate, 0.5f, 0.5f, 0.5f);
Perspective collumn major function looks like this.
GLXMATRIX* GLXMatrixPerspectiveCM(GLXMATRIX *pOut,float fov,float aspect, float zn,float zf) {
#ifdef TYW_DEBUG
if (!pOut)return nullptr;
#endif
float q = 1.0f / tan(0.5f*fov * (PI / 180.0f));
float A = q / aspect;
float B = (zn + zf) / (zn - zf);
float C = (2.0f * zn * zf) / (zn - zf);
pOut[0][0] = A;
pOut[1][1] = q;
pOut[2][2] = B;
pOut[2][3] = C;
pOut[3][2] = -1;
pOut[3][3] = 0;
return pOut;
}
Then I sended those matrices to shader.
//SetUniformMatrix4fv(std::string progIndx, std::string unfIndx, int count, bool transpose, const float* value);
- renderProgManager.SetUniformMatrix4fv("text.glsl", "objectPosition", 1, false, translate);
- renderProgManager.SetUniformMatrix4fv("text.glsl", "orthoMatrix", 1, false, projection);
But instead of seing triangle properly I got this.
- GLXMATRIX* projection
- GLXMATRIX* translate
I created memory space for them.
- projection = new GLXMATRIX;
- translate = new GLXMATRIX;
#ifndef GLMATRIX_DEFINED
typedef struct _GLMATRIX {
union {
struct {
float _11, _21, _31, _41;
float _12, _22, _32, _42;
float _13, _23, _33, _43;
float _14, _24, _34, _44;
};
float m[4][4];
};
}GLMATRIX;
#define GLMATRIX_DEFINED
#endif
typedef struct GLXMATRIX : public GLMATRIX {
public:
GLXMATRIX() {}
GLXMATRIX(const float*);
GLXMATRIX(GLXMATRIX &);
GLXMATRIX(
float m11, float m21, float m31, float m41,
float m12, float m22, float m32, float m42,
float m13, float m23, float m33, float m43,
float m14, float m24, float m34, float m44);
//acces grants
float& operator () (unsigned int row, unsigned int col);
float operator () (unsigned int row, unsigned int col) const;
//casting operators
operator float* ();
operator const float* () const;
//assignement operators
GLXMATRIX& operator *= (const GLXMATRIX&);
GLXMATRIX& operator += (const GLXMATRIX&);
GLXMATRIX& operator -= (const GLXMATRIX&);
GLXMATRIX& operator *= (float);
GLXMATRIX& operator /= (float);
//unary operators
GLXMATRIX operator + () const;
GLXMATRIX operator - () const;
//binary operators
GLXMATRIX operator * (const GLXMATRIX&) const;
GLXMATRIX operator + (const GLXMATRIX&) const;
GLXMATRIX operator - (const GLXMATRIX&) const;
GLXMATRIX operator * (float) const;
GLXMATRIX operator / (float) const;
friend GLXMATRIX operator * (float, const GLXMATRIX&);
bool operator == (const GLXMATRIX&) const;
bool operator != (const GLXMATRIX&) const;
}GLXMATRIX, *LPGLXMATRIX;
//casting operators
inline GLXMATRIX::operator float* ()
{
return (float*)&_11;
}
inline GLXMATRIX::operator const float* () const
{
return (const float*)&_11;
}