Net: Don't send large unreliable packets by reliable fragments
[d2df-sdl.git] / src / flexui / fui_gfx_gl_cursor.inc
blob0c9b7a19c8a429c2d2d4c295507422b7a6454961
1 (* coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2  * Understanding is not required. Only obedience.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 3 of the License ONLY.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *)
16 // ////////////////////////////////////////////////////////////////////////// //
17 // cursor (hi, Death Track!)
18 const curTexWidth = 32;
19 const curTexHeight = 32;
20 const curWidth = 17;
21 const curHeight = 23;
23 const cursorImg: array[0..curWidth*curHeight-1] of Byte = (
24   2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
25   3,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
26   3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
27   3,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,
28   3,3,4,2,2,0,0,0,0,0,0,0,0,0,0,0,0,
29   3,3,4,4,2,2,0,0,0,0,0,0,0,0,0,0,0,
30   3,3,4,4,4,2,2,0,0,0,0,0,0,0,0,0,0,
31   3,3,4,4,4,4,2,2,0,0,0,0,0,0,0,0,0,
32   3,3,4,4,4,5,6,2,2,0,0,0,0,0,0,0,0,
33   3,3,4,4,5,6,7,5,2,2,0,0,0,0,0,0,0,
34   3,3,4,5,6,7,5,4,5,2,2,0,0,0,0,0,0,
35   3,3,5,6,7,5,4,5,6,7,2,2,0,0,0,0,0,
36   3,3,6,7,5,4,5,6,7,7,7,2,2,0,0,0,0,
37   3,3,7,5,4,5,6,7,7,7,7,7,2,2,0,0,0,
38   3,3,5,4,5,6,8,8,8,8,8,8,8,8,2,0,0,
39   3,3,4,5,6,3,8,8,8,8,8,8,8,8,8,0,0,
40   3,3,5,6,3,3,0,0,0,0,0,0,0,0,0,0,0,
41   3,3,6,3,3,0,0,0,0,0,0,0,0,0,0,0,0,
42   3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,
43   3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
44   3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
45   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
46   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
48 const cursorPal: array[0..9*4-1] of Byte = (
49     0,  0,  0,  0,
50     0,  0,  0, 92, // shadow
51    85,255,255,255,
52    85, 85,255,255,
53   255, 85, 85,255,
54   170,  0,170,255,
55    85, 85, 85,255,
56     0,  0,  0,255,
57     0,  0,170,255
61 var
62   curtexid: GLuint = 0;
65 procedure createCursorTexture ();
66 var
67   tex, tpp: PByte;
68   c: Integer;
69   x, y: Integer;
70 begin
71   if (curtexid <> 0) then exit; //begin glDeleteTextures(1, @curtexid); curtexid := 0; end;
73   GetMem(tex, curTexWidth*curTexHeight*4);
74   try
75     FillChar(tex^, curTexWidth*curTexHeight*4, 0);
77     // draw shadow
78     for y := 0 to curHeight-1 do
79     begin
80       for x := 0 to curWidth-1 do
81       begin
82         if (cursorImg[y*curWidth+x] <> 0) then
83         begin
84           c := 1*4;
85           tpp := tex+((y+1)*(curTexWidth*4)+(x+3)*4);
86           tpp^ := cursorPal[c+0]; Inc(tpp);
87           tpp^ := cursorPal[c+1]; Inc(tpp);
88           tpp^ := cursorPal[c+2]; Inc(tpp);
89           tpp^ := cursorPal[c+3]; Inc(tpp);
90           tpp^ := cursorPal[c+0]; Inc(tpp);
91           tpp^ := cursorPal[c+1]; Inc(tpp);
92           tpp^ := cursorPal[c+2]; Inc(tpp);
93           tpp^ := cursorPal[c+3]; Inc(tpp);
94         end;
95       end;
96     end;
98     // draw cursor
99     for y := 0 to curHeight-1 do
100     begin
101       for x := 0 to curWidth-1 do
102       begin
103         c := cursorImg[y*curWidth+x]*4;
104         if (c <> 0) then
105         begin
106           tpp := tex+(y*(curTexWidth*4)+x*4);
107           tpp^ := cursorPal[c+0]; Inc(tpp);
108           tpp^ := cursorPal[c+1]; Inc(tpp);
109           tpp^ := cursorPal[c+2]; Inc(tpp);
110           tpp^ := cursorPal[c+3]; Inc(tpp);
111         end;
112       end;
113     end;
115     glGenTextures(1, @curtexid);
116     if (curtexid = 0) then raise Exception.Create('can''t create cursor texture');
118     glBindTexture(GL_TEXTURE_2D, curtexid);
119     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
120     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
121     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
122     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
124     //GLfloat[4] bclr = 0.0;
125     //glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, bclr.ptr);
127     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, curTexWidth, curTexHeight, 0, GL_RGBA{gltt}, GL_UNSIGNED_BYTE, tex);
128     glFinish();
129   finally
130     FreeMem(tex);
131   end;
132 end;
135 procedure oglDrawCursorAt (msX, msY: Integer);
137   sst: TSavedGLState;
138 begin
139   //if (curtexid = 0) then createCursorTexture() else glBindTexture(GL_TEXTURE_2D, curtexid);
140   sst := TSavedGLState.Create(true);
141   try
142     oglSetup2D(fuiScrWdt, fuiScrHgt);
143     glBindTexture(GL_TEXTURE_2D, curtexid);
144     glEnable(GL_TEXTURE_2D);
145     // blend it
146     glEnable(GL_BLEND);
147     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
148     glDisable(GL_STENCIL_TEST);
149     glDisable(GL_SCISSOR_TEST);
150     glDisable(GL_LIGHTING);
151     glDisable(GL_DEPTH_TEST);
152     glDisable(GL_CULL_FACE);
153     // color and opacity
154     glColor4f(1, 1, 1, 1.0);
155     //Dec(msX, 2);
156     glBegin(GL_QUADS);
157       glTexCoord2f(0.0, 0.0); glVertex2i(msX, msY); // top-left
158       glTexCoord2f(1.0, 0.0); glVertex2i(msX+curTexWidth, msY); // top-right
159       glTexCoord2f(1.0, 1.0); glVertex2i(msX+curTexWidth, msY+curTexHeight); // bottom-right
160       glTexCoord2f(0.0, 1.0); glVertex2i(msX, msY+curTexHeight); // bottom-left
161     glEnd();
162     //Inc(msX, 2);
163     //glColor4f(1, 1, 1, 1);
164     //glDisable(GL_BLEND);
165     //glDisable(GL_TEXTURE_2D);
166     //glBindTexture(GL_TEXTURE_2D, 0);
167   finally
168     sst.restore();
169   end;
170 end;