-#if defined(ECERE_NO3D) || defined(ECERE_VANILLA)
-public union Matrix
-{
- double array[16];
- double m[4][4];
-
- void Identity()
- {
- FillBytesBy4(this, 0, sizeof(Matrix) >> 2);
- m[0][0]=m[1][1]=m[2][2]=m[3][3]=1;
- }
-
- void Transpose(Matrix source)
- {
- int i,j;
- for(i=0; i<4; i++)
- for(j=0; j<4; j++)
- m[j][i] = source.m[i][j];
- }
-
- void Multiply(Matrix a, Matrix b)
- {
- // We need a full matrix multiplication for the Projection matrix
- m[0][0]=a.m[0][0]*b.m[0][0] + a.m[0][1]*b.m[1][0] + a.m[0][2]*b.m[2][0] + a.m[0][3]*b.m[3][0];
- m[0][1]=a.m[0][0]*b.m[0][1] + a.m[0][1]*b.m[1][1] + a.m[0][2]*b.m[2][1] + a.m[0][3]*b.m[3][1];
- m[0][2]=a.m[0][0]*b.m[0][2] + a.m[0][1]*b.m[1][2] + a.m[0][2]*b.m[2][2] + a.m[0][3]*b.m[3][2];
- m[0][3]=a.m[0][0]*b.m[0][3] + a.m[0][1]*b.m[1][3] + a.m[0][2]*b.m[2][3] + a.m[0][3]*b.m[3][3];
-
- m[1][0]=a.m[1][0]*b.m[0][0] + a.m[1][1]*b.m[1][0] + a.m[1][2]*b.m[2][0] + a.m[1][3]*b.m[3][0];
- m[1][1]=a.m[1][0]*b.m[0][1] + a.m[1][1]*b.m[1][1] + a.m[1][2]*b.m[2][1] + a.m[1][3]*b.m[3][1];
- m[1][2]=a.m[1][0]*b.m[0][2] + a.m[1][1]*b.m[1][2] + a.m[1][2]*b.m[2][2] + a.m[1][3]*b.m[3][2];
- m[1][3]=a.m[1][0]*b.m[0][3] + a.m[1][1]*b.m[1][3] + a.m[1][2]*b.m[2][3] + a.m[1][3]*b.m[3][3];
-
- m[2][0]=a.m[2][0]*b.m[0][0] + a.m[2][1]*b.m[1][0] + a.m[2][2]*b.m[2][0] + a.m[2][3]*b.m[3][0];
- m[2][1]=a.m[2][0]*b.m[0][1] + a.m[2][1]*b.m[1][1] + a.m[2][2]*b.m[2][1] + a.m[2][3]*b.m[3][1];
- m[2][2]=a.m[2][0]*b.m[0][2] + a.m[2][1]*b.m[1][2] + a.m[2][2]*b.m[2][2] + a.m[2][3]*b.m[3][2];
- m[2][3]=a.m[2][0]*b.m[0][3] + a.m[2][1]*b.m[1][3] + a.m[2][2]*b.m[2][3] + a.m[2][3]*b.m[3][3];
-
- m[3][0]=a.m[3][0]*b.m[0][0] + a.m[3][1]*b.m[1][0] + a.m[3][2]*b.m[2][0] + a.m[3][3]*b.m[3][0];
- m[3][1]=a.m[3][0]*b.m[0][1] + a.m[3][1]*b.m[1][1] + a.m[3][2]*b.m[2][1] + a.m[3][3]*b.m[3][1];
- m[3][2]=a.m[3][0]*b.m[0][2] + a.m[3][1]*b.m[1][2] + a.m[3][2]*b.m[2][2] + a.m[3][3]*b.m[3][2];
- m[3][3]=a.m[3][0]*b.m[0][3] + a.m[3][1]*b.m[1][3] + a.m[3][2]*b.m[2][3] + a.m[3][3]*b.m[3][3];
- }
-};
-#endif
-
-// Our own matrix stack
-static Matrix matrixStack[3][32];
-static int matrixIndex[3];
-static int curStack = 0;
-
-#if defined(_GLES)
-
- // OpenGL ES Porting Kit
-#if defined(__ANDROID__) || defined(__ODROID__)
- #define glBindFramebuffer glBindFramebufferOES
- #define glBindRenderbuffer glBindRenderbufferOES
- #define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
- #define GL_RENDERBUFFER GL_RENDERBUFFER_OES
- #define glFramebufferTexture2D glFramebufferTexture2DOES
- #define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES
- #define glGenFramebuffers glGenFramebuffersOES
- #define glGenRenderbuffers glGenRenderbuffersOES
- #define glDeleteFramebuffers glDeleteFramebuffersOES
- #define glDeleteRenderbuffers glDeleteRenderbuffersOES
-
- #define GL_POLYGON_STIPPLE 0xFFFF
- #define GL_LINE_STIPPLE 0xFFFF
- #define GL_LINE 0xFFFF
- #define GL_FILL 0xFFFF
- #define GL_ALL_ATTRIB_BITS 0xFFFF
- #define GL_LIGHT_MODEL_LOCAL_VIEWER 0xFFFF
- #define GL_INT 0x1404
- #define GL_UNSIGNED_INT 0x1405
- #define GL_DOUBLE 0x140A
- #define GL_POLYGON 9
- #define GL_QUADS 7
- #define APIENTRY
-#endif
-
- #define glDrawElementsi(type, count, start) glDrawElements(type, count, GL_UNSIGNED_SHORT, start)
-
- #define glBufferDatai glesBufferDatai
- #define glBufferDatad glesBufferDatad
- #define glVertexPointeri glesVertexPointeri
- #define glVertexPointerd glesVertexPointerd
-
- #define glRecti glesRecti
- #define glBegin glesBegin
- #define glTexCoord2i glesTexCoord2i
- #define glVertex2i glesVertex2i
- #define glTexCoord2d glesTexCoord2d
- #define glVertex2d glesVertex2d
- #define glTexCoord2f glesTexCoord2f
- #define glVertex2f glesVertex2f
- #define glEnd glesEnd
- #define glColor3f glesColor3f
- #define glColor4ub glesColor4ub
- #define glColor4fv glesColor4fv
- #define glLineStipple glesLineStipple
- #define glNormal3fv glesNormal3fv
- #define glNormal3f glesNormal3f
- #define glTexCoord2fv glesTexCoord2fv
- #define glColorMaterial glesColorMaterial
-
- #define glLoadMatrixd glesLoadMatrixd
- #define glMultMatrixd glesMultMatrixd
- #define glFrustum glesFrustum
- #define glOrtho glesOrtho
- #define glScaled glesScaled
- #define glTranslated glesTranslated
- #define glRotated glesRotated
- #define glVertex3d glesVertex3d
- #define glVertex3dv glesVertex3dv
- #define glVertex3f glesVertex3f
- #define glVertex3fv glesVertex3fv
- #define glLightModeli glesLightModeli
-
-#if defined(__ANDROID__)
- //#define GL_QUADS 0
- #define GL_QUAD_STRIP 0
- //#define GL_DOUBLE 0
- //#define GL_UNSIGNED_INT 0
- //#define GL_FILL 0
- //#define GL_LINE 0
- //#define GL_LINE_STIPPLE 0
- #define GL_BGRA_EXT 0
- #define GL_UNPACK_ROW_LENGTH 0
- #define GL_UNPACK_SKIP_PIXELS 0
- #define GL_UNPACK_SKIP_ROWS 0
- #define GL_RGBA8 0
- #define GL_PACK_ROW_LENGTH 0
- #define GL_PACK_SKIP_ROWS 0
- #define GL_PACK_SKIP_PIXELS 0
-#endif
-
-#else
-
-#define glVertexPointerd(nc, s, p, nv) glVertexPointer(nc, GL_DOUBLE, s, p)
-#define glDrawElementsi(type, count, start) glDrawElements(type, count, GL_UNSIGNED_INT, start)
-
-#endif
-
-#if defined(__ANDROID__) || defined(__ODROID__)
- static EGLDisplay eglDisplay;
- static EGLSurface eglSurface;
- static EGLContext eglContext;
- static int eglWidth, eglHeight;
-
-#if defined(__ANDROID__)
- static bool egl_init_display(ANativeWindow* window)
-#else
- static bool egl_init_display(uint window)
-#endif
- {
- const EGLint attribs[] =
- {
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
- EGL_BLUE_SIZE, 8,
- EGL_GREEN_SIZE, 8,
- EGL_RED_SIZE, 8,
- EGL_DEPTH_SIZE, 16, //24,
- /*EGL_SAMPLE_BUFFERS, 1,
- EGL_SAMPLES, 0, //2,*/
- EGL_NONE
- };
- EGLint w, h, format;
- EGLint numConfigs;
- EGLConfig config;
- EGLSurface surface;
- EGLContext context;
-
- EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
- eglInitialize(display, 0, 0);
- eglChooseConfig(display, attribs, &config, 1, &numConfigs);
- eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
-
- surface = eglCreateWindowSurface(display, config, window, null);
- context = eglCreateContext(display, config, null, null);
-
- if(!eglMakeCurrent(display, surface, surface, context))
- return false;
-
- eglQuerySurface(display, surface, EGL_WIDTH, &w);
- eglQuerySurface(display, surface, EGL_HEIGHT, &h);
-
- eglDisplay = display;
- eglContext = context;
- eglSurface = surface;
- eglWidth = w;
- eglHeight = h;
-
- glEnableClientState(GL_VERTEX_ARRAY);
- /*
- // Initialize GL state.
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
- glEnable(GL_CULL_FACE);
- glShadeModel(GL_SMOOTH);
- glDisable(GL_DEPTH_TEST);
- */
- glDisable(GL_CULL_FACE);
- glDisable(GL_DEPTH_TEST);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
-
- matrixStack[0][0].Identity();
- matrixStack[1][0].Identity();
- matrixStack[2][0].Identity();
-
- glesMatrixMode(GL_MODELVIEW);
- glScaled(1.0, 1.0, -1.0);
- glesMatrixMode(GL_PROJECTION);
- glShadeModel(GL_FLAT);
-
- glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
- glFogi(GL_FOG_MODE, GL_EXP);
- glFogf(GL_FOG_DENSITY, 0);
- glEnable(GL_NORMALIZE);
- glDepthFunc(GL_LESS);
- glClearDepth(1.0);
- glDisable(GL_MULTISAMPLE_ARB);
-
- glViewport(0,0,w,h);
- glesLoadIdentity();
- glOrtho(0,w,h,0,0.0,1.0);
-
- curArrayBuffer = 0;
- curElementBuffer = 0;
- return true;
- }
-
- static void egl_term_display()
- {
- if(stippleTexture)
- {
- glDeleteTextures(1, &stippleTexture);
- stippleTexture = 0;
- }
- if(eglDisplay != EGL_NO_DISPLAY)
- {
- eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- if(eglContext != EGL_NO_CONTEXT)
- eglDestroyContext(eglDisplay, eglContext);
- if(eglSurface != EGL_NO_SURFACE)
- eglDestroySurface(eglDisplay, eglSurface);
- eglTerminate(eglDisplay);
- }
- eglDisplay = EGL_NO_DISPLAY;
- eglContext = EGL_NO_CONTEXT;
- eglSurface = EGL_NO_SURFACE;
- }
-
-#endif
-
-// OpenGL Immediate Mode Porting Kit
-static int beginCount;
-static int vertexCount;
-static int normalCount;
-static float *vertexPointer;
-static float *normalPointer;
-static GLenum beginMode = -1;
-static uint beginBufferSize, normalBufferSize;
-static int numVertexCoords = 2;
-static bool vertexColorValues = false;
-static int vertexStride = 4;
-static int vertexOffset = 2;
-
-public void glesRecti(int a, int b, int c, int d)
-{
- glBegin(GL_QUADS);
- glVertex2i(a, b);
- glVertex2i(a, d);
- glVertex2i(c, d);
- glVertex2i(c, b);
- glEnd();
-}
-
-public void glesBegin(GLenum mode)
-{
- beginMode = mode;
- beginCount = 0;
- vertexCount = 0;
- vertexColorValues = false;
- vertexOffset = 2;
- vertexStride = 4;
- numVertexCoords = 2;
-
- if(!vertexPointer)
- {
- normalBufferSize = beginBufferSize = 1024; // default number of vertices
- vertexPointer = new float[beginBufferSize * vertexStride];
- normalPointer = new float[normalBufferSize * 3];
- }
-}
-
-public void glesTexCoord2f(float x, float y)
-{
- int count = vertexCount;
-
- if(vertexCount + numVertexCoords > beginBufferSize)
- {
- beginBufferSize = beginBufferSize + beginBufferSize/2;
- vertexPointer = renew vertexPointer float[beginBufferSize * vertexStride];
- }
-
- vertexPointer[count*vertexStride ] = x;
- vertexPointer[count*vertexStride+1] = y;
- count++;
-
- if(beginMode == GL_QUADS && ((beginCount % 4) == 3))
- {
- vertexPointer[count*vertexStride ] = vertexPointer[(count-4)*vertexStride];
- vertexPointer[count*vertexStride+1] = vertexPointer[(count-4)*vertexStride+1];
- count++;
- vertexPointer[count*vertexStride ] = vertexPointer[(count-3)*vertexStride];
- vertexPointer[count*vertexStride+1] = vertexPointer[(count-3)*vertexStride+1];
- count++;
- }
-}
-public void glesTexCoord2i(int x, int y) { glesTexCoord2f((float)x, (float)y); }
-public void glesTexCoord2d(double x, double y) { glesTexCoord2f((float)x, (float)y); }
-public void glesTexCoord2fv(float * a) { glesTexCoord2f(a[0], a[1]); }
-
-public void glesVertex2f(float x, float y)
-{
- numVertexCoords = 2;
- vertexStride = vertexOffset + numVertexCoords;
-
- if(vertexCount + 4 > beginBufferSize)
- {
- beginBufferSize = beginBufferSize + beginBufferSize/2;
- vertexPointer = renew vertexPointer float[beginBufferSize * vertexStride];
- }
-
- vertexPointer[vertexCount*vertexStride+vertexOffset] = x;
- vertexPointer[vertexCount*vertexStride+vertexOffset + 1] = y;
- vertexCount++;
-
- if(beginMode == GL_QUADS && ((beginCount % 4) == 3))
- {
- vertexPointer[vertexCount*vertexStride+vertexOffset] = vertexPointer[(vertexCount-4)*vertexStride+vertexOffset];
- vertexPointer[vertexCount*vertexStride+vertexOffset + 1] = vertexPointer[(vertexCount-4)*vertexStride+vertexOffset + 1];
- vertexCount++;
- vertexPointer[vertexCount*vertexStride+vertexOffset] = vertexPointer[(vertexCount-3)*vertexStride+vertexOffset];
- vertexPointer[vertexCount*vertexStride+vertexOffset + 1] = vertexPointer[(vertexCount-3)*vertexStride+vertexOffset + 1];
- vertexCount++;
- }
- beginCount++;
-}
-public void glesVertex2i(int x, int y) { glesVertex2f((float)x, (float)y); }
-public void glesVertex2d(double x, double y) { glesVertex2f((float)x, (float)y); }
-
-public void glesEnd(void)
-{
- int mode = beginMode;
- if(mode == GL_QUADS) mode = GL_TRIANGLES;
- else if(mode == GL_POLYGON) mode = GL_TRIANGLE_FAN;
-
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- noAB.use(texCoord, 2, GL_FLOAT, vertexStride * sizeof(float), vertexPointer);
- if(vertexColorValues)
- {
- glEnableClientState(GL_COLOR_ARRAY);
- noAB.use(color, 4, GL_FLOAT, vertexStride * sizeof(float), vertexPointer + 2);
- }
- noAB.use(vertex, numVertexCoords, GL_FLOAT, (vertexStride)*sizeof(float),vertexPointer+vertexOffset);
- if(normalCount && normalCount == vertexCount)
- {
- glEnableClientState(GL_NORMAL_ARRAY);
- noAB.use(normal, 3, GL_FLOAT, 3*sizeof(float),normalPointer);
- }
-
- glDrawArrays(mode, 0, vertexCount);
- if(normalCount)
- glDisableClientState(GL_NORMAL_ARRAY);
- if(vertexColorValues)
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- normalCount = 0;
- vertexColorValues = false;
- numVertexCoords = 2;
- beginMode = -1;
-}
-
-// Vertex Pointer
-static float *floatVPBuffer = null;
-static short *shortVPBuffer = null;
-static unsigned int shortVPSize = 0, floatVPSize = 0;
-
-// Buffer Data
-//static float *floatVPBuffer = null; // For floats we reuse floatVPBuffer
-static unsigned short *shortBDBuffer = null;
-static unsigned int shortBDSize = 0/*, floatVPSize = 0*/;
-
-public void glesVertexPointeri(int numCoords, int stride, int *pointer, int numVertices)
-{
- if(pointer)
- {
- int i;
- if(numVertices*numCoords > shortVPSize)
- {
- shortVPSize = numVertices*numCoords;
- shortVPBuffer = renew shortVPBuffer short[shortVPSize];
- }
- for(i = 0; i < numVertices*numCoords; i++)
- shortVPBuffer[i] = (short)pointer[i];
- glVertexPointer(numCoords, GL_SHORT, stride, shortVPBuffer);
- }
- else
- glVertexPointer(numCoords, GL_SHORT, stride, 0);
-}
-
-public void glesVertexPointerd(int numCoords, int stride, double *pointer, int numVertices)
-{
- if(pointer)
- {
- int i;
- if(numVertices*numCoords > floatVPSize)
- {
- floatVPSize = numVertices*numCoords;
- floatVPBuffer = renew floatVPBuffer float[floatVPSize];
- }
- for(i = 0; i < numVertices*numCoords; i++)
- floatVPBuffer[i] = (float)pointer[i];
- glVertexPointer(numCoords, GL_FLOAT, stride, floatVPBuffer);
- }
- else
- glVertexPointer(numCoords, GL_FLOAT, stride, 0);
-}
-
-public void glesTexReuseIntVP(int numCoords)
-{
- glTexCoordPointer(numCoords, GL_SHORT, 0, floatVPBuffer);
-}
-
-public void glesTexReuseDoubleVP(int numCoords)
-{
- glTexCoordPointer(numCoords, GL_FLOAT, 0, floatVPBuffer);
-}
-
-public void glesColor4f(float r, float g, float b, float a)
-{
- if(beginMode != (GLenum)-1)
- {
- int count = vertexCount;
-
- vertexColorValues = true;
- vertexOffset = 6;
- vertexStride = vertexOffset + numVertexCoords;
-
- if(vertexCount + vertexStride > beginBufferSize)
- {
- beginBufferSize = beginBufferSize + beginBufferSize/2;
- vertexPointer = renew vertexPointer float[beginBufferSize * vertexStride];
- }
-
- vertexPointer[count*vertexStride + 2] = r;
- vertexPointer[count*vertexStride + 3] = g;
- vertexPointer[count*vertexStride + 4] = b;
- vertexPointer[count*vertexStride + 5] = a;
- count++;
-
- if(beginMode == GL_QUADS && ((beginCount % 4) == 3))
- {
- vertexPointer[count*vertexStride + 2] = vertexPointer[(count-4) * vertexStride + 2];
- vertexPointer[count*vertexStride + 3] = vertexPointer[(count-4) * vertexStride + 3];
- vertexPointer[count*vertexStride + 4] = vertexPointer[(count-4) * vertexStride + 4];
- vertexPointer[count*vertexStride + 5] = vertexPointer[(count-4) * vertexStride + 5];
- count++;
- vertexPointer[count*vertexStride + 2] = vertexPointer[(count-3) * vertexStride + 2];
- vertexPointer[count*vertexStride + 3] = vertexPointer[(count-3) * vertexStride + 3];
- vertexPointer[count*vertexStride + 4] = vertexPointer[(count-3) * vertexStride + 4];
- vertexPointer[count*vertexStride + 5] = vertexPointer[(count-3) * vertexStride + 5];
- count++;
- }
- }
- else
- glColor4f(r, g, b, a);
-}
-
-public void glesColor3f( float r, float g, float b )
-{
- glesColor4f(r, g, b, 1.0f);
-}
-
-public void glesColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
-{
- glesColor4f(r/255.0f, g/255.0f, b/255.0f, a/255.0f);
-}
-
-public void glesColor4fv(float * a)
-{
- glesColor4f(a[0], a[1], a[2], a[3]);
-}
-
-public void glesBufferDatad(int target, int size, void * data, int usage)
-{
- int numElems = size/sizeof(double);
- double * dblPtr = (double *)data;
- int i;
- if (numElems > floatVPSize)
- {
- floatVPSize = numElems;
- floatVPBuffer = renew floatVPBuffer float[floatVPSize];
- }
- for (i=0; i< numElems; i++)
- floatVPBuffer[i] = (float)dblPtr[i];
-
- glBufferData(target, numElems*sizeof(float), floatVPBuffer, usage);
-}
-
-public void glesBufferDatai(int target, int size, void * data, int usage)
-{
- int numElems = size/sizeof(unsigned int);
- unsigned int * pointer = (unsigned int *)data;
- int i;
- if (numElems > shortBDSize)
- {
- shortBDSize = numElems;
- shortBDBuffer = renew shortBDBuffer uint16[shortBDSize];
- }
- for (i=0; i< numElems; i++)
- shortBDBuffer[i] = (unsigned short)pointer[i];
-
- glBufferData(target, numElems*sizeof(unsigned short), shortBDBuffer, usage);
-}
-
-// *** Our Custom Matrix Stack ***
-
-static void LoadCurMatrix()
-{
- double * i = matrixStack[curStack][matrixIndex[curStack]].array;
- float m[16] =
- {
- (float)i[0],(float)i[1],(float)i[2],(float)i[3],
- (float)i[4],(float)i[5],(float)i[6],(float)i[7],
- (float)i[8],(float)i[9],(float)i[10],(float)i[11],
- (float)i[12],(float)i[13],(float)i[14],(float)i[15]
- };
- glLoadMatrixf(m);
-}
-
-public void glesLoadIdentity()
-{
- matrixStack[curStack][matrixIndex[curStack]].Identity();
- LoadCurMatrix();
-}
-
-public void glesPushMatrix()
-{
- if(matrixIndex[curStack] + 1 < sizeof(matrixStack[0]) / sizeof(Matrix))
- {
- matrixIndex[curStack]++;
- memcpy(matrixStack[curStack][matrixIndex[curStack]].array, matrixStack[curStack][matrixIndex[curStack]-1].array, sizeof(Matrix));
- }
-}
-
-public void glesPopMatrix()
-{
- if(matrixIndex[curStack] > 0)
- {
- matrixIndex[curStack]--;
- LoadCurMatrix();
- }
-}
-
-public void glesLoadMatrixd(double * i)
-{
- memcpy(matrixStack[curStack][matrixIndex[curStack]].array, i, sizeof(Matrix));
- LoadCurMatrix();
-}
-
-public void glesOrtho( double l, double r, double b, double t, double n, double f )
-{
- Matrix m
- { {
- (2 / (r - l)), 0, 0, 0,
- 0, (2 / (t - b)), 0, 0,
- 0, 0, (-2 / (f - n)), 0,
- (-(r + l) / (r - l)), (-(t + b) / (t - b)), (-(f + n) / (f - n)), 1
- } };
- Matrix res;
- res.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
- matrixStack[curStack][matrixIndex[curStack]] = res;
- LoadCurMatrix();
-}
-
-public void glesFrustum( double l, double r, double b, double t, double n, double f )
-{
- nearPlane = n;
- n = 1;
- l /= nearPlane;
- r /= nearPlane;
- b /= nearPlane;
- t /= nearPlane;
- f /= nearPlane;
- {
- double A = ((r + l) / (r - l));
- double B = ((t + b) / (t - b));
- double C = (-(f + n) / (f - n));
- double D = (-2*f*n/(f-n));
- Matrix m
- { {
- (2.0*n / (r - l)), 0, 0, 0,
- 0, (2.0*n / (t - b)), 0, 0,
- A, B, C,-1,
- 0, 0, D, 0
- } };
- Matrix res;
- res.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
- matrixStack[curStack][matrixIndex[curStack]] = res;
- LoadCurMatrix();
- }
-}
-
-public void glesRotated( double a, double b, double c, double d )
-{
- Quaternion q;
- Matrix m, r;
-
- q.RotationAxis({(float)b,(float)c,(float)-d}, a );
- m.RotationQuaternion(q);
- r.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
- matrixStack[curStack][matrixIndex[curStack]] = r;
- LoadCurMatrix();
-}
-public void glesScaled( double a, double b, double c )
-{
- Matrix m, r;
-
- m.Identity();
- m.Scale(a,b,c);
- r.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
- matrixStack[curStack][matrixIndex[curStack]] = r;
- LoadCurMatrix();
-}
-
-public void glesTranslated( double a, double b, double c )
-{
- Matrix m, r;
-
- m.Identity();
- m.Translate(a,b,c);
- r.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
- matrixStack[curStack][matrixIndex[curStack]] = r;
- LoadCurMatrix();
-}
-
-public void glesMultMatrixd( double * i )
-{
- Matrix r;
- r.Multiply((Matrix *)i, matrixStack[curStack][matrixIndex[curStack]]);
- matrixStack[curStack][matrixIndex[curStack]] = r;
- LoadCurMatrix();
-}
-
-public void glesMatrixMode(int mode)
-{
- curStack = (mode == GL_MODELVIEW) ? 0 : (mode == GL_PROJECTION) ? 1 : 2;
- glMatrixMode(mode);
-}
-
-#if defined(_GLES)
-
-#define glPushMatrix glesPushMatrix
-#define glPopMatrix glesPopMatrix
-#define glLoadIdentity glesLoadIdentity
-#define glMatrixMode glesMatrixMode
-
-#endif
-
-/* Using the built-in matrix stack
-void glesLoadMatrixd( double * i )
-{
- float m[16] =
- {
- (float)i[0],(float)i[1],(float)i[2],(float)i[3],
- (float)i[4],(float)i[5],(float)i[6],(float)i[7],
- (float)i[8],(float)i[9],(float)i[10],(float)i[11],
- (float)i[12],(float)i[13],(float)i[14],(float)i[15]
- };
- glLoadMatrixf(m);
-}
-
-void glesOrtho( double l, double r, double b, double t, double n, double f )
-{
- float matrix[4][4] =
- {
- { (float)(2 / (r - l)), 0, 0, 0 },
- { 0, (float)(2 / (t - b)), 0, 0 },
- { 0, 0, (float)(-2 / (f - n)), 0 },
- { (float)(-(r + l) / (r - l)), (float)(-(t + b) / (t - b)), (float)(-(f + n) / (f - n)), 1 }
- };
- glMultMatrixf((float *)matrix);
-}
-
-void glesFrustum( double l, double r, double b, double t, double n, double f )
-{
- float A = (float)((r + l) / (r - l));
- float B = (float)((t + b) / (t - b));
- float C = (float)(-(f + n) / (f - n));
- float D = (float)(-2*f*n/(f-n));
- float matrix[4][4] =
- {
- { (float)(2*n / (r - l)), 0, 0, 0 },
- { 0, (float)(2*n / (t - b)), 0, 0 },
- { A, B, C,-1 },
- { 0, 0, D, 0 }
- };
- glMultMatrixf((float *)matrix);
-}
-
-void glesRotated( double a, double b, double c, double d ) { glRotatef((float)a, (float)b, (float)c, (float)d); }
-void glesScaled( double a, double b, double c ) { glScalef((float)a, (float)b, (float)c); }
-void glesTranslated( double a, double b, double c ) { glTranslatef((float)a, (float)b, (float)c); }
-
-void glesMultMatrixd( double * i )
-{
- float m[16] =
- {
- (float)i[0], (float)i[1], (float)i[2], (float)i[3],
- (float)i[4], (float)i[5], (float)i[6], (float)i[7],
- (float)i[8], (float)i[9], (float)i[10], (float)i[11],
- (float)i[12], (float)i[13], (float)i[14], (float)i[15]
- };
- glMultMatrixf(m);
-}