vrchess

diff src/opengl.cc @ 0:b326d53321f7

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 25 Apr 2014 05:20:53 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/opengl.cc	Fri Apr 25 05:20:53 2014 +0300
     1.3 @@ -0,0 +1,61 @@
     1.4 +#include "opengl.h"
     1.5 +#include <vmath/vmath.h>
     1.6 +
     1.7 +void load_matrix(const Matrix4x4 &m)
     1.8 +{
     1.9 +#ifdef SINGLE_PRECISION_MATH
    1.10 +	if(glLoadTransposeMatrixfARB) {
    1.11 +		glLoadTransposeMatrixfARB((float*)&m);
    1.12 +	} else {
    1.13 +		Matrix4x4 tmat = m.transposed();
    1.14 +		glLoadMatrixf((float*)&tmat);
    1.15 +	}
    1.16 +#else
    1.17 +	if(glLoadTransposeMatrixdARB) {
    1.18 +		glLoadTransposeMatrixdARB((double*)&m);
    1.19 +	} else {
    1.20 +		Matrix4x4 tmat = m.transposed();
    1.21 +		glLoadMatrixd((double*)&tmat);
    1.22 +	}
    1.23 +#endif
    1.24 +}
    1.25 +
    1.26 +void mult_matrix(const Matrix4x4 &m)
    1.27 +{
    1.28 +#ifdef SINGLE_PRECISION_MATH
    1.29 +	if(glMultTransposeMatrixfARB) {
    1.30 +		glMultTransposeMatrixfARB((float*)&m);
    1.31 +	} else {
    1.32 +		Matrix4x4 tmat = m.transposed();
    1.33 +		glMultMatrixf((float*)&tmat);
    1.34 +	}
    1.35 +#else
    1.36 +	if(glMultTransposeMatrixdARB) {
    1.37 +		glMultTransposeMatrixdARB((double*)&m);
    1.38 +	} else {
    1.39 +		Matrix4x4 tmat = m.transposed();
    1.40 +		glMultMatrixd((double*)&tmat);
    1.41 +	}
    1.42 +#endif
    1.43 +}
    1.44 +
    1.45 +const char *strglerr(int err)
    1.46 +{
    1.47 +	static const char *errnames[] = {
    1.48 +		"GL_INVALID_ENUM",
    1.49 +		"GL_INVALID_VALUE",
    1.50 +		"GL_INVALID_OPERATION",
    1.51 +		"GL_STACK_OVERFLOW",
    1.52 +		"GL_STACK_UNDERFLOW",
    1.53 +		"GL_OUT_OF_MEMORY",
    1.54 +		"GL_INVALID_FRAMEBUFFER_OPERATION"
    1.55 +	};
    1.56 +
    1.57 +	if(!err) {
    1.58 +		return "GL_NO_ERROR";
    1.59 +	}
    1.60 +	if(err < GL_INVALID_ENUM || err > GL_OUT_OF_MEMORY) {
    1.61 +		return "<invalid gl error>";
    1.62 +	}
    1.63 +	return errnames[err - GL_INVALID_ENUM];
    1.64 +}