}
#endif
-#define BACKENDACTIVECHECK if (!backendactive) Sys_Error(__func__ " called when backend is not active\n");
+#define BACKENDACTIVECHECK if (!backendactive) Sys_Error("GL backend function called when backend is not active\n");
float r_mesh_farclip;
int mesh_maxtris;
int mesh_maxverts; // always mesh_maxtris * 3
-static matrix4x4_t backendmatrix;
+static matrix4x4_t backend_viewmatrix;
+static matrix4x4_t backend_modelmatrix;
+static matrix4x4_t backend_modelviewmatrix;
+static matrix4x4_t backend_glmodelviewmatrix;
static int backendunits, backendactive;
static qbyte *varray_bcolor;
qglFrustum(-xmax, xmax, -ymax, ymax, zNear, zFar);CHECKGLERROR
qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
- qglLoadIdentity ();CHECKGLERROR
+ Matrix4x4_CreateRotate(&backend_viewmatrix, -90, 1, 0, 0);
+ Matrix4x4_ConcatRotate(&backend_viewmatrix, 90, 0, 0, 1);
+ Matrix4x4_ConcatRotate(&backend_viewmatrix, -r_refdef.viewangles[2], 1, 0, 0);
+ Matrix4x4_ConcatRotate(&backend_viewmatrix, -r_refdef.viewangles[0], 0, 1, 0);
+ Matrix4x4_ConcatRotate(&backend_viewmatrix, -r_refdef.viewangles[1], 0, 0, 1);
+ Matrix4x4_ConcatTranslate(&backend_viewmatrix, -r_refdef.vieworg[0], -r_refdef.vieworg[1], -r_refdef.vieworg[2]);
+ //Con_Printf("Our Matrix:\n");
+ //Matrix4x4_Print(&backend_viewmatrix);
+
+ //Matrix4x4_Transpose(&backend_glmodelviewmatrix, &backend_viewmatrix);
+ //qglLoadMatrixf(&backend_glmodelviewmatrix.m[0][0]);CHECKGLERROR
+ memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix));
+
+ /*
// put Z going up
+ qglLoadIdentity ();CHECKGLERROR
qglRotatef (-90, 1, 0, 0);CHECKGLERROR
qglRotatef (90, 0, 0, 1);CHECKGLERROR
// camera rotation
qglRotatef (-r_refdef.viewangles[1], 0, 0, 1);CHECKGLERROR
// camera location
qglTranslatef (-r_refdef.vieworg[0], -r_refdef.vieworg[1], -r_refdef.vieworg[2]);CHECKGLERROR
+ qglGetFloatv (GL_MODELVIEW_MATRIX, &gl_viewmatrix.m[0][0]);
+ Matrix4x4_Transpose(&backend_viewmatrix, &gl_viewmatrix);
+ Con_Printf("GL Matrix:\n");
+ Matrix4x4_Print(&backend_viewmatrix);
+ */
}
static struct
}
}
+/*
void GL_TransformVertices(int numverts)
{
int i;
v[2] = tempv[0] * m[8] + tempv[1] * m[9] + tempv[2] * m[10] + m[11];
}
}
+*/
void GL_DrawRangeElements(int firstvert, int endvert, int indexcount, GLuint *index)
{
// drawmode 0 always uses byte colors
if (!gl_mesh_floatcolors.integer || gl_mesh_drawmode.integer <= 0)
GL_ConvertColorsFloatToByte(numverts);
- GL_TransformVertices(numverts);
+ //GL_TransformVertices(numverts);
if (!r_render.integer)
return;
GL_DrawRangeElements(0, numverts, numtriangles * 3, varray_element);
GL_SetupTextureState();
}
- backendmatrix = m->matrix; // this copies the struct
+ //backendmatrix = m->matrix; // this copies the struct
+ if (memcmp(&m->matrix, &backend_modelmatrix, sizeof(matrix4x4_t)))
+ {
+ backend_modelmatrix = m->matrix;
+ Matrix4x4_Concat(&backend_modelviewmatrix, &backend_viewmatrix, &m->matrix);
+ Matrix4x4_Transpose(&backend_glmodelviewmatrix, &backend_modelviewmatrix);
+ qglLoadMatrixf(&backend_glmodelviewmatrix.m[0][0]);
+ }
overbright = false;
scaler = 1;
#define GL_MODELVIEW 0x1700
#define GL_PROJECTION 0x1701
#define GL_TEXTURE 0x1702
+#define GL_MATRIX_MODE 0x0BA0
+#define GL_MODELVIEW_MATRIX 0x0BA6
+#define GL_PROJECTION_MATRIX 0x0BA7
+#define GL_TEXTURE_MATRIX 0x0BA8
#define GL_DEPTH_TEST 0x0B71
extern void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
extern void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
-//extern void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
-//extern void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
-//extern void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
+extern void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
+extern void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
+extern void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
extern void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
extern GLenum (GLAPIENTRY *qglGetError)(void);
//extern void (GLAPIENTRY *qglPushMatrix)(void);
//extern void (GLAPIENTRY *qglPopMatrix)(void);
extern void (GLAPIENTRY *qglLoadIdentity)(void);
-//extern void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
-//extern void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
+extern void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
+extern void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
//extern void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
//extern void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
//extern void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
y *= len;
z *= len;
- angle *= M_PI / 180.0;
+ angle *= -M_PI / 180.0;
c = cos(angle);
s = sin(angle);
void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z)
{
matrix4x4_t base, temp;
- Matrix4x4_Copy(out, &base);
+ base = *out;
Matrix4x4_CreateTranslate(&temp, x, y, z);
Matrix4x4_Concat(out, &base, &temp);
}
void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, float z)
{
matrix4x4_t base, temp;
- Matrix4x4_Copy(out, &base);
+ base = *out;
Matrix4x4_CreateRotate(&temp, angle, x, y, z);
Matrix4x4_Concat(out, &base, &temp);
}
void Matrix4x4_ConcatScale (matrix4x4_t *out, float x)
{
matrix4x4_t base, temp;
- Matrix4x4_Copy(out, &base);
+ base = *out;
Matrix4x4_CreateScale(&temp, x);
Matrix4x4_Concat(out, &base, &temp);
}
void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z)
{
matrix4x4_t base, temp;
- Matrix4x4_Copy(out, &base);
+ base = *out;
Matrix4x4_CreateScale3(&temp, x, y, z);
Matrix4x4_Concat(out, &base, &temp);
}
+void Matrix4x4_Print (const matrix4x4_t *in)
+{
+ Con_Printf("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n"
+ , in->m[0][0], in->m[0][1], in->m[0][2], in->m[0][3]
+ , in->m[1][0], in->m[1][1], in->m[1][2], in->m[1][3]
+ , in->m[2][0], in->m[2][1], in->m[2][2], in->m[2][3]
+ , in->m[3][0], in->m[3][1], in->m[3][2], in->m[3][3]);
+}
void Matrix3x4_ConcatTranslate (matrix3x4_t *out, float x, float y, float z)
{
matrix3x4_t base, temp;
- Matrix3x4_Copy(out, &base);
+ base = *out;
Matrix3x4_CreateTranslate(&temp, x, y, z);
Matrix3x4_Concat(out, &base, &temp);
}
void Matrix3x4_ConcatRotate (matrix3x4_t *out, float angle, float x, float y, float z)
{
matrix3x4_t base, temp;
- Matrix3x4_Copy(out, &base);
+ base = *out;
Matrix3x4_CreateRotate(&temp, angle, x, y, z);
Matrix3x4_Concat(out, &base, &temp);
}
void Matrix3x4_ConcatScale (matrix3x4_t *out, float x)
{
matrix3x4_t base, temp;
- Matrix3x4_Copy(out, &base);
+ base = *out;
Matrix3x4_CreateScale(&temp, x);
Matrix3x4_Concat(out, &base, &temp);
}
void Matrix3x4_ConcatScale3 (matrix3x4_t *out, float x, float y, float z)
{
matrix3x4_t base, temp;
- Matrix3x4_Copy(out, &base);
+ base = *out;
Matrix3x4_CreateScale3(&temp, x, y, z);
Matrix3x4_Concat(out, &base, &temp);
}
+
+void Matrix3x4_Print (const matrix3x4_t *in)
+{
+ Con_Printf("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n"
+ , in->m[0][0], in->m[0][1], in->m[0][2], in->m[0][3]
+ , in->m[1][0], in->m[1][1], in->m[1][2], in->m[1][3]
+ , in->m[2][0], in->m[2][1], in->m[2][2], in->m[2][3]);
+}
+
// immediately applies a Scale3 to the matrix
void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z);
+// print a matrix to the console
+void Matrix4x4_Print(const matrix4x4_t *in);
// functions for manipulating 3x4 matrices
// immediately applies a Scale3 to the matrix
void Matrix3x4_ConcatScale3 (matrix3x4_t *out, float x, float y, float z);
+// print a matrix to the console
+void Matrix3x4_Print(const matrix3x4_t *in);
+
#endif
void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
-//void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
-//void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
-//void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
+void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
+void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
+void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
GLenum (GLAPIENTRY *qglGetError)(void);
//void (GLAPIENTRY *qglPushMatrix)(void);
//void (GLAPIENTRY *qglPopMatrix)(void);
void (GLAPIENTRY *qglLoadIdentity)(void);
-//void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
-//void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
+void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
+void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
//void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
//void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
//void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
// {"glIsEnabled", (void **) &qglIsEnabled},
{"glEnableClientState", (void **) &qglEnableClientState},
{"glDisableClientState", (void **) &qglDisableClientState},
-// {"glGetBooleanv", (void **) &qglGetBooleanv},
-// {"glGetDoublev", (void **) &qglGetDoublev},
-// {"glGetFloatv", (void **) &qglGetFloatv},
+ {"glGetBooleanv", (void **) &qglGetBooleanv},
+ {"glGetDoublev", (void **) &qglGetDoublev},
+ {"glGetFloatv", (void **) &qglGetFloatv},
{"glGetIntegerv", (void **) &qglGetIntegerv},
{"glGetError", (void **) &qglGetError},
{"glGetString", (void **) &qglGetString},
// {"glPushMatrix", (void **) &qglPushMatrix},
// {"glPopMatrix", (void **) &qglPopMatrix},
{"glLoadIdentity", (void **) &qglLoadIdentity},
-// {"glLoadMatrixd", (void **) &qglLoadMatrixd},
-// {"glLoadMatrixf", (void **) &qglLoadMatrixf},
+ {"glLoadMatrixd", (void **) &qglLoadMatrixd},
+ {"glLoadMatrixf", (void **) &qglLoadMatrixf},
// {"glMultMatrixd", (void **) &qglMultMatrixd},
// {"glMultMatrixf", (void **) &qglMultMatrixf},
// {"glRotated", (void **) &qglRotated},