X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fengine%2Fe_graphics.pas;h=ded85939193aaba22a8f569de903b4ed3dd94504;hb=5e0a71e1d35a9037be80c8912060a913d0e98b18;hp=87b31a5b22dcaea9db8f8628a1d275266f896efe;hpb=c74268cea52d103c8f9e8b14ce6974b5619e73f9;p=d2df-sdl.git diff --git a/src/engine/e_graphics.pas b/src/engine/e_graphics.pas index 87b31a5..ded8593 100644 --- a/src/engine/e_graphics.pas +++ b/src/engine/e_graphics.pas @@ -69,9 +69,12 @@ procedure e_DrawSizeMirror(ID: DWORD; X, Y: Integer; Alpha: Byte; AlphaChannel: Blending: Boolean; Width, Height: Word; Mirror: TMirrorType = M_NONE); procedure e_DrawFill(ID: DWORD; X, Y: Integer; XCount, YCount: Word; Alpha: Integer; - AlphaChannel: Boolean; Blending: Boolean); + AlphaChannel: Boolean; Blending: Boolean; ambientBlendMode: Boolean=false); -procedure e_DrawFillX (id: DWORD; x, y, wdt, hgt: Integer; alpha: Integer; alphachannel: Boolean; blending: Boolean; scale: Single); +procedure e_DrawFillX (id: DWORD; x, y, wdt, hgt: Integer; alpha: Integer; alphachannel: Boolean; + blending: Boolean; scale: Single; ambientBlendMode: Boolean=false); + +procedure e_AmbientQuad (x, y, w, h: Integer; r, g, b, a: Byte); procedure e_DrawPoint(Size: Byte; X, Y: Integer; Red, Green, Blue: Byte); procedure e_DrawLine(Width: Byte; X1, Y1, X2, Y2: Integer; Red, Green, Blue: Byte; Alpha: Byte = 0); @@ -608,39 +611,35 @@ begin end; procedure e_DrawFill(ID: DWORD; X, Y: Integer; XCount, YCount: Word; Alpha: Integer; - AlphaChannel: Boolean; Blending: Boolean); + AlphaChannel: Boolean; Blending: Boolean; ambientBlendMode: Boolean=false); var X2, Y2, dx, w, h: Integer; u, v: Single; begin if e_NoGraphics then Exit; glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255); + ambientBlendMode := false; - if (Alpha > 0) or (AlphaChannel) or (Blending) then - glEnable(GL_BLEND) + if (Alpha > 0) or AlphaChannel or Blending then + begin + glEnable(GL_BLEND); + end else - glDisable(GL_BLEND); - - if (AlphaChannel) or (Alpha > 0) then - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - if Alpha > 0 then - glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255-Alpha); - - if Blending then - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - - if XCount = 0 then - XCount := 1; + begin + if not ambientBlendMode then glDisable(GL_BLEND); + end; + if AlphaChannel or (Alpha > 0) then glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (Alpha > 0) then glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255-Alpha); + if Blending then glBlendFunc(GL_SRC_ALPHA, GL_ONE); - if YCount = 0 then - YCount := 1; + if (XCount = 0) then XCount := 1; + if (YCount = 0) then YCount := 1; glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, e_Textures[ID].tx.id); - X2 := X + e_Textures[ID].tx.width * XCount; - Y2 := Y + e_Textures[ID].tx.height * YCount; + X2 := X+e_Textures[ID].tx.width*XCount; + Y2 := Y+e_Textures[ID].tx.height*YCount; //k8: this SHOULD work... i hope if (e_Textures[ID].tx.width = e_Textures[ID].tx.glwidth) and (e_Textures[ID].tx.height = e_Textures[ID].tx.glheight) then @@ -707,7 +706,8 @@ begin end; -procedure e_DrawFillX (id: DWORD; x, y, wdt, hgt: Integer; alpha: Integer; alphachannel: Boolean; blending: Boolean; scale: Single); +procedure e_DrawFillX (id: DWORD; x, y, wdt, hgt: Integer; alpha: Integer; alphachannel: Boolean; + blending: Boolean; scale: Single; ambientBlendMode: Boolean=false); var x2, y2: Integer; { @@ -715,8 +715,9 @@ var scxywh: array[0..3] of GLint; vpxywh: array[0..3] of GLint; } - w, h, dw, cw, ch: Integer; + w, h, dw, cw, ch, yofs: Integer; u, v, cu, cv: Single; + onlyOneY: Boolean; { procedure setScissorGLInternal (x, y, w, h: Integer); @@ -741,26 +742,28 @@ var begin if e_NoGraphics then exit; + ambientBlendMode := false; if (wdt < 1) or (hgt < 1) then exit; if (wdt mod e_Textures[ID].tx.width = 0) and (hgt mod e_Textures[ID].tx.height = 0) then begin - e_DrawFill(id, x, y, wdt div e_Textures[ID].tx.width, hgt div e_Textures[ID].tx.height, alpha, alphachannel, blending); + e_DrawFill(id, x, y, wdt div e_Textures[ID].tx.width, hgt div e_Textures[ID].tx.height, alpha, alphachannel, blending, ambientBlendMode); exit; end; glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255); if (Alpha > 0) or AlphaChannel or Blending then - glEnable(GL_BLEND) + begin + glEnable(GL_BLEND); + end else - glDisable(GL_BLEND); - + begin + if not ambientBlendMode then glDisable(GL_BLEND); + end; if AlphaChannel or (Alpha > 0) then glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - if (Alpha > 0) then glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255-Alpha); - if Blending then glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_TEXTURE_2D); @@ -770,7 +773,7 @@ begin y2 := y+hgt; //k8: this SHOULD work... i hope - if (e_Textures[ID].tx.width = e_Textures[ID].tx.glwidth) and (e_Textures[ID].tx.height = e_Textures[ID].tx.glheight) then + if {false and} (e_Textures[ID].tx.width = e_Textures[ID].tx.glwidth) and (e_Textures[ID].tx.height = e_Textures[ID].tx.glheight) then begin glBegin(GL_QUADS); glTexCoord2f(0, hgt/e_Textures[ID].tx.height); glVertex2i(x, y); @@ -796,24 +799,26 @@ begin w := e_Textures[ID].tx.width; h := e_Textures[ID].tx.height; x2 := x; + if (hgt > h) then begin y += hgt-h; onlyOneY := false; end else onlyOneY := true; glBegin(GL_QUADS); while (hgt > 0) do begin - if (hgt >= h) then begin ch := h; cv := v; end else begin ch := hgt; cv := v/(h/hgt) end; + if (hgt >= h) then begin ch := h; cv := v; yofs := 0; end else begin ch := hgt; cv := v/(h/hgt); yofs := h-hgt; end; + if onlyOneY then yofs := 0; Dec(hgt, h); dw := wdt; x := x2; while (dw > 0) do begin - if (dw >= w) then begin cw := w; cu := u; end else begin cw := dw; cu := u/(w/dw) end; + if (dw >= w) then begin cw := w; cu := u; end else begin cw := dw; cu := u/(w/dw); end; Dec(dw, w); - glTexCoord2f(0, cv); glVertex2i(X, Y); - glTexCoord2f(cu, cv); glVertex2i(X+cw, Y); - glTexCoord2f(cu, 0); glVertex2i(X+cw, Y+ch); - glTexCoord2f(0, 0); glVertex2i(X, Y+ch); + glTexCoord2f(0, cv); glVertex2i(X, Y+yofs); + glTexCoord2f(cu, cv); glVertex2i(X+cw, Y+yofs); + glTexCoord2f(cu, 0); glVertex2i(X+cw, Y+ch+yofs); + glTexCoord2f(0, 0); glVertex2i(X, Y+ch+yofs); Inc(X, w); end; - Inc(Y, h); + Dec(Y, h); end; glEnd(); //if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST); @@ -823,6 +828,37 @@ begin end; +procedure e_AmbientQuad (x, y, w, h: Integer; r, g, b, a: Byte); +begin + if e_NoGraphics then exit; + if (w < 1) or (h < 1) then exit; + if (a <> 255) or ((r or g or b) <> 0) then + begin + glEnable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + glColor4ub(r, g, b, a); + if ((r or g or b) <> 0) then + begin + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBegin(GL_QUADS); + glVertex2i(x, y); + glVertex2i(x+w, y); + glVertex2i(x+w, y+h); + glVertex2i(x, y+h); + glEnd(); + end; + glBlendFunc(GL_ZERO, GL_SRC_ALPHA); + glBegin(GL_QUADS); + glVertex2i(x, y); + glVertex2i(x+w, y); + glVertex2i(x+w, y+h); + glVertex2i(x, y+h); + glEnd(); + glDisable(GL_BLEND); + end; +end; + + procedure e_DrawAdv(ID: DWORD; X, Y: Integer; Alpha: Byte; AlphaChannel: Boolean; Blending: Boolean; Angle: Single; RC: PDFPoint; Mirror: TMirrorType = M_NONE); begin