7 SysUtils
, Classes
, Math
, e_log
, e_textures
, SDL2
, GL
, GLExt
, MAPDEF
;
10 TMirrorType
=(M_NONE
, M_HORIZONTAL
, M_VERTICAL
);
11 TBlending
=(B_NONE
, B_BLEND
, B_FILTER
, B_INVERT
);
17 TPoint
= MAPDEF
.TPoint
; // TODO: create an utiltypes.pas or something
18 // for other types like rect as well
25 Left
, Top
, Right
, Bottom
: Integer;
43 //------------------------------------------------------------------
45 //------------------------------------------------------------------
47 procedure e_SetViewPort(X
, Y
, Width
, Height
: Word);
48 procedure e_ResizeWindow(Width
, Height
: Integer);
50 procedure e_Draw(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
51 Blending
: Boolean; Mirror
: TMirrorType
= M_NONE
);
52 procedure e_DrawAdv(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
53 Blending
: Boolean; Angle
: Single; RC
: PPoint
; Mirror
: TMirrorType
= M_NONE
);
54 procedure e_DrawSize(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
55 Blending
: Boolean; Width
, Height
: Word; Mirror
: TMirrorType
= M_NONE
);
56 procedure e_DrawSizeMirror(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
57 Blending
: Boolean; Width
, Height
: Word; Mirror
: TMirrorType
= M_NONE
);
58 procedure e_DrawFill(ID
: DWORD
; X
, Y
: Integer; XCount
, YCount
: Word; Alpha
: Integer;
59 AlphaChannel
: Boolean; Blending
: Boolean);
60 procedure e_DrawPoint(Size
: Byte; X
, Y
: Integer; Red
, Green
, Blue
: Byte);
61 procedure e_DrawLine(Width
: Byte; X1
, Y1
, X2
, Y2
: Integer; Red
, Green
, Blue
: Byte; Alpha
: Byte = 0);
62 procedure e_DrawQuad(X1
, Y1
, X2
, Y2
: Integer; Red
, Green
, Blue
: Byte; Alpha
: Byte = 0);
63 procedure e_DrawFillQuad(X1
, Y1
, X2
, Y2
: Integer; Red
, Green
, Blue
, Alpha
: Byte;
64 Blending
: TBlending
= B_NONE
);
66 function e_CreateTexture(FileName
: string; var ID
: DWORD
): Boolean;
67 function e_CreateTextureEx(FileName
: string; var ID
: DWORD
; fX
, fY
, fWidth
, fHeight
: Word): Boolean;
68 function e_CreateTextureMem(pData
: Pointer; var ID
: DWORD
): Boolean;
69 function e_CreateTextureMemEx(pData
: Pointer; var ID
: DWORD
; fX
, fY
, fWidth
, fHeight
: Word): Boolean;
70 procedure e_GetTextureSize(ID
: DWORD
; Width
, Height
: PWord);
71 function e_GetTextureSize2(ID
: DWORD
): TRectWH
;
72 procedure e_DeleteTexture(ID
: DWORD
);
73 procedure e_RemoveAllTextures();
76 function e_CharFont_Create(sp
: ShortInt=0): DWORD
;
77 procedure e_CharFont_AddChar(FontID
: DWORD
; Texture
: Integer; c
: Char; w
: Byte);
78 procedure e_CharFont_Print(FontID
: DWORD
; X
, Y
: Integer; Text: string);
79 procedure e_CharFont_PrintEx(FontID
: DWORD
; X
, Y
: Integer; Text: string;
80 Color
: TRGB
; Scale
: Single = 1.0);
81 procedure e_CharFont_PrintFmt(FontID
: DWORD
; X
, Y
: Integer; Text: string);
82 procedure e_CharFont_GetSize(FontID
: DWORD
; Text: string; var w
, h
: Word);
83 procedure e_CharFont_GetSizeFmt(FontID
: DWORD
; Text: string; var w
, h
: Word);
84 function e_CharFont_GetMaxWidth(FontID
: DWORD
): Word;
85 function e_CharFont_GetMaxHeight(FontID
: DWORD
): Word;
86 procedure e_CharFont_Remove(FontID
: DWORD
);
87 procedure e_CharFont_RemoveAll();
90 procedure e_TextureFontBuild(Tex
: DWORD
; var FontID
: DWORD
; XCount
, YCount
: Word;
92 procedure e_TextureFontKill(FontID
: DWORD
);
93 procedure e_TextureFontPrint(X
, Y
: GLint
; Text: string; FontID
: DWORD
);
94 procedure e_TextureFontPrintEx(X
, Y
: GLint
; Text: string; FontID
: DWORD
; Red
, Green
,
95 Blue
: Byte; Scale
: Single; Shadow
: Boolean = False);
96 procedure e_TextureFontPrintFmt(X
, Y
: GLint
; Text: string; FontID
: DWORD
; Shadow
: Boolean = False);
97 procedure e_TextureFontGetSize(ID
: DWORD
; var CharWidth
, CharHeight
: Byte);
98 procedure e_RemoveAllTextureFont();
100 procedure e_ReleaseEngine();
101 procedure e_BeginRender();
102 procedure e_Clear(Mask
: TGLbitfield
; Red
, Green
, Blue
: Single); overload
;
103 procedure e_Clear(); overload
;
104 procedure e_EndRender();
106 function e_GetGamma(win
: PSDL_Window
): Byte;
107 procedure e_SetGamma(win
: PSDL_Window
;Gamma
: Byte);
109 procedure e_MakeScreenshot(st
: TStream
; Width
, Height
: Word);
111 function _RGB(Red
, Green
, Blue
: Byte): TRGB
;
112 function _Point(X
, Y
: Integer): TPoint2i
;
113 function _Rect(X
, Y
: Integer; Width
, Height
: Word): TRectWH
;
114 function _TRect(L
, T
, R
, B
: LongInt): TRect
;
119 e_NoGraphics
: Boolean = False;
136 TTextureFont
= record
146 Chars
: array[0..255] of
156 TSavedTexture
= record
163 e_Textures
: array of TTexture
= nil;
164 e_TextureFonts
: array of TTextureFont
= nil;
165 e_CharFonts
: array of TCharFont
;
166 //e_SavedTextures: array of TSavedTexture;
168 //------------------------------------------------------------------
169 // Èíèöèàëèçèðóåò OpenGL
170 //------------------------------------------------------------------
171 procedure e_InitGL();
175 e_DummyTextures
:= True;
181 glDisable(GL_DEPTH_TEST
);
182 glEnable(GL_SCISSOR_TEST
);
183 glClearColor(0, 0, 0, 0);
186 procedure e_SetViewPort(X
, Y
, Width
, Height
: Word);
188 mat
: Array [0..15] of GLDouble
;
191 if e_NoGraphics
then Exit
;
193 glScissor(X
, Y
, Width
, Height
);
194 glViewport(X
, Y
, Width
, Height
);
195 //gluOrtho2D(0, Width, Height, 0);
197 glMatrixMode(GL_PROJECTION
);
199 mat
[ 0] := 2.0 / Width
;
205 mat
[ 5] := -2.0 / Height
;
219 glLoadMatrixd(@mat
[0]);
221 glMatrixMode(GL_MODELVIEW
);
225 //------------------------------------------------------------------
226 // Èùåò ñâîáîäíûé ýëåìåíò â ìàññèâå òåêñòóð
227 //------------------------------------------------------------------
228 function FindTexture(): DWORD
;
232 if e_Textures
<> nil then
233 for i
:= 0 to High(e_Textures
) do
234 if e_Textures
[i
].Width
= 0 then
240 if e_Textures
= nil then
242 SetLength(e_Textures
, 32);
247 Result
:= High(e_Textures
) + 1;
248 SetLength(e_Textures
, Length(e_Textures
) + 32);
252 //------------------------------------------------------------------
254 //------------------------------------------------------------------
255 function e_CreateTexture(FileName
: String; var ID
: DWORD
): Boolean;
262 e_WriteLog('Loading texture from '+FileName
, MSG_NOTIFY
);
264 find_id
:= FindTexture();
266 if not LoadTexture(FileName
, e_Textures
[find_id
].tx
, e_Textures
[find_id
].Width
,
267 e_Textures
[find_id
].Height
, @fmt
) then Exit
;
270 e_Textures
[ID
].Fmt
:= fmt
;
275 function e_CreateTextureEx(FileName
: String; var ID
: DWORD
; fX
, fY
, fWidth
, fHeight
: Word): Boolean;
282 find_id
:= FindTexture();
284 if not LoadTextureEx(FileName
, e_Textures
[find_id
].tx
, fX
, fY
, fWidth
, fHeight
, @fmt
) then exit
;
286 e_Textures
[find_id
].Width
:= fWidth
;
287 e_Textures
[find_id
].Height
:= fHeight
;
288 e_Textures
[find_id
].Fmt
:= fmt
;
295 function e_CreateTextureMem(pData
: Pointer; var ID
: DWORD
): Boolean;
302 find_id
:= FindTexture
;
304 if not LoadTextureMem(pData
, e_Textures
[find_id
].tx
, e_Textures
[find_id
].Width
,
305 e_Textures
[find_id
].Height
, @fmt
) then exit
;
308 e_Textures
[id
].Fmt
:= fmt
;
313 function e_CreateTextureMemEx(pData
: Pointer; var ID
: DWORD
; fX
, fY
, fWidth
, fHeight
: Word): Boolean;
320 find_id
:= FindTexture();
322 if not LoadTextureMemEx(pData
, e_Textures
[find_id
].tx
, fX
, fY
, fWidth
, fHeight
, @fmt
) then exit
;
324 e_Textures
[find_id
].Width
:= fWidth
;
325 e_Textures
[find_id
].Height
:= fHeight
;
326 e_Textures
[find_id
].Fmt
:= fmt
;
333 procedure e_GetTextureSize(ID
: DWORD
; Width
, Height
: PWord);
335 if Width
<> nil then Width
^ := e_Textures
[ID
].Width
;
336 if Height
<> nil then Height
^ := e_Textures
[ID
].Height
;
339 function e_GetTextureSize2(ID
: DWORD
): TRectWH
;
347 w
:= e_Textures
[ID
].Width
;
348 h
:= e_Textures
[ID
].Height
;
355 if e_NoGraphics
then Exit
;
357 data
:= GetMemory(w
*h
*4);
358 glEnable(GL_TEXTURE_2D
);
359 glBindTexture(GL_TEXTURE_2D
, e_Textures
[ID
].tx
.id
);
360 glGetTexImage(GL_TEXTURE_2D
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
362 for y
:= h
-1 downto 0 do
369 a
:= Byte((data
+y
*w
*4+x
*4+3)^) <> 0;
375 Result
.Y
:= h
-lastline
;
387 a
:= Byte((data
+y
*w
*4+x
*4+3)^) <> 0;
393 Result
.Height
:= h
-lastline
-Result
.Y
;
405 a
:= Byte((data
+y
*w
*4+x
*4+3)^) <> 0;
411 Result
.X
:= lastline
+1;
416 for x
:= w
-1 downto 0 do
423 a
:= Byte((data
+y
*w
*4+x
*4+3)^) <> 0;
429 Result
.Width
:= lastline
-Result
.X
+1;
437 procedure e_ResizeWindow(Width
, Height
: Integer);
441 e_SetViewPort(0, 0, Width
, Height
);
444 procedure e_Draw(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
445 Blending
: Boolean; Mirror
: TMirrorType
= M_NONE
);
449 if e_NoGraphics
then Exit
;
450 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
452 if (Alpha
> 0) or (AlphaChannel
) or (Blending
) then
457 if (AlphaChannel
) or (Alpha
> 0) then
458 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
461 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255-Alpha
);
464 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
466 glEnable(GL_TEXTURE_2D
);
467 glBindTexture(GL_TEXTURE_2D
, e_Textures
[ID
].tx
.id
);
470 u
:= e_Textures
[ID
].tx
.u
;
471 v
:= e_Textures
[ID
].tx
.v
;
473 if Mirror
= M_NONE
then
475 glTexCoord2f(u
, 0); glVertex2i(X
+ e_Textures
[id
].Width
, Y
);
476 glTexCoord2f(0, 0); glVertex2i(X
, Y
);
477 glTexCoord2f(0, -v
); glVertex2i(X
, Y
+ e_Textures
[id
].Height
);
478 glTexCoord2f(u
, -v
); glVertex2i(X
+ e_Textures
[id
].Width
, Y
+ e_Textures
[id
].Height
);
481 if Mirror
= M_HORIZONTAL
then
483 glTexCoord2f(u
, 0); glVertex2i(X
, Y
);
484 glTexCoord2f(0, 0); glVertex2i(X
+ e_Textures
[id
].Width
, Y
);
485 glTexCoord2f(0, -v
); glVertex2i(X
+ e_Textures
[id
].Width
, Y
+ e_Textures
[id
].Height
);
486 glTexCoord2f(u
, -v
); glVertex2i(X
, Y
+ e_Textures
[id
].Height
);
489 if Mirror
= M_VERTICAL
then
491 glTexCoord2f(u
, -v
); glVertex2i(X
+ e_Textures
[id
].Width
, Y
);
492 glTexCoord2f(0, -v
); glVertex2i(X
, Y
);
493 glTexCoord2f(0, 0); glVertex2i(X
, Y
+ e_Textures
[id
].Height
);
494 glTexCoord2f(u
, 0); glVertex2i(X
+ e_Textures
[id
].Width
, Y
+ e_Textures
[id
].Height
);
502 procedure e_DrawSize(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
503 Blending
: Boolean; Width
, Height
: Word; Mirror
: TMirrorType
= M_NONE
);
507 if e_NoGraphics
then Exit
;
508 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
510 if (Alpha
> 0) or (AlphaChannel
) or (Blending
) then
515 if (AlphaChannel
) or (Alpha
> 0) then
516 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
519 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255-Alpha
);
522 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
524 glEnable(GL_TEXTURE_2D
);
525 glBindTexture(GL_TEXTURE_2D
, e_Textures
[ID
].tx
.id
);
527 u
:= e_Textures
[ID
].tx
.u
;
528 v
:= e_Textures
[ID
].tx
.v
;
531 glTexCoord2f(0, v
); glVertex2i(X
, Y
);
532 glTexCoord2f(u
, v
); glVertex2i(X
+ Width
, Y
);
533 glTexCoord2f(u
, 0); glVertex2i(X
+ Width
, Y
+ Height
);
534 glTexCoord2f(0, 0); glVertex2i(X
, Y
+ Height
);
540 procedure e_DrawSizeMirror(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
541 Blending
: Boolean; Width
, Height
: Word; Mirror
: TMirrorType
= M_NONE
);
545 if e_NoGraphics
then Exit
;
546 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
548 if (Alpha
> 0) or (AlphaChannel
) or (Blending
) then
553 if (AlphaChannel
) or (Alpha
> 0) then
554 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
557 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255-Alpha
);
560 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
562 glEnable(GL_TEXTURE_2D
);
563 glBindTexture(GL_TEXTURE_2D
, e_Textures
[ID
].tx
.id
);
566 u
:= e_Textures
[ID
].tx
.u
;
567 v
:= e_Textures
[ID
].tx
.v
;
569 if Mirror
= M_NONE
then
571 glTexCoord2f(u
, 0); glVertex2i(X
+ Width
, Y
);
572 glTexCoord2f(0, 0); glVertex2i(X
, Y
);
573 glTexCoord2f(0, -v
); glVertex2i(X
, Y
+ Height
);
574 glTexCoord2f(u
, -v
); glVertex2i(X
+ Width
, Y
+ Height
);
577 if Mirror
= M_HORIZONTAL
then
579 glTexCoord2f(u
, 0); glVertex2i(X
, Y
);
580 glTexCoord2f(0, 0); glVertex2i(X
+ Width
, Y
);
581 glTexCoord2f(0, -v
); glVertex2i(X
+ Width
, Y
+ Height
);
582 glTexCoord2f(u
, -v
); glVertex2i(X
, Y
+ Height
);
585 if Mirror
= M_VERTICAL
then
587 glTexCoord2f(u
, -v
); glVertex2i(X
+ Width
, Y
);
588 glTexCoord2f(0, -v
); glVertex2i(X
, Y
);
589 glTexCoord2f(0, 0); glVertex2i(X
, Y
+ Height
);
590 glTexCoord2f(u
, 0); glVertex2i(X
+ Width
, Y
+ Height
);
598 procedure e_DrawFill(ID
: DWORD
; X
, Y
: Integer; XCount
, YCount
: Word; Alpha
: Integer;
599 AlphaChannel
: Boolean; Blending
: Boolean);
601 X2
, Y2
, dx
, w
, h
: Integer;
604 if e_NoGraphics
then Exit
;
605 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
607 if (Alpha
> 0) or (AlphaChannel
) or (Blending
) then
612 if (AlphaChannel
) or (Alpha
> 0) then
613 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
616 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255-Alpha
);
619 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
627 glEnable(GL_TEXTURE_2D
);
628 glBindTexture(GL_TEXTURE_2D
, e_Textures
[ID
].tx
.id
);
630 X2
:= X
+ e_Textures
[ID
].Width
* XCount
;
631 Y2
:= Y
+ e_Textures
[ID
].Height
* YCount
;
633 //k8: this SHOULD work... i hope
634 if (e_Textures
[ID
].tx
.width
= e_Textures
[ID
].tx
.glwidth
) and (e_Textures
[ID
].tx
.height
= e_Textures
[ID
].tx
.glheight
) then
637 glTexCoord2i(0, YCount
); glVertex2i(X
, Y
);
638 glTexCoord2i(XCount
, YCount
); glVertex2i(X2
, Y
);
639 glTexCoord2i(XCount
, 0); glVertex2i(X2
, Y2
);
640 glTexCoord2i(0, 0); glVertex2i(X
, Y2
);
647 u
:= e_Textures
[ID
].tx
.u
;
648 v
:= e_Textures
[ID
].tx
.v
;
649 w
:= e_Textures
[ID
].tx
.width
;
650 h
:= e_Textures
[ID
].tx
.height
;
657 glTexCoord2f(0, v
); glVertex2i(X
, Y
);
658 glTexCoord2f(u
, v
); glVertex2i(X
+w
, Y
);
659 glTexCoord2f(u
, 0); glVertex2i(X
+w
, Y
+h
);
660 glTexCoord2f(0, 0); glVertex2i(X
, Y
+h
);
674 procedure e_DrawAdv(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
675 Blending
: Boolean; Angle
: Single; RC
: PPoint
; Mirror
: TMirrorType
= M_NONE
);
679 if e_NoGraphics
then Exit
;
680 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
682 if (Alpha
> 0) or (AlphaChannel
) or (Blending
) then
687 if (AlphaChannel
) or (Alpha
> 0) then
688 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
691 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255-Alpha
);
694 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
696 if (Angle
<> 0) and (RC
<> nil) then
699 glTranslatef(X
+RC
.X
, Y
+RC
.Y
, 0);
700 glRotatef(Angle
, 0, 0, 1);
701 glTranslatef(-(X
+RC
.X
), -(Y
+RC
.Y
), 0);
704 glEnable(GL_TEXTURE_2D
);
705 glBindTexture(GL_TEXTURE_2D
, e_Textures
[id
].tx
.id
);
706 glBegin(GL_QUADS
); //0-1 1-1
709 u
:= e_Textures
[ID
].tx
.u
;
710 v
:= e_Textures
[ID
].tx
.v
;
712 if Mirror
= M_NONE
then
714 glTexCoord2f(u
, 0); glVertex2i(X
+ e_Textures
[id
].Width
, Y
);
715 glTexCoord2f(0, 0); glVertex2i(X
, Y
);
716 glTexCoord2f(0, -v
); glVertex2i(X
, Y
+ e_Textures
[id
].Height
);
717 glTexCoord2f(u
, -v
); glVertex2i(X
+ e_Textures
[id
].Width
, Y
+ e_Textures
[id
].Height
);
720 if Mirror
= M_HORIZONTAL
then
722 glTexCoord2f(u
, 0); glVertex2i(X
, Y
);
723 glTexCoord2f(0, 0); glVertex2i(X
+ e_Textures
[id
].Width
, Y
);
724 glTexCoord2f(0, -v
); glVertex2i(X
+ e_Textures
[id
].Width
, Y
+ e_Textures
[id
].Height
);
725 glTexCoord2f(u
, -v
); glVertex2i(X
, Y
+ e_Textures
[id
].Height
);
728 if Mirror
= M_VERTICAL
then
730 glTexCoord2f(u
, -v
); glVertex2i(X
+ e_Textures
[id
].Width
, Y
);
731 glTexCoord2f(0, -v
); glVertex2i(X
, Y
);
732 glTexCoord2f(0, 0); glVertex2i(X
, Y
+ e_Textures
[id
].Height
);
733 glTexCoord2f(u
, 0); glVertex2i(X
+ e_Textures
[id
].Width
, Y
+ e_Textures
[id
].Height
);
744 procedure e_DrawPoint(Size
: Byte; X
, Y
: Integer; Red
, Green
, Blue
: Byte);
746 if e_NoGraphics
then Exit
;
747 glDisable(GL_TEXTURE_2D
);
748 glColor3ub(Red
, Green
, Blue
);
751 if (Size
= 2) or (Size
= 4) then
755 glVertex2f(X
+0.3, Y
+1.0);
758 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
761 procedure e_LineCorrection(var X1
, Y1
, X2
, Y2
: Integer);
763 // Make lines only top-left/bottom-right and top-right/bottom-left
775 // Pixel-perfect hack
783 procedure e_DrawQuad(X1
, Y1
, X2
, Y2
: Integer; Red
, Green
, Blue
: Byte; Alpha
: Byte = 0);
785 nX1
, nY1
, nX2
, nY2
: Integer;
787 if e_NoGraphics
then Exit
;
788 // Only top-left/bottom-right quad
805 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
809 glDisable(GL_TEXTURE_2D
);
810 glColor4ub(Red
, Green
, Blue
, 255-Alpha
);
814 nX1
:= X1
; nY1
:= Y1
;
815 nX2
:= X2
; nY2
:= Y1
;
816 e_LineCorrection(nX1
, nY1
, nX2
, nY2
); // Pixel-perfect lines
817 glVertex2i(nX1
, nY1
);
818 glVertex2i(nX2
, nY2
);
820 nX1
:= X2
; nY1
:= Y1
;
821 nX2
:= X2
; nY2
:= Y2
;
822 e_LineCorrection(nX1
, nY1
, nX2
, nY2
);
823 glVertex2i(nX1
, nY1
);
824 glVertex2i(nX2
, nY2
);
826 nX1
:= X2
; nY1
:= Y2
;
827 nX2
:= X1
; nY2
:= Y2
;
828 e_LineCorrection(nX1
, nY1
, nX2
, nY2
);
829 glVertex2i(nX1
, nY1
);
830 glVertex2i(nX2
, nY2
);
832 nX1
:= X1
; nY1
:= Y2
;
833 nX2
:= X1
; nY2
:= Y1
;
834 e_LineCorrection(nX1
, nY1
, nX2
, nY2
);
835 glVertex2i(nX1
, nY1
);
836 glVertex2i(nX2
, nY2
);
839 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
844 procedure e_DrawFillQuad(X1
, Y1
, X2
, Y2
: Integer; Red
, Green
, Blue
, Alpha
: Byte;
845 Blending
: TBlending
= B_NONE
);
847 if e_NoGraphics
then Exit
;
848 if (Alpha
> 0) or (Blending
<> B_NONE
) then
853 if Blending
= B_BLEND
then
854 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
)
856 if Blending
= B_FILTER
then
857 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
)
859 if Blending
= B_INVERT
then
860 glBlendFunc(GL_ONE_MINUS_DST_COLOR
, GL_ZERO
)
863 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
865 glDisable(GL_TEXTURE_2D
);
866 glColor4ub(Red
, Green
, Blue
, 255-Alpha
);
878 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
883 procedure e_DrawLine(Width
: Byte; X1
, Y1
, X2
, Y2
: Integer; Red
, Green
, Blue
: Byte; Alpha
: Byte = 0);
885 if e_NoGraphics
then Exit
;
886 // Pixel-perfect lines
888 e_LineCorrection(X1
, Y1
, X2
, Y2
);
893 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
897 glDisable(GL_TEXTURE_2D
);
898 glColor4ub(Red
, Green
, Blue
, 255-Alpha
);
906 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
911 //------------------------------------------------------------------
912 // Óäàëÿåò òåêñòóðó èç ìàññèâà
913 //------------------------------------------------------------------
914 procedure e_DeleteTexture(ID
: DWORD
);
916 if not e_NoGraphics
then
917 glDeleteTextures(1, @e_Textures
[ID
].tx
.id
);
918 e_Textures
[ID
].tx
.id
:= 0;
919 e_Textures
[ID
].Width
:= 0;
920 e_Textures
[ID
].Height
:= 0;
923 //------------------------------------------------------------------
924 // Óäàëÿåò âñå òåêñòóðû
925 //------------------------------------------------------------------
926 procedure e_RemoveAllTextures();
930 if e_Textures
= nil then Exit
;
932 for i
:= 0 to High(e_Textures
) do
933 if e_Textures
[i
].Width
<> 0 then e_DeleteTexture(i
);
937 //------------------------------------------------------------------
939 //------------------------------------------------------------------
940 procedure e_ReleaseEngine();
943 e_RemoveAllTextureFont
;
946 procedure e_BeginRender();
948 if e_NoGraphics
then Exit
;
949 glEnable(GL_ALPHA_TEST
);
950 glAlphaFunc(GL_GREATER
, 0.0);
953 procedure e_Clear(Mask
: TGLbitfield
; Red
, Green
, Blue
: Single); overload
;
955 if e_NoGraphics
then Exit
;
956 glClearColor(Red
, Green
, Blue
, 0);
960 procedure e_Clear(); overload
;
962 if e_NoGraphics
then Exit
;
963 glClearColor(0, 0, 0, 0);
964 glClear(GL_COLOR_BUFFER_BIT
);
967 procedure e_EndRender();
969 if e_NoGraphics
then Exit
;
973 function e_GetGamma(win
: PSDL_Window
): Byte;
975 ramp
: array [0..256*3-1] of Word;
976 rgb
: array [0..2] of Double;
985 if e_NoGraphics
then Exit
;
990 SDL_GetWindowGammaRamp(win
, @ramp
[0], @ramp
[256], @ramp
[512]);
999 for j
:= min
to max
- 1 do
1002 B
:= (j
mod 256)/256;
1004 sum
:= sum
+ ln(A
)/ln(B
);
1007 rgb
[i
] := sum
/ count
;
1010 Result
:= 100 - Trunc(((rgb
[0] + rgb
[1] + rgb
[2])/3 - 0.23) * 100/(2.7 - 0.23));
1013 procedure e_SetGamma(win
: PSDL_Window
; Gamma
: Byte);
1015 ramp
: array [0..256*3-1] of Word;
1020 if e_NoGraphics
then Exit
;
1021 g
:= (100 - Gamma
)*(2.7 - 0.23)/100 + 0.23;
1023 for i
:= 0 to 255 do
1025 r
:= Exp(g
* ln(i
/256))*65536;
1026 if r
< 0 then r
:= 0
1027 else if r
> 65535 then r
:= 65535;
1028 ramp
[i
] := trunc(r
);
1029 ramp
[i
+ 256] := trunc(r
);
1030 ramp
[i
+ 512] := trunc(r
);
1033 SDL_SetWindowGammaRamp(win
, @ramp
[0], @ramp
[256], @ramp
[512]);
1036 function e_CharFont_Create(sp
: ShortInt=0): DWORD
;
1040 e_WriteLog('Creating CharFont...', MSG_NOTIFY
);
1044 if e_CharFonts
<> nil then
1045 for i
:= 0 to High(e_CharFonts
) do
1046 if not e_CharFonts
[i
].Live
then
1052 if id
= DWORD(-1) then
1054 SetLength(e_CharFonts
, Length(e_CharFonts
) + 1);
1055 id
:= High(e_CharFonts
);
1058 with e_CharFonts
[id
] do
1060 for i
:= 0 to High(Chars
) do
1074 procedure e_CharFont_AddChar(FontID
: DWORD
; Texture
: Integer; c
: Char; w
: Byte);
1076 with e_CharFonts
[FontID
].Chars
[Ord(c
)] do
1078 TextureID
:= Texture
;
1083 procedure e_CharFont_Print(FontID
: DWORD
; X
, Y
: Integer; Text: string);
1087 if e_NoGraphics
then Exit
;
1088 if Text = '' then Exit
;
1089 if e_CharFonts
= nil then Exit
;
1090 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1092 with e_CharFonts
[FontID
] do
1094 for a
:= 1 to Length(Text) do
1095 with Chars
[Ord(Text[a
])] do
1096 if TextureID
<> -1 then
1098 e_Draw(TextureID
, X
, Y
, 0, True, False);
1099 X
:= X
+Width
+IfThen(a
= Length(Text), 0, Space
);
1104 procedure e_CharFont_PrintEx(FontID
: DWORD
; X
, Y
: Integer; Text: string;
1105 Color
: TRGB
; Scale
: Single = 1.0);
1110 if e_NoGraphics
then Exit
;
1111 if Text = '' then Exit
;
1112 if e_CharFonts
= nil then Exit
;
1113 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1115 with e_CharFonts
[FontID
] do
1117 for a
:= 1 to Length(Text) do
1118 with Chars
[Ord(Text[a
])] do
1119 if TextureID
<> -1 then
1121 if Scale
<> 1.0 then
1124 glScalef(Scale
, Scale
, 0);
1129 e_Draw(TextureID
, X
, Y
, 0, True, False);
1132 if Scale
<> 1.0 then glPopMatrix
;
1134 X
:= X
+Width
+IfThen(a
= Length(Text), 0, Space
);
1139 procedure e_CharFont_PrintFmt(FontID
: DWORD
; X
, Y
: Integer; Text: string);
1141 a
, TX
, TY
, len
: Integer;
1145 if e_NoGraphics
then Exit
;
1146 if Text = '' then Exit
;
1147 if e_CharFonts
= nil then Exit
;
1148 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1156 len
:= Length(Text);
1158 e_CharFont_GetSize(FontID
, 'A', w
, h
);
1160 with e_CharFonts
[FontID
] do
1162 for a
:= 1 to len
do
1173 c
.R
:= 0; c
.G
:= 0; c
.B
:= 0;
1178 c
.R
:= 255; c
.G
:= 255; c
.B
:= 255;
1183 c
.R
:= c
.R
div 2; c
.G
:= c
.G
div 2; c
.B
:= c
.B
div 2;
1188 c
.R
:= Min(c
.R
* 2, 255); c
.G
:= Min(c
.G
* 2, 255); c
.B
:= Min(c
.B
* 2, 255);
1193 c
.R
:= 255; c
.G
:= 0; c
.B
:= 0;
1198 c
.R
:= 0; c
.G
:= 255; c
.B
:= 0;
1203 c
.R
:= 0; c
.G
:= 0; c
.B
:= 255;
1208 c
.R
:= 255; c
.G
:= 255; c
.B
:= 0;
1213 with Chars
[Ord(Text[a
])] do
1214 if TextureID
<> -1 then
1218 e_Draw(TextureID
, TX
, TY
, 0, True, False);
1221 TX
:= TX
+Width
+IfThen(a
= Length(Text), 0, Space
);
1227 procedure e_CharFont_GetSize(FontID
: DWORD
; Text: string; var w
, h
: Word);
1235 if Text = '' then Exit
;
1236 if e_CharFonts
= nil then Exit
;
1237 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1239 with e_CharFonts
[FontID
] do
1241 for a
:= 1 to Length(Text) do
1242 with Chars
[Ord(Text[a
])] do
1243 if TextureID
<> -1 then
1245 w
:= w
+Width
+IfThen(a
= Length(Text), 0, Space
);
1246 e_GetTextureSize(TextureID
, nil, @h2
);
1247 if h2
> h
then h
:= h2
;
1252 procedure e_CharFont_GetSizeFmt(FontID
: DWORD
; Text: string; var w
, h
: Word);
1254 a
, lines
, len
: Integer;
1261 if Text = '' then Exit
;
1262 if e_CharFonts
= nil then Exit
;
1263 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1266 len
:= Length(Text);
1268 with e_CharFonts
[FontID
] do
1270 for a
:= 1 to len
do
1272 if Text[a
] = #10 then
1282 else if Text[a
] in [#1, #2, #3, #4, #18, #19, #20, #21] then
1285 with Chars
[Ord(Text[a
])] do
1286 if TextureID
<> -1 then
1288 w2
:= w2
+ Width
+ IfThen(a
= len
, 0, Space
);
1289 e_GetTextureSize(TextureID
, nil, @h2
);
1290 if h2
> h
then h
:= h2
;
1300 function e_CharFont_GetMaxWidth(FontID
: DWORD
): Word;
1306 if e_CharFonts
= nil then Exit
;
1307 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1309 for a
:= 0 to High(e_CharFonts
[FontID
].Chars
) do
1310 Result
:= Max(Result
, e_CharFonts
[FontID
].Chars
[a
].Width
);
1313 function e_CharFont_GetMaxHeight(FontID
: DWORD
): Word;
1320 if e_CharFonts
= nil then Exit
;
1321 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1323 for a
:= 0 to High(e_CharFonts
[FontID
].Chars
) do
1325 if e_CharFonts
[FontID
].Chars
[a
].TextureID
<> -1 then
1326 e_GetTextureSize(e_CharFonts
[FontID
].Chars
[a
].TextureID
, nil, @h2
)
1328 if h2
> Result
then Result
:= h2
;
1332 procedure e_CharFont_Remove(FontID
: DWORD
);
1336 with e_CharFonts
[FontID
] do
1337 for a
:= 0 to High(Chars
) do
1338 if Chars
[a
].TextureID
<> -1 then e_DeleteTexture(Chars
[a
].TextureID
);
1340 e_CharFonts
[FontID
].Live
:= False;
1343 procedure e_CharFont_RemoveAll();
1347 if e_CharFonts
= nil then Exit
;
1349 for a
:= 0 to High(e_CharFonts
) do
1350 e_CharFont_Remove(a
);
1355 procedure e_TextureFontBuild(Tex
: DWORD
; var FontID
: DWORD
; XCount
, YCount
: Word;
1362 if e_NoGraphics
then Exit
;
1363 e_WriteLog('Creating texture font...', MSG_NOTIFY
);
1367 if e_TextureFonts
<> nil then
1368 for i
:= 0 to High(e_TextureFonts
) do
1369 if e_TextureFonts
[i
].Base
= 0 then
1375 if id
= DWORD(-1) then
1377 SetLength(e_TextureFonts
, Length(e_TextureFonts
) + 1);
1378 id
:= High(e_TextureFonts
);
1381 with e_TextureFonts
[id
] do
1383 Base
:= glGenLists(XCount
*YCount
);
1384 TextureID
:= e_Textures
[Tex
].tx
.id
;
1385 CharWidth
:= (e_Textures
[Tex
].Width
div XCount
)+Space
;
1386 CharHeight
:= e_Textures
[Tex
].Height
div YCount
;
1393 glBindTexture(GL_TEXTURE_2D
, e_Textures
[Tex
].tx
.id
);
1394 for loop1
:= 0 to XCount
*YCount
-1 do
1396 cx
:= (loop1
mod XCount
)/XCount
;
1397 cy
:= (loop1
div YCount
)/YCount
;
1399 glNewList(e_TextureFonts
[id
].Base
+loop1
, GL_COMPILE
);
1401 glTexCoord2f(cx
, 1.0-cy
-1/YCount
);
1402 glVertex2d(0, e_Textures
[Tex
].Height
div YCount
);
1404 glTexCoord2f(cx
+1/XCount
, 1.0-cy
-1/YCount
);
1405 glVertex2i(e_Textures
[Tex
].Width
div XCount
, e_Textures
[Tex
].Height
div YCount
);
1407 glTexCoord2f(cx
+1/XCount
, 1.0-cy
);
1408 glVertex2i(e_Textures
[Tex
].Width
div XCount
, 0);
1410 glTexCoord2f(cx
, 1.0-cy
);
1413 glTranslated((e_Textures
[Tex
].Width
div XCount
)+Space
, 0, 0);
1420 procedure e_TextureFontKill(FontID
: DWORD
);
1422 if e_NoGraphics
then Exit
;
1423 glDeleteLists(e_TextureFonts
[FontID
].Base
, 256);
1424 e_TextureFonts
[FontID
].Base
:= 0;
1427 procedure e_TextureFontPrint(X
, Y
: GLint
; Text: string; FontID
: DWORD
);
1429 if e_NoGraphics
then Exit
;
1430 if Integer(FontID
) > High(e_TextureFonts
) then Exit
;
1431 if Text = '' then Exit
;
1433 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1436 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
1439 glBindTexture(GL_TEXTURE_2D
, e_TextureFonts
[FontID
].TextureID
);
1440 glEnable(GL_TEXTURE_2D
);
1441 glTranslated(x
, y
, 0);
1442 glListBase(DWORD(Integer(e_TextureFonts
[FontID
].Base
)-32));
1443 glCallLists(Length(Text), GL_UNSIGNED_BYTE
, PChar(Text));
1444 glDisable(GL_TEXTURE_2D
);
1447 glDisable(GL_BLEND
);
1450 // god forgive me for this, but i cannot figure out how to do it without lists
1451 procedure e_TextureFontPrintChar(X
, Y
: Integer; Ch
: Char; FontID
: DWORD
; Shadow
: Boolean = False);
1453 if e_NoGraphics
then Exit
;
1458 glColor4ub(0, 0, 0, 128);
1459 glTranslated(X
+1, Y
+1, 0);
1460 glCallLists(1, GL_UNSIGNED_BYTE
, @Ch
);
1465 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
1466 glTranslated(X
, Y
, 0);
1467 glCallLists(1, GL_UNSIGNED_BYTE
, @Ch
);
1472 procedure e_TextureFontPrintFmt(X
, Y
: Integer; Text: string; FontID
: DWORD
; Shadow
: Boolean = False);
1474 a
, TX
, TY
, len
: Integer;
1478 if e_NoGraphics
then Exit
;
1479 if Text = '' then Exit
;
1480 if e_TextureFonts
= nil then Exit
;
1481 if Integer(FontID
) > High(e_TextureFonts
) then Exit
;
1489 len
:= Length(Text);
1491 w
:= e_TextureFonts
[FontID
].CharWidth
;
1493 with e_TextureFonts
[FontID
] do
1495 glBindTexture(GL_TEXTURE_2D
, e_TextureFonts
[FontID
].TextureID
);
1496 glEnable(GL_TEXTURE_2D
);
1497 glListBase(DWORD(Integer(e_TextureFonts
[FontID
].Base
)-32));
1499 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1502 for a
:= 1 to len
do
1513 c
.R
:= 0; c
.G
:= 0; c
.B
:= 0;
1518 c
.R
:= 255; c
.G
:= 255; c
.B
:= 255;
1523 c
.R
:= c
.R
div 2; c
.G
:= c
.G
div 2; c
.B
:= c
.B
div 2;
1528 c
.R
:= Min(c
.R
* 2, 255); c
.G
:= Min(c
.G
* 2, 255); c
.B
:= Min(c
.B
* 2, 255);
1533 c
.R
:= 255; c
.G
:= 0; c
.B
:= 0;
1538 c
.R
:= 0; c
.G
:= 255; c
.B
:= 0;
1543 c
.R
:= 0; c
.G
:= 0; c
.B
:= 255;
1548 c
.R
:= 255; c
.G
:= 255; c
.B
:= 0;
1555 e_TextureFontPrintChar(TX
, TY
, Text[a
], FontID
, Shadow
);
1560 glDisable(GL_TEXTURE_2D
);
1561 glDisable(GL_BLEND
);
1565 procedure e_TextureFontPrintEx(X
, Y
: GLint
; Text: string; FontID
: DWORD
; Red
, Green
,
1566 Blue
: Byte; Scale
: Single; Shadow
: Boolean = False);
1568 if e_NoGraphics
then Exit
;
1569 if Text = '' then Exit
;
1572 glBindTexture(GL_TEXTURE_2D
, e_TextureFonts
[FontID
].TextureID
);
1573 glEnable(GL_TEXTURE_2D
);
1574 glListBase(DWORD(Integer(e_TextureFonts
[FontID
].Base
)-32));
1576 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1581 glColor4ub(0, 0, 0, 128);
1582 glTranslated(x
+1, y
+1, 0);
1583 glScalef(Scale
, Scale
, 0);
1584 glCallLists(Length(Text), GL_UNSIGNED_BYTE
, PChar(Text));
1589 glColor4ub(Red
, Green
, Blue
, 255);
1590 glTranslated(x
, y
, 0);
1591 glScalef(Scale
, Scale
, 0);
1592 glCallLists(Length(Text), GL_UNSIGNED_BYTE
, PChar(Text));
1594 glDisable(GL_TEXTURE_2D
);
1596 glColor3ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
);
1597 glDisable(GL_BLEND
);
1600 procedure e_TextureFontGetSize(ID
: DWORD
; var CharWidth
, CharHeight
: Byte);
1604 if e_NoGraphics
then Exit
;
1605 if Integer(ID
) > High(e_TextureFonts
) then
1607 CharWidth
:= e_TextureFonts
[ID
].CharWidth
;
1608 CharHeight
:= e_TextureFonts
[ID
].CharHeight
;
1611 procedure e_RemoveAllTextureFont();
1615 if e_NoGraphics
then Exit
;
1616 if e_TextureFonts
= nil then Exit
;
1618 for i
:= 0 to High(e_TextureFonts
) do
1619 if e_TextureFonts
[i
].Base
<> 0 then
1621 glDeleteLists(e_TextureFonts
[i
].Base
, 256);
1622 e_TextureFonts
[i
].Base
:= 0;
1625 e_TextureFonts
:= nil;
1628 function _RGB(Red
, Green
, Blue
: Byte): TRGB
;
1635 function _Point(X
, Y
: Integer): TPoint2i
;
1641 function _Rect(X
, Y
: Integer; Width
, Height
: Word): TRectWH
;
1645 Result
.Width
:= Width
;
1646 Result
.Height
:= Height
;
1649 function _TRect(L
, T
, R
, B
: LongInt): TRect
;
1658 procedure e_MakeScreenshot (st
: TStream
; Width
, Height
: Word);
1660 pixels
, obuf
, scln
, ps
, pd
: PByte;
1665 sign
: array [0..7] of Byte;
1666 hbuf
: array [0..12] of Byte;
1669 if e_NoGraphics
then Exit
;
1672 // first, extract and pack graphics data
1674 if (Width
mod 4) > 0 then Width
:= Width
+ 4 - (Width
mod 4);
1676 GetMem(pixels
, Width
*Height
*3);
1678 FillChar(pixels
^, Width
*Height
*3, 0);
1679 glReadPixels(0, 0, Width
, Height
, GL_RGB
, GL_UNSIGNED_BYTE
, pixels
);
1680 //e_WriteLog('PNG: pixels read', MSG_NOTIFY);
1683 GetMem(scln
, (Width
*3+1)*Height
);
1687 Inc(ps
, (Width
*3)*(Height
-1));
1688 for i
:= 0 to Height
-1 do
1692 Move(ps
^, pd
^, Width
*3);
1703 obufsize
:= (Width
*3+1)*Height
*2;
1704 GetMem(obuf
, obufsize
);
1709 res
:= compress2(Pointer(obuf
), dlen
, Pointer(pixels
), (Width
*3+1)*Height
, 9);
1710 if res
= Z_OK
then break
;
1711 if res
<> Z_BUF_ERROR
then raise Exception
.Create('can''t pack data for PNG');
1712 obufsize
:= obufsize
*2;
1715 GetMem(obuf
, obufsize
);
1717 //e_WriteLog(Format('PNG: pixels compressed from %d to %d', [Integer(Width*Height*3), Integer(dlen)]), MSG_NOTIFY);
1730 st
.writeBuffer(sign
, 8);
1731 //e_WriteLog('PNG: signature written', MSG_NOTIFY);
1734 writeIntBE(st
, LongWord(13));
1739 st
.writeBuffer(sign
, 4);
1740 crc
:= crc32(0, @sign
, 4);
1743 hbuf
[2] := (Width
shr 8) and $ff;
1744 hbuf
[3] := Width
and $ff;
1747 hbuf
[6] := (Height
shr 8) and $ff;
1748 hbuf
[7] := Height
and $ff;
1749 hbuf
[8] := 8; // bit depth
1750 hbuf
[9] := 2; // RGB
1751 hbuf
[10] := 0; // compression method
1752 hbuf
[11] := 0; // filter method
1753 hbuf
[12] := 0; // no interlace
1754 crc
:= crc32(crc
, @hbuf
, 13);
1755 st
.writeBuffer(hbuf
, 13);
1756 writeIntBE(st
, crc
);
1757 //e_WriteLog('PNG: header written', MSG_NOTIFY);
1760 writeIntBE(st
, LongWord(dlen
));
1765 st
.writeBuffer(sign
, 4);
1766 crc
:= crc32(0, @sign
, 4);
1767 crc
:= crc32(crc
, obuf
, dlen
);
1768 st
.writeBuffer(obuf
^, dlen
);
1769 writeIntBE(st
, crc
);
1770 //e_WriteLog('PNG: image data written', MSG_NOTIFY);
1773 writeIntBE(st
, LongWord(0));
1778 st
.writeBuffer(sign
, 4);
1779 crc
:= crc32(0, @sign
, 4);
1780 writeIntBE(st
, crc
);
1781 //e_WriteLog('PNG: end marker written', MSG_NOTIFY);
1783 if obuf
<> nil then FreeMem(obuf
);