6 SysUtils
, Math
, e_log
, e_textures
, SDL2
, GL
, GLExt
, MAPDEF
;
9 TMirrorType
=(M_NONE
, M_HORIZONTAL
, M_VERTICAL
);
10 TBlending
=(B_NONE
, B_BLEND
, B_FILTER
, B_INVERT
);
16 TPoint
= MAPDEF
.TPoint
; // TODO: create an utiltypes.pas or something
17 // for other types like rect as well
24 Left
, Top
, Right
, Bottom
: Integer;
42 //------------------------------------------------------------------
44 //------------------------------------------------------------------
46 procedure e_SetViewPort(X
, Y
, Width
, Height
: Word);
47 procedure e_ResizeWindow(Width
, Height
: Integer);
49 procedure e_Draw(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
50 Blending
: Boolean; Mirror
: TMirrorType
= M_NONE
);
51 procedure e_DrawAdv(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
52 Blending
: Boolean; Angle
: Single; RC
: PPoint
; Mirror
: TMirrorType
= M_NONE
);
53 procedure e_DrawSize(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
54 Blending
: Boolean; Width
, Height
: Word; Mirror
: TMirrorType
= M_NONE
);
55 procedure e_DrawSizeMirror(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
56 Blending
: Boolean; Width
, Height
: Word; Mirror
: TMirrorType
= M_NONE
);
57 procedure e_DrawFill(ID
: DWORD
; X
, Y
: Integer; XCount
, YCount
: Word; Alpha
: Integer;
58 AlphaChannel
: Boolean; Blending
: Boolean);
59 procedure e_DrawPoint(Size
: Byte; X
, Y
: Integer; Red
, Green
, Blue
: Byte);
60 procedure e_DrawLine(Width
: Byte; X1
, Y1
, X2
, Y2
: Integer; Red
, Green
, Blue
: Byte; Alpha
: Byte = 0);
61 procedure e_DrawQuad(X1
, Y1
, X2
, Y2
: Integer; Red
, Green
, Blue
: Byte; Alpha
: Byte = 0);
62 procedure e_DrawFillQuad(X1
, Y1
, X2
, Y2
: Integer; Red
, Green
, Blue
, Alpha
: Byte;
63 Blending
: TBlending
= B_NONE
);
65 function e_CreateTexture(FileName
: string; var ID
: DWORD
): Boolean;
66 function e_CreateTextureEx(FileName
: string; var ID
: DWORD
; fX
, fY
, fWidth
, fHeight
: Word): Boolean;
67 function e_CreateTextureMem(pData
: Pointer; var ID
: DWORD
): Boolean;
68 function e_CreateTextureMemEx(pData
: Pointer; var ID
: DWORD
; fX
, fY
, fWidth
, fHeight
: Word): Boolean;
69 procedure e_GetTextureSize(ID
: DWORD
; Width
, Height
: PWord);
70 function e_GetTextureSize2(ID
: DWORD
): TRectWH
;
71 procedure e_DeleteTexture(ID
: DWORD
);
72 procedure e_RemoveAllTextures();
75 function e_CharFont_Create(sp
: ShortInt=0): DWORD
;
76 procedure e_CharFont_AddChar(FontID
: DWORD
; Texture
: Integer; c
: Char; w
: Byte);
77 procedure e_CharFont_Print(FontID
: DWORD
; X
, Y
: Integer; Text: string);
78 procedure e_CharFont_PrintEx(FontID
: DWORD
; X
, Y
: Integer; Text: string;
79 Color
: TRGB
; Scale
: Single = 1.0);
80 procedure e_CharFont_PrintFmt(FontID
: DWORD
; X
, Y
: Integer; Text: string);
81 procedure e_CharFont_GetSize(FontID
: DWORD
; Text: string; var w
, h
: Word);
82 procedure e_CharFont_GetSizeFmt(FontID
: DWORD
; Text: string; var w
, h
: Word);
83 function e_CharFont_GetMaxWidth(FontID
: DWORD
): Word;
84 function e_CharFont_GetMaxHeight(FontID
: DWORD
): Word;
85 procedure e_CharFont_Remove(FontID
: DWORD
);
86 procedure e_CharFont_RemoveAll();
89 procedure e_TextureFontBuild(Tex
: DWORD
; var FontID
: DWORD
; XCount
, YCount
: Word;
91 procedure e_TextureFontKill(FontID
: DWORD
);
92 procedure e_TextureFontPrint(X
, Y
: GLint
; Text: string; FontID
: DWORD
);
93 procedure e_TextureFontPrintEx(X
, Y
: GLint
; Text: string; FontID
: DWORD
; Red
, Green
,
94 Blue
: Byte; Scale
: Single; Shadow
: Boolean = False);
95 procedure e_TextureFontPrintFmt(X
, Y
: GLint
; Text: string; FontID
: DWORD
; Shadow
: Boolean = False);
96 procedure e_TextureFontGetSize(ID
: DWORD
; var CharWidth
, CharHeight
: Byte);
97 procedure e_RemoveAllTextureFont();
99 procedure e_ReleaseEngine();
100 procedure e_BeginRender();
101 procedure e_Clear(Mask
: TGLbitfield
; Red
, Green
, Blue
: Single); overload
;
102 procedure e_Clear(); overload
;
103 procedure e_EndRender();
105 procedure e_SaveGLContext();
106 procedure e_RestoreGLContext();
108 function e_GetGamma(win
: PSDL_Window
): Byte;
109 procedure e_SetGamma(win
: PSDL_Window
;Gamma
: Byte);
111 procedure e_MakeScreenshot(FileName
: string; Width
, Height
: Word);
113 function _RGB(Red
, Green
, Blue
: Byte): TRGB
;
114 function _Point(X
, Y
: Integer): TPoint2i
;
115 function _Rect(X
, Y
: Integer; Width
, Height
: Word): TRectWH
;
116 function _TRect(L
, T
, R
, B
: LongInt): TRect
;
133 TTextureFont
= record
143 Chars
: array[0..255] of
153 TSavedTexture
= record
160 e_Textures
: array of TTexture
= nil;
161 e_TextureFonts
: array of TTextureFont
= nil;
162 e_CharFonts
: array of TCharFont
;
163 e_SavedTextures
: array of TSavedTexture
;
165 //------------------------------------------------------------------
166 // Èíèöèàëèçèðóåò OpenGL
167 //------------------------------------------------------------------
168 procedure e_InitGL();
170 glDisable(GL_DEPTH_TEST
);
171 glEnable(GL_SCISSOR_TEST
);
175 glClearColor(0, 0, 0, 0);
178 procedure e_SetViewPort(X
, Y
, Width
, Height
: Word);
180 mat
: Array [0..15] of GLDouble
;
184 glScissor(X
, Y
, Width
, Height
);
185 glViewport(X
, Y
, Width
, Height
);
186 //gluOrtho2D(0, Width, Height, 0);
188 glMatrixMode(GL_PROJECTION
);
190 mat
[ 0] := 2.0 / Width
;
196 mat
[ 5] := -2.0 / Height
;
210 glLoadMatrixd(@mat
[0]);
212 glMatrixMode(GL_MODELVIEW
);
216 //------------------------------------------------------------------
217 // Èùåò ñâîáîäíûé ýëåìåíò â ìàññèâå òåêñòóð
218 //------------------------------------------------------------------
219 function FindTexture(): DWORD
;
223 if e_Textures
<> nil then
224 for i
:= 0 to High(e_Textures
) do
225 if e_Textures
[i
].Width
= 0 then
231 if e_Textures
= nil then
233 SetLength(e_Textures
, 32);
238 Result
:= High(e_Textures
) + 1;
239 SetLength(e_Textures
, Length(e_Textures
) + 32);
243 //------------------------------------------------------------------
245 //------------------------------------------------------------------
246 function e_CreateTexture(FileName
: String; var ID
: DWORD
): Boolean;
253 e_WriteLog('Loading texture from '+FileName
, MSG_NOTIFY
);
255 find_id
:= FindTexture();
257 if not LoadTexture(FileName
, e_Textures
[find_id
].tx
, e_Textures
[find_id
].Width
,
258 e_Textures
[find_id
].Height
, @fmt
) then Exit
;
261 e_Textures
[ID
].Fmt
:= fmt
;
266 function e_CreateTextureEx(FileName
: String; var ID
: DWORD
; fX
, fY
, fWidth
, fHeight
: Word): Boolean;
273 find_id
:= FindTexture();
275 if not LoadTextureEx(FileName
, e_Textures
[find_id
].tx
, fX
, fY
, fWidth
, fHeight
, @fmt
) then exit
;
277 e_Textures
[find_id
].Width
:= fWidth
;
278 e_Textures
[find_id
].Height
:= fHeight
;
279 e_Textures
[find_id
].Fmt
:= fmt
;
286 function e_CreateTextureMem(pData
: Pointer; var ID
: DWORD
): Boolean;
293 find_id
:= FindTexture
;
295 if not LoadTextureMem(pData
, e_Textures
[find_id
].tx
, e_Textures
[find_id
].Width
,
296 e_Textures
[find_id
].Height
, @fmt
) then exit
;
299 e_Textures
[id
].Fmt
:= fmt
;
304 function e_CreateTextureMemEx(pData
: Pointer; var ID
: DWORD
; fX
, fY
, fWidth
, fHeight
: Word): Boolean;
311 find_id
:= FindTexture();
313 if not LoadTextureMemEx(pData
, e_Textures
[find_id
].tx
, fX
, fY
, fWidth
, fHeight
, @fmt
) then exit
;
315 e_Textures
[find_id
].Width
:= fWidth
;
316 e_Textures
[find_id
].Height
:= fHeight
;
317 e_Textures
[find_id
].Fmt
:= fmt
;
324 procedure e_GetTextureSize(ID
: DWORD
; Width
, Height
: PWord);
326 if Width
<> nil then Width
^ := e_Textures
[ID
].Width
;
327 if Height
<> nil then Height
^ := e_Textures
[ID
].Height
;
330 function e_GetTextureSize2(ID
: DWORD
): TRectWH
;
338 w
:= e_Textures
[ID
].Width
;
339 h
:= e_Textures
[ID
].Height
;
340 data
:= GetMemory(w
*h
*4);
341 glEnable(GL_TEXTURE_2D
);
342 glBindTexture(GL_TEXTURE_2D
, e_Textures
[ID
].tx
.id
);
343 glGetTexImage(GL_TEXTURE_2D
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
350 for y
:= h
-1 downto 0 do
357 a
:= Byte((data
+y
*w
*4+x
*4+3)^) <> 0;
363 Result
.Y
:= h
-lastline
;
375 a
:= Byte((data
+y
*w
*4+x
*4+3)^) <> 0;
381 Result
.Height
:= h
-lastline
-Result
.Y
;
393 a
:= Byte((data
+y
*w
*4+x
*4+3)^) <> 0;
399 Result
.X
:= lastline
+1;
404 for x
:= w
-1 downto 0 do
411 a
:= Byte((data
+y
*w
*4+x
*4+3)^) <> 0;
417 Result
.Width
:= lastline
-Result
.X
+1;
425 procedure e_ResizeWindow(Width
, Height
: Integer);
429 e_SetViewPort(0, 0, Width
, Height
);
432 procedure e_Draw(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
433 Blending
: Boolean; Mirror
: TMirrorType
= M_NONE
);
437 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
439 if (Alpha
> 0) or (AlphaChannel
) or (Blending
) then
444 if (AlphaChannel
) or (Alpha
> 0) then
445 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
448 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255-Alpha
);
451 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
453 glEnable(GL_TEXTURE_2D
);
454 glBindTexture(GL_TEXTURE_2D
, e_Textures
[ID
].tx
.id
);
457 u
:= e_Textures
[ID
].tx
.u
;
458 v
:= e_Textures
[ID
].tx
.v
;
460 if Mirror
= M_NONE
then
462 glTexCoord2f(u
, 0); glVertex2i(X
+ e_Textures
[id
].Width
, Y
);
463 glTexCoord2f(0, 0); glVertex2i(X
, Y
);
464 glTexCoord2f(0, -v
); glVertex2i(X
, Y
+ e_Textures
[id
].Height
);
465 glTexCoord2f(u
, -v
); glVertex2i(X
+ e_Textures
[id
].Width
, Y
+ e_Textures
[id
].Height
);
468 if Mirror
= M_HORIZONTAL
then
470 glTexCoord2f(u
, 0); glVertex2i(X
, Y
);
471 glTexCoord2f(0, 0); glVertex2i(X
+ e_Textures
[id
].Width
, Y
);
472 glTexCoord2f(0, -v
); glVertex2i(X
+ e_Textures
[id
].Width
, Y
+ e_Textures
[id
].Height
);
473 glTexCoord2f(u
, -v
); glVertex2i(X
, Y
+ e_Textures
[id
].Height
);
476 if Mirror
= M_VERTICAL
then
478 glTexCoord2f(u
, -v
); glVertex2i(X
+ e_Textures
[id
].Width
, Y
);
479 glTexCoord2f(0, -v
); glVertex2i(X
, Y
);
480 glTexCoord2f(0, 0); glVertex2i(X
, Y
+ e_Textures
[id
].Height
);
481 glTexCoord2f(u
, 0); glVertex2i(X
+ e_Textures
[id
].Width
, Y
+ e_Textures
[id
].Height
);
489 procedure e_DrawSize(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
490 Blending
: Boolean; Width
, Height
: Word; Mirror
: TMirrorType
= M_NONE
);
494 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
496 if (Alpha
> 0) or (AlphaChannel
) or (Blending
) then
501 if (AlphaChannel
) or (Alpha
> 0) then
502 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
505 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255-Alpha
);
508 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
510 glEnable(GL_TEXTURE_2D
);
511 glBindTexture(GL_TEXTURE_2D
, e_Textures
[ID
].tx
.id
);
513 u
:= e_Textures
[ID
].tx
.u
;
514 v
:= e_Textures
[ID
].tx
.v
;
517 glTexCoord2f(0, v
); glVertex2i(X
, Y
);
518 glTexCoord2f(u
, v
); glVertex2i(X
+ Width
, Y
);
519 glTexCoord2f(u
, 0); glVertex2i(X
+ Width
, Y
+ Height
);
520 glTexCoord2f(0, 0); glVertex2i(X
, Y
+ Height
);
526 procedure e_DrawSizeMirror(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
527 Blending
: Boolean; Width
, Height
: Word; Mirror
: TMirrorType
= M_NONE
);
531 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
533 if (Alpha
> 0) or (AlphaChannel
) or (Blending
) then
538 if (AlphaChannel
) or (Alpha
> 0) then
539 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
542 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255-Alpha
);
545 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
547 glEnable(GL_TEXTURE_2D
);
548 glBindTexture(GL_TEXTURE_2D
, e_Textures
[ID
].tx
.id
);
551 u
:= e_Textures
[ID
].tx
.u
;
552 v
:= e_Textures
[ID
].tx
.v
;
554 if Mirror
= M_NONE
then
556 glTexCoord2f(u
, 0); glVertex2i(X
+ Width
, Y
);
557 glTexCoord2f(0, 0); glVertex2i(X
, Y
);
558 glTexCoord2f(0, -v
); glVertex2i(X
, Y
+ Height
);
559 glTexCoord2f(u
, -v
); glVertex2i(X
+ Width
, Y
+ Height
);
562 if Mirror
= M_HORIZONTAL
then
564 glTexCoord2f(u
, 0); glVertex2i(X
, Y
);
565 glTexCoord2f(0, 0); glVertex2i(X
+ Width
, Y
);
566 glTexCoord2f(0, -v
); glVertex2i(X
+ Width
, Y
+ Height
);
567 glTexCoord2f(u
, -v
); glVertex2i(X
, Y
+ Height
);
570 if Mirror
= M_VERTICAL
then
572 glTexCoord2f(u
, -v
); glVertex2i(X
+ Width
, Y
);
573 glTexCoord2f(0, -v
); glVertex2i(X
, Y
);
574 glTexCoord2f(0, 0); glVertex2i(X
, Y
+ Height
);
575 glTexCoord2f(u
, 0); glVertex2i(X
+ Width
, Y
+ Height
);
583 procedure e_DrawFill(ID
: DWORD
; X
, Y
: Integer; XCount
, YCount
: Word; Alpha
: Integer;
584 AlphaChannel
: Boolean; Blending
: Boolean);
586 X2
, Y2
, dx
, w
, h
: Integer;
589 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
591 if (Alpha
> 0) or (AlphaChannel
) or (Blending
) then
596 if (AlphaChannel
) or (Alpha
> 0) then
597 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
600 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255-Alpha
);
603 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
611 glEnable(GL_TEXTURE_2D
);
612 glBindTexture(GL_TEXTURE_2D
, e_Textures
[ID
].tx
.id
);
614 X2
:= X
+ e_Textures
[ID
].Width
* XCount
;
615 Y2
:= Y
+ e_Textures
[ID
].Height
* YCount
;
617 //k8: this SHOULD work... i hope
618 if (e_Textures
[ID
].tx
.width
= e_Textures
[ID
].tx
.glwidth
) and (e_Textures
[ID
].tx
.height
= e_Textures
[ID
].tx
.glheight
) then
621 glTexCoord2i(0, YCount
); glVertex2i(X
, Y
);
622 glTexCoord2i(XCount
, YCount
); glVertex2i(X2
, Y
);
623 glTexCoord2i(XCount
, 0); glVertex2i(X2
, Y2
);
624 glTexCoord2i(0, 0); glVertex2i(X
, Y2
);
631 u
:= e_Textures
[ID
].tx
.u
;
632 v
:= e_Textures
[ID
].tx
.v
;
633 w
:= e_Textures
[ID
].tx
.width
;
634 h
:= e_Textures
[ID
].tx
.height
;
641 glTexCoord2f(0, v
); glVertex2i(X
, Y
);
642 glTexCoord2f(u
, v
); glVertex2i(X
+w
, Y
);
643 glTexCoord2f(u
, 0); glVertex2i(X
+w
, Y
+h
);
644 glTexCoord2f(0, 0); glVertex2i(X
, Y
+h
);
658 procedure e_DrawAdv(ID
: DWORD
; X
, Y
: Integer; Alpha
: Byte; AlphaChannel
: Boolean;
659 Blending
: Boolean; Angle
: Single; RC
: PPoint
; Mirror
: TMirrorType
= M_NONE
);
663 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
665 if (Alpha
> 0) or (AlphaChannel
) or (Blending
) then
670 if (AlphaChannel
) or (Alpha
> 0) then
671 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
674 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255-Alpha
);
677 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
679 if (Angle
<> 0) and (RC
<> nil) then
682 glTranslatef(X
+RC
.X
, Y
+RC
.Y
, 0);
683 glRotatef(Angle
, 0, 0, 1);
684 glTranslatef(-(X
+RC
.X
), -(Y
+RC
.Y
), 0);
687 glEnable(GL_TEXTURE_2D
);
688 glBindTexture(GL_TEXTURE_2D
, e_Textures
[id
].tx
.id
);
689 glBegin(GL_QUADS
); //0-1 1-1
692 u
:= e_Textures
[ID
].tx
.u
;
693 v
:= e_Textures
[ID
].tx
.v
;
695 if Mirror
= M_NONE
then
697 glTexCoord2f(u
, 0); glVertex2i(X
+ e_Textures
[id
].Width
, Y
);
698 glTexCoord2f(0, 0); glVertex2i(X
, Y
);
699 glTexCoord2f(0, -v
); glVertex2i(X
, Y
+ e_Textures
[id
].Height
);
700 glTexCoord2f(u
, -v
); glVertex2i(X
+ e_Textures
[id
].Width
, Y
+ e_Textures
[id
].Height
);
703 if Mirror
= M_HORIZONTAL
then
705 glTexCoord2f(u
, 0); glVertex2i(X
, Y
);
706 glTexCoord2f(0, 0); glVertex2i(X
+ e_Textures
[id
].Width
, Y
);
707 glTexCoord2f(0, -v
); glVertex2i(X
+ e_Textures
[id
].Width
, Y
+ e_Textures
[id
].Height
);
708 glTexCoord2f(u
, -v
); glVertex2i(X
, Y
+ e_Textures
[id
].Height
);
711 if Mirror
= M_VERTICAL
then
713 glTexCoord2f(u
, -v
); glVertex2i(X
+ e_Textures
[id
].Width
, Y
);
714 glTexCoord2f(0, -v
); glVertex2i(X
, Y
);
715 glTexCoord2f(0, 0); glVertex2i(X
, Y
+ e_Textures
[id
].Height
);
716 glTexCoord2f(u
, 0); glVertex2i(X
+ e_Textures
[id
].Width
, Y
+ e_Textures
[id
].Height
);
727 procedure e_DrawPoint(Size
: Byte; X
, Y
: Integer; Red
, Green
, Blue
: Byte);
729 glDisable(GL_TEXTURE_2D
);
730 glColor3ub(Red
, Green
, Blue
);
733 if (Size
= 2) or (Size
= 4) then
737 glVertex2f(X
+0.3, Y
+1.0);
740 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
743 procedure e_LineCorrection(var X1
, Y1
, X2
, Y2
: Integer);
745 // Make lines only top-left/bottom-right and top-right/bottom-left
757 // Pixel-perfect hack
765 procedure e_DrawQuad(X1
, Y1
, X2
, Y2
: Integer; Red
, Green
, Blue
: Byte; Alpha
: Byte = 0);
767 nX1
, nY1
, nX2
, nY2
: Integer;
769 // Only top-left/bottom-right quad
786 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
790 glDisable(GL_TEXTURE_2D
);
791 glColor4ub(Red
, Green
, Blue
, 255-Alpha
);
795 nX1
:= X1
; nY1
:= Y1
;
796 nX2
:= X2
; nY2
:= Y1
;
797 e_LineCorrection(nX1
, nY1
, nX2
, nY2
); // Pixel-perfect lines
798 glVertex2i(nX1
, nY1
);
799 glVertex2i(nX2
, nY2
);
801 nX1
:= X2
; nY1
:= Y1
;
802 nX2
:= X2
; nY2
:= Y2
;
803 e_LineCorrection(nX1
, nY1
, nX2
, nY2
);
804 glVertex2i(nX1
, nY1
);
805 glVertex2i(nX2
, nY2
);
807 nX1
:= X2
; nY1
:= Y2
;
808 nX2
:= X1
; nY2
:= Y2
;
809 e_LineCorrection(nX1
, nY1
, nX2
, nY2
);
810 glVertex2i(nX1
, nY1
);
811 glVertex2i(nX2
, nY2
);
813 nX1
:= X1
; nY1
:= Y2
;
814 nX2
:= X1
; nY2
:= Y1
;
815 e_LineCorrection(nX1
, nY1
, nX2
, nY2
);
816 glVertex2i(nX1
, nY1
);
817 glVertex2i(nX2
, nY2
);
820 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
825 procedure e_DrawFillQuad(X1
, Y1
, X2
, Y2
: Integer; Red
, Green
, Blue
, Alpha
: Byte;
826 Blending
: TBlending
= B_NONE
);
828 if (Alpha
> 0) or (Blending
<> B_NONE
) then
833 if Blending
= B_BLEND
then
834 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
)
836 if Blending
= B_FILTER
then
837 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
)
839 if Blending
= B_INVERT
then
840 glBlendFunc(GL_ONE_MINUS_DST_COLOR
, GL_ZERO
)
843 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
845 glDisable(GL_TEXTURE_2D
);
846 glColor4ub(Red
, Green
, Blue
, 255-Alpha
);
858 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
863 procedure e_DrawLine(Width
: Byte; X1
, Y1
, X2
, Y2
: Integer; Red
, Green
, Blue
: Byte; Alpha
: Byte = 0);
865 // Pixel-perfect lines
867 e_LineCorrection(X1
, Y1
, X2
, Y2
);
872 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
876 glDisable(GL_TEXTURE_2D
);
877 glColor4ub(Red
, Green
, Blue
, 255-Alpha
);
885 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
890 //------------------------------------------------------------------
891 // Óäàëÿåò òåêñòóðó èç ìàññèâà
892 //------------------------------------------------------------------
893 procedure e_DeleteTexture(ID
: DWORD
);
895 glDeleteTextures(1, @e_Textures
[ID
].tx
.id
);
896 e_Textures
[ID
].tx
.id
:= 0;
897 e_Textures
[ID
].Width
:= 0;
898 e_Textures
[ID
].Height
:= 0;
901 //------------------------------------------------------------------
902 // Óäàëÿåò âñå òåêñòóðû
903 //------------------------------------------------------------------
904 procedure e_RemoveAllTextures();
908 if e_Textures
= nil then Exit
;
910 for i
:= 0 to High(e_Textures
) do
911 if e_Textures
[i
].Width
<> 0 then e_DeleteTexture(i
);
915 //------------------------------------------------------------------
917 //------------------------------------------------------------------
918 procedure e_ReleaseEngine();
921 e_RemoveAllTextureFont
;
924 procedure e_BeginRender();
926 glEnable(GL_ALPHA_TEST
);
927 glAlphaFunc(GL_GREATER
, 0.0);
930 procedure e_Clear(Mask
: TGLbitfield
; Red
, Green
, Blue
: Single); overload
;
932 glClearColor(Red
, Green
, Blue
, 0);
936 procedure e_Clear(); overload
;
938 glClearColor(0, 0, 0, 0);
939 glClear(GL_COLOR_BUFFER_BIT
);
942 procedure e_EndRender();
947 procedure e_MakeScreenshot(FileName
: String; Width
, Height
: Word);
952 aRGB = Array [0..1] of TRGB;
955 TByteArray = Array [0..1] of Byte;
956 PByteArray = ^TByteArray;
959 FILEHEADER: BITMAPFILEHEADER;
960 INFOHEADER: BITMAPINFOHEADER;
967 if (Width mod 4) > 0 then
968 Width := Width + 4 - (Width mod 4);
970 GetMem(pixels, Width*Height*3);
971 glReadPixels(0, 0, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
973 for i := 0 to Width * Height - 1 do
974 with PaRGB(pixels)[i] do
983 bfType := $4D42; // "BM"
984 bfSize := Width*Height*3 + SizeOf(BITMAPFILEHEADER) + SizeOf(BITMAPINFOHEADER);
987 bfOffBits := SizeOf(BITMAPFILEHEADER) + SizeOf(BITMAPINFOHEADER);
992 biSize := SizeOf(BITMAPINFOHEADER);
998 biSizeImage := Width*Height*3;
999 biXPelsPerMeter := 0;
1000 biYPelsPerMeter := 0;
1002 biClrImportant := 0;
1005 AssignFile(F, FileName);
1008 BlockWrite(F, FILEHEADER, SizeOf(FILEHEADER));
1009 BlockWrite(F, INFOHEADER, SizeOf(INFOHEADER));
1010 BlockWrite(F, pixels[0], Width*Height*3);
1017 function e_GetGamma(win
: PSDL_Window
): Byte;
1019 ramp
: array [0..256*3-1] of Word;
1020 rgb
: array [0..2] of Double;
1032 SDL_GetWindowGammaRamp(win
, @ramp
[0], @ramp
[256], @ramp
[512]);
1041 for j
:= min
to max
- 1 do
1044 B
:= (j
mod 256)/256;
1046 sum
:= sum
+ ln(A
)/ln(B
);
1049 rgb
[i
] := sum
/ count
;
1052 Result
:= 100 - Trunc(((rgb
[0] + rgb
[1] + rgb
[2])/3 - 0.23) * 100/(2.7 - 0.23));
1055 procedure e_SetGamma(win
: PSDL_Window
; Gamma
: Byte);
1057 ramp
: array [0..256*3-1] of Word;
1062 g
:= (100 - Gamma
)*(2.7 - 0.23)/100 + 0.23;
1064 for i
:= 0 to 255 do
1066 r
:= Exp(g
* ln(i
/256))*65536;
1067 if r
< 0 then r
:= 0
1068 else if r
> 65535 then r
:= 65535;
1069 ramp
[i
] := trunc(r
);
1070 ramp
[i
+ 256] := trunc(r
);
1071 ramp
[i
+ 512] := trunc(r
);
1074 SDL_SetWindowGammaRamp(win
, @ramp
[0], @ramp
[256], @ramp
[512]);
1077 function e_CharFont_Create(sp
: ShortInt=0): DWORD
;
1081 e_WriteLog('Creating CharFont...', MSG_NOTIFY
);
1085 if e_CharFonts
<> nil then
1086 for i
:= 0 to High(e_CharFonts
) do
1087 if not e_CharFonts
[i
].Live
then
1093 if id
= DWORD(-1) then
1095 SetLength(e_CharFonts
, Length(e_CharFonts
) + 1);
1096 id
:= High(e_CharFonts
);
1099 with e_CharFonts
[id
] do
1101 for i
:= 0 to High(Chars
) do
1115 procedure e_CharFont_AddChar(FontID
: DWORD
; Texture
: Integer; c
: Char; w
: Byte);
1117 with e_CharFonts
[FontID
].Chars
[Ord(c
)] do
1119 TextureID
:= Texture
;
1124 procedure e_CharFont_Print(FontID
: DWORD
; X
, Y
: Integer; Text: string);
1128 if Text = '' then Exit
;
1129 if e_CharFonts
= nil then Exit
;
1130 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1132 with e_CharFonts
[FontID
] do
1134 for a
:= 1 to Length(Text) do
1135 with Chars
[Ord(Text[a
])] do
1136 if TextureID
<> -1 then
1138 e_Draw(TextureID
, X
, Y
, 0, True, False);
1139 X
:= X
+Width
+IfThen(a
= Length(Text), 0, Space
);
1144 procedure e_CharFont_PrintEx(FontID
: DWORD
; X
, Y
: Integer; Text: string;
1145 Color
: TRGB
; Scale
: Single = 1.0);
1150 if Text = '' then Exit
;
1151 if e_CharFonts
= nil then Exit
;
1152 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1154 with e_CharFonts
[FontID
] do
1156 for a
:= 1 to Length(Text) do
1157 with Chars
[Ord(Text[a
])] do
1158 if TextureID
<> -1 then
1160 if Scale
<> 1.0 then
1163 glScalef(Scale
, Scale
, 0);
1168 e_Draw(TextureID
, X
, Y
, 0, True, False);
1171 if Scale
<> 1.0 then glPopMatrix
;
1173 X
:= X
+Width
+IfThen(a
= Length(Text), 0, Space
);
1178 procedure e_CharFont_PrintFmt(FontID
: DWORD
; X
, Y
: Integer; Text: string);
1180 a
, TX
, TY
, len
: Integer;
1184 if Text = '' then Exit
;
1185 if e_CharFonts
= nil then Exit
;
1186 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1194 len
:= Length(Text);
1196 e_CharFont_GetSize(FontID
, 'A', w
, h
);
1198 with e_CharFonts
[FontID
] do
1200 for a
:= 1 to len
do
1211 c
.R
:= 0; c
.G
:= 0; c
.B
:= 0;
1216 c
.R
:= 255; c
.G
:= 255; c
.B
:= 255;
1221 c
.R
:= c
.R
div 2; c
.G
:= c
.G
div 2; c
.B
:= c
.B
div 2;
1226 c
.R
:= Min(c
.R
* 2, 255); c
.G
:= Min(c
.G
* 2, 255); c
.B
:= Min(c
.B
* 2, 255);
1231 c
.R
:= 255; c
.G
:= 0; c
.B
:= 0;
1236 c
.R
:= 0; c
.G
:= 255; c
.B
:= 0;
1241 c
.R
:= 0; c
.G
:= 0; c
.B
:= 255;
1246 c
.R
:= 255; c
.G
:= 255; c
.B
:= 0;
1251 with Chars
[Ord(Text[a
])] do
1252 if TextureID
<> -1 then
1256 e_Draw(TextureID
, TX
, TY
, 0, True, False);
1259 TX
:= TX
+Width
+IfThen(a
= Length(Text), 0, Space
);
1265 procedure e_CharFont_GetSize(FontID
: DWORD
; Text: string; var w
, h
: Word);
1273 if Text = '' then Exit
;
1274 if e_CharFonts
= nil then Exit
;
1275 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1277 with e_CharFonts
[FontID
] do
1279 for a
:= 1 to Length(Text) do
1280 with Chars
[Ord(Text[a
])] do
1281 if TextureID
<> -1 then
1283 w
:= w
+Width
+IfThen(a
= Length(Text), 0, Space
);
1284 e_GetTextureSize(TextureID
, nil, @h2
);
1285 if h2
> h
then h
:= h2
;
1290 procedure e_CharFont_GetSizeFmt(FontID
: DWORD
; Text: string; var w
, h
: Word);
1292 a
, lines
, len
: Integer;
1299 if Text = '' then Exit
;
1300 if e_CharFonts
= nil then Exit
;
1301 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1304 len
:= Length(Text);
1306 with e_CharFonts
[FontID
] do
1308 for a
:= 1 to len
do
1310 if Text[a
] = #10 then
1320 else if Text[a
] in [#1, #2, #3, #4, #18, #19, #20, #21] then
1323 with Chars
[Ord(Text[a
])] do
1324 if TextureID
<> -1 then
1326 w2
:= w2
+ Width
+ IfThen(a
= len
, 0, Space
);
1327 e_GetTextureSize(TextureID
, nil, @h2
);
1328 if h2
> h
then h
:= h2
;
1338 function e_CharFont_GetMaxWidth(FontID
: DWORD
): Word;
1344 if e_CharFonts
= nil then Exit
;
1345 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1347 for a
:= 0 to High(e_CharFonts
[FontID
].Chars
) do
1348 Result
:= Max(Result
, e_CharFonts
[FontID
].Chars
[a
].Width
);
1351 function e_CharFont_GetMaxHeight(FontID
: DWORD
): Word;
1358 if e_CharFonts
= nil then Exit
;
1359 if Integer(FontID
) > High(e_CharFonts
) then Exit
;
1361 for a
:= 0 to High(e_CharFonts
[FontID
].Chars
) do
1363 if e_CharFonts
[FontID
].Chars
[a
].TextureID
<> -1 then
1364 e_GetTextureSize(e_CharFonts
[FontID
].Chars
[a
].TextureID
, nil, @h2
)
1366 if h2
> Result
then Result
:= h2
;
1370 procedure e_CharFont_Remove(FontID
: DWORD
);
1374 with e_CharFonts
[FontID
] do
1375 for a
:= 0 to High(Chars
) do
1376 if Chars
[a
].TextureID
<> -1 then e_DeleteTexture(Chars
[a
].TextureID
);
1378 e_CharFonts
[FontID
].Live
:= False;
1381 procedure e_CharFont_RemoveAll();
1385 if e_CharFonts
= nil then Exit
;
1387 for a
:= 0 to High(e_CharFonts
) do
1388 e_CharFont_Remove(a
);
1393 procedure e_TextureFontBuild(Tex
: DWORD
; var FontID
: DWORD
; XCount
, YCount
: Word;
1400 e_WriteLog('Creating texture font...', MSG_NOTIFY
);
1404 if e_TextureFonts
<> nil then
1405 for i
:= 0 to High(e_TextureFonts
) do
1406 if e_TextureFonts
[i
].Base
= 0 then
1412 if id
= DWORD(-1) then
1414 SetLength(e_TextureFonts
, Length(e_TextureFonts
) + 1);
1415 id
:= High(e_TextureFonts
);
1418 with e_TextureFonts
[id
] do
1420 Base
:= glGenLists(XCount
*YCount
);
1421 TextureID
:= e_Textures
[Tex
].tx
.id
;
1422 CharWidth
:= (e_Textures
[Tex
].Width
div XCount
)+Space
;
1423 CharHeight
:= e_Textures
[Tex
].Height
div YCount
;
1430 glBindTexture(GL_TEXTURE_2D
, e_Textures
[Tex
].tx
.id
);
1431 for loop1
:= 0 to XCount
*YCount
-1 do
1433 cx
:= (loop1
mod XCount
)/XCount
;
1434 cy
:= (loop1
div YCount
)/YCount
;
1436 glNewList(e_TextureFonts
[id
].Base
+loop1
, GL_COMPILE
);
1438 glTexCoord2f(cx
, 1.0-cy
-1/YCount
);
1439 glVertex2d(0, e_Textures
[Tex
].Height
div YCount
);
1441 glTexCoord2f(cx
+1/XCount
, 1.0-cy
-1/YCount
);
1442 glVertex2i(e_Textures
[Tex
].Width
div XCount
, e_Textures
[Tex
].Height
div YCount
);
1444 glTexCoord2f(cx
+1/XCount
, 1.0-cy
);
1445 glVertex2i(e_Textures
[Tex
].Width
div XCount
, 0);
1447 glTexCoord2f(cx
, 1.0-cy
);
1450 glTranslated((e_Textures
[Tex
].Width
div XCount
)+Space
, 0, 0);
1457 procedure e_TextureFontBuildInPlace(id
: DWORD
);
1461 XCount
, YCount
, Space
: Integer;
1464 with e_TextureFonts
[id
] do
1466 Base
:= glGenLists(XC
*YC
);
1467 TextureID
:= e_Textures
[Texture
].tx
.id
;
1474 glBindTexture(GL_TEXTURE_2D
, e_Textures
[Tex
].tx
.id
);
1475 for loop1
:= 0 to XCount
*YCount
-1 do
1477 cx
:= (loop1
mod XCount
)/XCount
;
1478 cy
:= (loop1
div YCount
)/YCount
;
1480 glNewList(e_TextureFonts
[id
].Base
+loop1
, GL_COMPILE
);
1482 glTexCoord2f(cx
, 1.0-cy
-1/YCount
);
1483 glVertex2d(0, e_Textures
[Tex
].Height
div YCount
);
1485 glTexCoord2f(cx
+1/XCount
, 1.0-cy
-1/YCount
);
1486 glVertex2i(e_Textures
[Tex
].Width
div XCount
, e_Textures
[Tex
].Height
div YCount
);
1488 glTexCoord2f(cx
+1/XCount
, 1.0-cy
);
1489 glVertex2i(e_Textures
[Tex
].Width
div XCount
, 0);
1491 glTexCoord2f(cx
, 1.0-cy
);
1494 glTranslated((e_Textures
[Tex
].Width
div XCount
)+Space
, 0, 0);
1499 procedure e_TextureFontKill(FontID
: DWORD
);
1501 glDeleteLists(e_TextureFonts
[FontID
].Base
, 256);
1502 e_TextureFonts
[FontID
].Base
:= 0;
1505 procedure e_TextureFontPrint(X
, Y
: GLint
; Text: string; FontID
: DWORD
);
1507 if Integer(FontID
) > High(e_TextureFonts
) then Exit
;
1508 if Text = '' then Exit
;
1510 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1513 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
1516 glBindTexture(GL_TEXTURE_2D
, e_TextureFonts
[FontID
].TextureID
);
1517 glEnable(GL_TEXTURE_2D
);
1518 glTranslated(x
, y
, 0);
1519 glListBase(DWORD(Integer(e_TextureFonts
[FontID
].Base
)-32));
1520 glCallLists(Length(Text), GL_UNSIGNED_BYTE
, PChar(Text));
1521 glDisable(GL_TEXTURE_2D
);
1524 glDisable(GL_BLEND
);
1527 // god forgive me for this, but i cannot figure out how to do it without lists
1528 procedure e_TextureFontPrintChar(X
, Y
: Integer; Ch
: Char; FontID
: DWORD
; Shadow
: Boolean = False);
1534 glColor4ub(0, 0, 0, 128);
1535 glTranslated(X
+1, Y
+1, 0);
1536 glCallLists(1, GL_UNSIGNED_BYTE
, @Ch
);
1541 glColor4ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
, 255);
1542 glTranslated(X
, Y
, 0);
1543 glCallLists(1, GL_UNSIGNED_BYTE
, @Ch
);
1548 procedure e_TextureFontPrintFmt(X
, Y
: Integer; Text: string; FontID
: DWORD
; Shadow
: Boolean = False);
1550 a
, TX
, TY
, len
: Integer;
1554 if Text = '' then Exit
;
1555 if e_TextureFonts
= nil then Exit
;
1556 if Integer(FontID
) > High(e_TextureFonts
) then Exit
;
1564 len
:= Length(Text);
1566 w
:= e_TextureFonts
[FontID
].CharWidth
;
1568 with e_TextureFonts
[FontID
] do
1570 glBindTexture(GL_TEXTURE_2D
, e_TextureFonts
[FontID
].TextureID
);
1571 glEnable(GL_TEXTURE_2D
);
1572 glListBase(DWORD(Integer(e_TextureFonts
[FontID
].Base
)-32));
1574 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1577 for a
:= 1 to len
do
1588 c
.R
:= 0; c
.G
:= 0; c
.B
:= 0;
1593 c
.R
:= 255; c
.G
:= 255; c
.B
:= 255;
1598 c
.R
:= c
.R
div 2; c
.G
:= c
.G
div 2; c
.B
:= c
.B
div 2;
1603 c
.R
:= Min(c
.R
* 2, 255); c
.G
:= Min(c
.G
* 2, 255); c
.B
:= Min(c
.B
* 2, 255);
1608 c
.R
:= 255; c
.G
:= 0; c
.B
:= 0;
1613 c
.R
:= 0; c
.G
:= 255; c
.B
:= 0;
1618 c
.R
:= 0; c
.G
:= 0; c
.B
:= 255;
1623 c
.R
:= 255; c
.G
:= 255; c
.B
:= 0;
1630 e_TextureFontPrintChar(TX
, TY
, Text[a
], FontID
, Shadow
);
1635 glDisable(GL_TEXTURE_2D
);
1636 glDisable(GL_BLEND
);
1640 procedure e_TextureFontPrintEx(X
, Y
: GLint
; Text: string; FontID
: DWORD
; Red
, Green
,
1641 Blue
: Byte; Scale
: Single; Shadow
: Boolean = False);
1643 if Text = '' then Exit
;
1646 glBindTexture(GL_TEXTURE_2D
, e_TextureFonts
[FontID
].TextureID
);
1647 glEnable(GL_TEXTURE_2D
);
1648 glListBase(DWORD(Integer(e_TextureFonts
[FontID
].Base
)-32));
1650 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1655 glColor4ub(0, 0, 0, 128);
1656 glTranslated(x
+1, y
+1, 0);
1657 glScalef(Scale
, Scale
, 0);
1658 glCallLists(Length(Text), GL_UNSIGNED_BYTE
, PChar(Text));
1663 glColor4ub(Red
, Green
, Blue
, 255);
1664 glTranslated(x
, y
, 0);
1665 glScalef(Scale
, Scale
, 0);
1666 glCallLists(Length(Text), GL_UNSIGNED_BYTE
, PChar(Text));
1668 glDisable(GL_TEXTURE_2D
);
1670 glColor3ub(e_Colors
.R
, e_Colors
.G
, e_Colors
.B
);
1671 glDisable(GL_BLEND
);
1674 procedure e_TextureFontGetSize(ID
: DWORD
; var CharWidth
, CharHeight
: Byte);
1676 if Integer(ID
) > High(e_TextureFonts
) then
1678 CharWidth
:= e_TextureFonts
[ID
].CharWidth
;
1679 CharHeight
:= e_TextureFonts
[ID
].CharHeight
;
1682 procedure e_RemoveAllTextureFont();
1686 if e_TextureFonts
= nil then Exit
;
1688 for i
:= 0 to High(e_TextureFonts
) do
1689 if e_TextureFonts
[i
].Base
<> 0 then
1691 glDeleteLists(e_TextureFonts
[i
].Base
, 256);
1692 e_TextureFonts
[i
].Base
:= 0;
1695 e_TextureFonts
:= nil;
1698 procedure e_SaveGLContext();
1703 e_WriteLog('Backing up GL context:', MSG_NOTIFY
);
1705 glPushAttrib(GL_ALL_ATTRIB_BITS
);
1706 glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS
);
1708 if e_Textures
<> nil then
1710 e_WriteLog(' Backing up textures...', MSG_NOTIFY
);
1711 SetLength(e_SavedTextures
, Length(e_Textures
));
1712 for i
:= Low(e_Textures
) to High(e_Textures
) do
1714 e_SavedTextures
[i
].Pixels
:= nil;
1715 if e_Textures
[i
].Width
> 0 then
1717 with e_SavedTextures
[i
] do
1720 if e_Textures
[i
].Fmt
= GL_RGBA
then Inc(PxLen
);
1721 Pixels
:= GetMem(PxLen
* e_Textures
[i
].Width
* e_Textures
[i
].Height
);
1722 glBindTexture(GL_TEXTURE_2D
, e_Textures
[i
].tx
.id
);
1723 glGetTexImage(GL_TEXTURE_2D
, 0, e_Textures
[i
].Fmt
, GL_UNSIGNED_BYTE
, Pixels
);
1724 glBindTexture(GL_TEXTURE_2D
, 0);
1725 OldID
:= e_Textures
[i
].tx
.id
;
1732 if e_TextureFonts
<> nil then
1734 e_WriteLog(' Releasing texturefonts...', MSG_NOTIFY
);
1735 for i
:= 0 to High(e_TextureFonts
) do
1736 if e_TextureFonts
[i
].Base
<> 0 then
1738 glDeleteLists(e_TextureFonts
[i
].Base
, 256);
1739 e_TextureFonts
[i
].Base
:= 0;
1744 procedure e_RestoreGLContext();
1749 e_WriteLog('Restoring GL context:', MSG_NOTIFY
);
1751 glPopClientAttrib();
1754 if e_SavedTextures
<> nil then
1756 e_WriteLog(' Regenerating textures...', MSG_NOTIFY
);
1757 for i
:= Low(e_SavedTextures
) to High(e_SavedTextures
) do
1759 if e_SavedTextures
[i
].Pixels
<> nil then
1760 with e_SavedTextures
[i
] do
1762 CreateTexture(e_Textures
[TexID
].tx
, e_Textures
[TexID
].Width
, e_Textures
[TexID
].Height
, e_Textures
[TexID
].Fmt
, Pixels
);
1763 //GLID := CreateTexture(e_Textures[TexID].Width, e_Textures[TexID].Height, e_Textures[TexID].Fmt, Pixels);
1764 //e_Textures[TexID].tx := GLID;
1770 if e_TextureFonts
<> nil then
1772 e_WriteLog(' Regenerating texturefonts...', MSG_NOTIFY
);
1773 for i
:= Low(e_TextureFonts
) to High(e_TextureFonts
) do
1774 with e_TextureFonts
[i
] do
1776 TextureID
:= e_Textures
[Texture
].tx
.id
;
1778 e_TextureFontBuildInPlace(i
);
1782 SetLength(e_SavedTextures
, 0);
1786 function _RGB(Red
, Green
, Blue
: Byte): TRGB
;
1793 function _Point(X
, Y
: Integer): TPoint2i
;
1799 function _Rect(X
, Y
: Integer; Width
, Height
: Word): TRectWH
;
1803 Result
.Width
:= Width
;
1804 Result
.Height
:= Height
;
1807 function _TRect(L
, T
, R
, B
: LongInt): TRect
;