1 (* coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2 * Understanding is not required. Only obedience.
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.
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.
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/>.
16 // ////////////////////////////////////////////////////////////////////////// //
17 // cursor (hi, Death Track!)
18 const curTexWidth = 32;
19 const curTexHeight = 32;
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 = (
50 0, 0, 0, 92, // shadow
65 procedure createCursorTexture ();
71 if (curtexid <> 0) then exit; //begin glDeleteTextures(1, @curtexid); curtexid := 0; end;
73 GetMem(tex, curTexWidth*curTexHeight*4);
75 FillChar(tex^, curTexWidth*curTexHeight*4, 0);
78 for y := 0 to curHeight-1 do
80 for x := 0 to curWidth-1 do
82 if (cursorImg[y*curWidth+x] <> 0) then
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);
99 for y := 0 to curHeight-1 do
101 for x := 0 to curWidth-1 do
103 c := cursorImg[y*curWidth+x]*4;
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);
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);
135 procedure oglDrawCursorAt (msX, msY: Integer);
139 //if (curtexid = 0) then createCursorTexture() else glBindTexture(GL_TEXTURE_2D, curtexid);
140 sst := TSavedGLState.Create(true);
142 oglSetup2D(fuiScrWdt, fuiScrHgt);
143 glBindTexture(GL_TEXTURE_2D, curtexid);
144 glEnable(GL_TEXTURE_2D);
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);
154 glColor4f(1, 1, 1, 1.0);
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
163 //glColor4f(1, 1, 1, 1);
164 //glDisable(GL_BLEND);
165 //glDisable(GL_TEXTURE_2D);
166 //glBindTexture(GL_TEXTURE_2D, 0);