DEADSOFTWARE

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