DEADSOFTWARE

nogl: fix quads
[d2df-sdl.git] / src / nogl / noGLES1.inc
index 9aa878324dc0159081663f9e56c145e962fdb628..6142e2e4ee6c148f254d365c166ed62be90f986e 100644 (file)
@@ -46,6 +46,7 @@ implementation
     es_glDisable: procedure (cap: GLenum); cdecl;
     es_glIsEnabled: function (cap: GLenum): GLBoolean; cdecl;
     es_glGetString: function (name: GLenum): PChar; cdecl;
+    es_glGetError: function (): GLenum; cdecl;
     es_glClearColor: procedure (red, green, blue, alpha: GLclampf); cdecl;
     es_glClear: procedure (mask: GLbitfield); cdecl;
     es_glAlphaFunc: procedure (func: GLenum; ref: GLclampf); cdecl;
@@ -56,6 +57,8 @@ implementation
     es_glFlush: procedure; cdecl;
     es_glFinish: procedure; cdecl;
 
+    es_glMultMatrixf: procedure (m: PGLfloat); cdecl;
+    es_glOrthof: procedure (left, right, bottom, top, near, far: GLfloat); cdecl;
     es_glLoadIdentity: procedure; cdecl;
     es_glMatrixMode: procedure (mode: GLenum); cdecl;
     es_glLoadMatrixf: procedure (m: PGLfloat); cdecl;
@@ -115,6 +118,11 @@ implementation
     result := es_glGetString(name);
   end;
 
+  function glGetError: GLenum;
+  begin
+    result := es_glGetError
+  end;
+
   procedure glClearColor(red, green, blue, alpha: GLclampf);
   begin
     es_glClearColor(red, green, blue, alpha);
@@ -167,7 +175,7 @@ implementation
   procedure glBegin(mode: GLenum);
   begin
     assert(cmds.mode = GL_INVALID_ENUM);
-    assert((mode = GL_POINTS) or (mode = GL_LINES) or (mode = GL_QUADS));
+    assert((mode = GL_POINTS) or (mode = GL_LINES) or (mode = GL_QUADS) or (mode = GL_LINE_LOOP));
     cmds.mode := mode;
     SetLength(cmds.v, 0);
     SetLength(cmds.c, 0);
@@ -224,15 +232,16 @@ implementation
   begin
     i := Length(x);
     vpx := Length(v);
-    if (cmds.mode = GL_QUADS) and (i div vpx mod 4 = 3) then
+    if (cmds.mode = GL_QUADS) and (i div vpx mod 6 = 3) then
     begin
-      for j := 0 to vpx - 1 do
-        AddFloatRaw(x, x[i - 3*vpx + j]);
-      for j := 0 to vpx - 1 do
-        AddFloatRaw(x, x[i - 1*vpx + j]);
+      for j := 0 to vpx - 1 do AddFloatRaw(x, x[i - 1*vpx + j]);
+      for j := 0 to vpx - 1 do AddFloatRaw(x, v[j]);
+      for j := 0 to vpx - 1 do AddFloatRaw(x, x[i - 3*vpx + j]);
+    end
+    else
+    begin
+      for j := 0 to vpx - 1 do AddFloatRaw(x, v[j]);
     end;
-    for j := 0 to vpx - 1 do
-      AddFloatRaw(x, v[j]);
   end;
 
 (* ---------- end internals ---------- *)
@@ -290,6 +299,34 @@ implementation
 
 
 
+  procedure glOrtho (left, right, bottom, top, near, far: GLdouble);
+    var m: array [0..15] of GLfloat;
+  begin
+    if assigned(es_glOrthof) then
+    begin
+      es_glOrthof(left, right, bottom, top, near, far);
+    end
+    else
+    begin
+      m[0] := 2 / (right - left);
+      m[1] := 0;
+      m[2] := 0;
+      m[3] := 0;
+      m[4] := 0;
+      m[5] := 2 / (top - bottom);
+      m[6] := 0;
+      m[7] := 0;
+      m[8] := 0;
+      m[9] := 0;
+      m[10] := -2 / (far - near);
+      m[11] := 0;
+      m[12] := -((right + left) / (right - left));
+      m[13] := -((top + bottom) / (top - bottom));
+      m[14] := -((far + near) / (far - near));
+      m[15] := 1;
+      es_glMultMatrixf(@m[0]);
+    end;
+  end;
 
   procedure glLoadIdentity;
   begin
@@ -492,6 +529,7 @@ implementation
     es_glDisable := SDL_GL_GetProcAddress('glDisable');
     es_glIsEnabled := SDL_GL_GetProcAddress('glIsEnabled');
     es_glGetString := SDL_GL_GetProcAddress('glGetString');
+    es_glGetError := SDL_GL_GetProcAddress('glGetError');
     es_glClearColor := SDL_GL_GetProcAddress('glClearColor');
     es_glClear := SDL_GL_GetProcAddress('glClear');
     es_glAlphaFunc := SDL_GL_GetProcAddress('glAlphaFunc');
@@ -502,6 +540,8 @@ implementation
     es_glFlush := SDL_GL_GetProcAddress('glFlush');
     es_glFinish := SDL_GL_GetProcAddress('glFinish');
 
+    es_glMultMatrixf := SDL_GL_GetProcAddress('glMultMatrixf');
+    es_glOrthof := SDL_GL_GetProcAddress('glOrthof');
     es_glLoadIdentity := SDL_GL_GetProcAddress('glLoadIdentity');
     es_glMatrixMode := SDL_GL_GetProcAddress('glMatrixMode');
     es_glLoadMatrixf := SDL_GL_GetProcAddress('glLoadMatrixf');
@@ -570,6 +610,8 @@ implementation
     es_glFlush := nil;
     es_glFinish := nil;
 
+    es_glMultMatrixf := nil;
+    es_glOrthof := nil;
     es_glLoadIdentity := nil;
     es_glMatrixMode := nil;
     es_glLoadMatrixf := nil;