From: DeaDDooMER Date: Tue, 20 Feb 2018 15:08:41 +0000 (+0300) Subject: Reimplemented lines and particles rendering with nanoGL X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=385f70688f69aba255d1cdb9b7f0717bfe1b6945;p=d2df-sdl.git Reimplemented lines and particles rendering with nanoGL --- diff --git a/src/engine/e_graphics.pas b/src/engine/e_graphics.pas index b78a175..18e4c1a 100644 --- a/src/engine/e_graphics.pas +++ b/src/engine/e_graphics.pas @@ -1085,8 +1085,11 @@ end; procedure e_DrawLine(Width: Byte; X1, Y1, X2, Y2: Integer; Red, Green, Blue: Byte; Alpha: Byte = 0); +{$IFDEF USE_NANOGL} + var + v: array [0..3] of GLfloat; +{$ENDIF} begin -{$IFNDEF USE_NANOGL} // FIXIT: nanoGL doesn't support glBegin(GL_LINES) if e_NoGraphics then Exit; // Pixel-perfect lines if Width = 1 then @@ -1103,15 +1106,24 @@ begin glColor4ub(Red, Green, Blue, 255-Alpha); glLineWidth(Width); +{$IFDEF USE_NANOGL} + v[0] := X1; v[1] := Y1; v[2] := X2; v[3] := Y2; + glVertexPointer(2, GL_FLOAT, 0, @v[0]); + glEnableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDrawArrays(GL_LINES, 0, 4); +{$ELSE} glBegin(GL_LINES); glVertex2i(X1, Y1); glVertex2i(X2, Y2); glEnd(); +{$ENDIF} glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255); glDisable(GL_BLEND); -{$ENDIF} end; //------------------------------------------------------------------ diff --git a/src/game/g_gfx.pas b/src/game/g_gfx.pas index 0f26212..01ada52 100644 --- a/src/game/g_gfx.pas +++ b/src/game/g_gfx.pas @@ -1469,9 +1469,6 @@ procedure g_GFX_SetMax (count: Integer); var a: Integer; begin -{$IFDEF USE_NANOGL} // FIXIT: nanoGL doesn't support glBegin(GL_POINTS) - count := 0; -{$ENDIF} if count > 50000 then count := 50000; if (count < 1) then count := 1; SetLength(Particles, count); @@ -1627,8 +1624,19 @@ end; procedure g_GFX_Draw (); -var - a, len: Integer; + var + a, len: Integer; +{$IFDEF USE_NANOGL} + type + PVertex = ^Vertex; + Vertex = record + x, y: GLfloat; + r, g, b, a: GLfloat; + end; + var + count: Integer; + v: PVertex; +{$ENDIF} begin if not gpart_dbg_enabled then exit; @@ -1643,6 +1651,37 @@ begin glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +{$IFDEF USE_NANOGL} + len := High(Particles); + v := GetMem(len * SizeOf(Vertex) + 1); + count := 0; + for a := 0 to len do + begin + with Particles[a] do + begin + if alive and (x >= sX) and (y >= sY) and (x <= sX + sWidth) and (sY <= sY + sHeight) then + begin + v[count].x := x + 0.37; + v[count].y := y + 0.37; + v[count].r := red / 255; + v[count].g := green / 255; + v[count].b := blue / 255; + v[count].a := alpha / 255; + Inc(count); + end; + end; + end; + + glVertexPointer(2, GL_FLOAT, SizeOf(Vertex), @v.x); + glColorPointer(4, GL_FLOAT, SizeOf(Vertex), @v.r); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDrawArrays(GL_POINTS, 0, count - 1); + + Dispose(v); +{$ELSE} glBegin(GL_POINTS); len := High(Particles); @@ -1660,6 +1699,7 @@ begin end; glEnd(); +{$ENDIF} glDisable(GL_BLEND); end;