author | unC0Rr |
Thu, 18 Nov 2010 11:32:47 +0300 | |
changeset 4374 | bcefeeabaa33 |
parent 4371 | ae172b2b03ed |
child 4375 | ae5507ddb989 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2947 | 2 |
* Hedgewars, a free turn based strategy game |
3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
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, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
4 | 18 |
|
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uMisc; |
22 |
interface |
|
2630 | 23 |
|
4374 | 24 |
uses SDLh, uConsts, GLunit, uTypes; |
2697 | 25 |
|
3611 | 26 |
|
3169
c8c6ac44f51b
prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents:
3165
diff
changeset
|
27 |
procedure movecursor(dx, dy: LongInt); |
3929
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
28 |
(* |
4 | 29 |
procedure AdjustColor(var Color: Longword); |
208 | 30 |
procedure SetKB(n: Longword); |
3929
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
31 |
*) |
208 | 32 |
procedure SendKB; |
306 | 33 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
34 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2279
diff
changeset
|
35 |
function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture; |
759 | 36 |
procedure FreeTexture(tex: PTexture); |
2670 | 37 |
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
4374 | 38 |
procedure OutError(Msg: shortstring; isFatalError: boolean); |
39 |
procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline; |
|
40 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
2735 | 41 |
procedure MakeScreenshot(filename: shortstring); |
4 | 42 |
|
4359 | 43 |
procedure initModule; |
44 |
procedure freeModule; |
|
45 |
||
4 | 46 |
implementation |
4374 | 47 |
uses uConsole, uIO, typinfo, sysutils, uVariables, uUtils; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
48 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
49 |
var KBnum: Longword; |
4 | 50 |
|
3756 | 51 |
|
3169
c8c6ac44f51b
prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents:
3165
diff
changeset
|
52 |
procedure movecursor(dx, dy: LongInt); |
2428 | 53 |
var x, y: LongInt; |
54 |
begin |
|
55 |
if (dx = 0) and (dy = 0) then exit; |
|
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
56 |
|
2428 | 57 |
SDL_GetMouseState(@x, @y); |
58 |
Inc(x, dx); |
|
59 |
Inc(y, dy); |
|
60 |
SDL_WarpMouse(x, y); |
|
61 |
end; |
|
62 |
||
4 | 63 |
|
2905 | 64 |
procedure OutError(Msg: shortstring; isFatalError: boolean); |
4 | 65 |
begin |
3407 | 66 |
// obsolete? written in WriteLnToConsole() anyway |
67 |
// {$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
68 |
WriteLnToConsole(Msg); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
69 |
if isFatalError then |
3407 | 70 |
begin |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
71 |
SendIPC('E' + GetLastConsoleLine); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
72 |
SDL_Quit; |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
73 |
halt(1) |
3407 | 74 |
end |
4 | 75 |
end; |
76 |
||
2905 | 77 |
procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); |
4 | 78 |
begin |
70 | 79 |
if not Assert then OutError(Msg, isFatal) |
4 | 80 |
end; |
81 |
||
82 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
83 |
begin |
|
84 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
85 |
end; |
|
86 |
||
3929
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
87 |
(* |
188 | 88 |
procedure AdjustColor(var Color: Longword); |
4 | 89 |
begin |
90 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
91 |
end; |
|
92 |
||
3929
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
93 |
procedure SetKB(n: Longword); |
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
94 |
begin |
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
95 |
KBnum:= n |
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
96 |
end; |
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
97 |
*) |
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
98 |
|
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
99 |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
100 |
procedure SetTextureParameters(enableClamp: Boolean); |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
101 |
begin |
3611 | 102 |
if enableClamp and ((cReducedQuality and rqClampLess) = 0) then |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
103 |
begin |
3594
aeca3d8f1b29
turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents:
3593
diff
changeset
|
104 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
aeca3d8f1b29
turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents:
3593
diff
changeset
|
105 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
106 |
end; |
3594
aeca3d8f1b29
turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents:
3593
diff
changeset
|
107 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
aeca3d8f1b29
turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents:
3593
diff
changeset
|
108 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
109 |
end; |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
110 |
|
4 | 111 |
|
208 | 112 |
procedure SendKB; |
113 |
var s: shortstring; |
|
114 |
begin |
|
115 |
if KBnum <> 0 then |
|
2947 | 116 |
begin |
117 |
s:= 'K' + inttostr(KBnum); |
|
118 |
SendIPCRaw(@s, Length(s) + 1) |
|
119 |
end |
|
208 | 120 |
end; |
121 |
||
337 | 122 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
3784
75aa91bea32b
Extend statistics collection (TeamKills, TurnSkips, TeamDamage)
burp
parents:
3779
diff
changeset
|
123 |
const stc: array [TStatInfoType] of char = 'rDkKHTPsSB'; |
2382 | 124 |
var buf: shortstring; |
337 | 125 |
begin |
2382 | 126 |
buf:= 'i' + stc[sit] + s; |
127 |
SendIPCRaw(@buf[0], length(buf) + 1) |
|
337 | 128 |
end; |
129 |
||
771 | 130 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
131 |
procedure ResetVertexArrays(texture: PTexture); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
132 |
begin |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
133 |
with texture^ do |
2947 | 134 |
begin |
135 |
vb[0].X:= 0; |
|
136 |
vb[0].Y:= 0; |
|
137 |
vb[1].X:= w; |
|
138 |
vb[1].Y:= 0; |
|
139 |
vb[2].X:= w; |
|
140 |
vb[2].Y:= h; |
|
141 |
vb[3].X:= 0; |
|
142 |
vb[3].Y:= h; |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
143 |
|
2947 | 144 |
tb[0].X:= 0; |
145 |
tb[0].Y:= 0; |
|
146 |
tb[1].X:= rx; |
|
147 |
tb[1].Y:= 0; |
|
148 |
tb[2].X:= rx; |
|
149 |
tb[2].Y:= ry; |
|
150 |
tb[3].X:= 0; |
|
151 |
tb[3].Y:= ry |
|
152 |
end; |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
153 |
end; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
154 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
155 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
156 |
begin |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
157 |
new(NewTexture); |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
158 |
NewTexture^.PrevTexture:= nil; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
159 |
NewTexture^.NextTexture:= nil; |
3537
8f5b3108f29c
New approach to the low-res problem. Basically, we already have a 1024 minimum, and the tallest maps are restricting themselves to 2048 maximum. All backgrounds are scaled down 50%, then scaled up on draw. Saves memory, and backgrounds are already deliberately fuzzed for depth of field anyway.
nemo
parents:
3534
diff
changeset
|
160 |
NewTexture^.Scale:= 1; |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
161 |
if TextureList <> nil then |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
162 |
begin |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
163 |
TextureList^.PrevTexture:= NewTexture; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
164 |
NewTexture^.NextTexture:= TextureList |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
165 |
end; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
166 |
TextureList:= NewTexture; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
167 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
168 |
NewTexture^.w:= width; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
169 |
NewTexture^.h:= height; |
1896 | 170 |
NewTexture^.rx:= 1.0; |
171 |
NewTexture^.ry:= 1.0; |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
172 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
173 |
ResetVertexArrays(NewTexture); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
174 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
175 |
glGenTextures(1, @NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
176 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
177 |
glBindTexture(GL_TEXTURE_2D, NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
178 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
179 |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
180 |
SetTextureParameters(true); |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
181 |
end; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
182 |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2279
diff
changeset
|
183 |
function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture; |
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
184 |
var tw, th, x, y: Longword; |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
185 |
tmpp: pointer; |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
186 |
fromP4, toP4: PLongWordArray; |
753 | 187 |
begin |
755 | 188 |
new(Surface2Tex); |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
189 |
Surface2Tex^.PrevTexture:= nil; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
190 |
Surface2Tex^.NextTexture:= nil; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
191 |
if TextureList <> nil then |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
192 |
begin |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
193 |
TextureList^.PrevTexture:= Surface2Tex; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
194 |
Surface2Tex^.NextTexture:= TextureList |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
195 |
end; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
196 |
TextureList:= Surface2Tex; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
197 |
|
755 | 198 |
Surface2Tex^.w:= surf^.w; |
199 |
Surface2Tex^.h:= surf^.h; |
|
200 |
||
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
201 |
if (surf^.format^.BytesPerPixel <> 4) then |
3859 | 202 |
begin |
2947 | 203 |
TryDo(false, 'Surface2Tex failed, expecting 32 bit surface', true); |
204 |
Surface2Tex^.id:= 0; |
|
205 |
exit |
|
3859 | 206 |
end; |
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
207 |
|
753 | 208 |
|
755 | 209 |
glGenTextures(1, @Surface2Tex^.id); |
753 | 210 |
|
755 | 211 |
glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); |
753 | 212 |
|
771 | 213 |
if SDL_MustLock(surf) then |
2947 | 214 |
SDLTry(SDL_LockSurface(surf) >= 0, true); |
771 | 215 |
|
2428 | 216 |
if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then |
3859 | 217 |
begin |
2947 | 218 |
tw:= toPowerOf2(Surf^.w); |
219 |
th:= toPowerOf2(Surf^.h); |
|
1896 | 220 |
|
2947 | 221 |
Surface2Tex^.rx:= Surf^.w / tw; |
222 |
Surface2Tex^.ry:= Surf^.h / th; |
|
2376 | 223 |
|
2947 | 224 |
GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); |
1896 | 225 |
|
3859 | 226 |
fromP4:= Surf^.pixels; |
227 |
toP4:= tmpp; |
|
771 | 228 |
|
3859 | 229 |
for y:= 0 to Pred(Surf^.h) do |
2947 | 230 |
begin |
3859 | 231 |
for x:= 0 to Pred(Surf^.w) do toP4^[x]:= fromP4^[x]; |
232 |
for x:= Surf^.w to Pred(tw) do toP4^[x]:= 0; |
|
233 |
toP4:= @(toP4^[tw]); |
|
234 |
fromP4:= @(fromP4^[Surf^.pitch div 4]) |
|
2947 | 235 |
end; |
1896 | 236 |
|
3859 | 237 |
for y:= Surf^.h to Pred(th) do |
2947 | 238 |
begin |
3859 | 239 |
for x:= 0 to Pred(tw) do toP4^[x]:= 0; |
240 |
toP4:= @(toP4^[tw]) |
|
2947 | 241 |
end; |
771 | 242 |
|
2947 | 243 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpp); |
2376 | 244 |
|
2947 | 245 |
FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
3859 | 246 |
end |
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
247 |
else |
3859 | 248 |
begin |
2947 | 249 |
Surface2Tex^.rx:= 1.0; |
250 |
Surface2Tex^.ry:= 1.0; |
|
251 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf^.w, surf^.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf^.pixels); |
|
3859 | 252 |
end; |
753 | 253 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
254 |
ResetVertexArrays(Surface2Tex); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
255 |
|
754 | 256 |
if SDL_MustLock(surf) then |
2947 | 257 |
SDL_UnlockSurface(surf); |
754 | 258 |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
259 |
SetTextureParameters(enableClamp); |
753 | 260 |
end; |
261 |
||
759 | 262 |
procedure FreeTexture(tex: PTexture); |
263 |
begin |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
264 |
if tex <> nil then |
2947 | 265 |
begin |
3697 | 266 |
if tex^.NextTexture <> nil then |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
267 |
tex^.NextTexture^.PrevTexture:= tex^.PrevTexture; |
3697 | 268 |
if tex^.PrevTexture <> nil then |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
269 |
tex^.PrevTexture^.NextTexture:= tex^.NextTexture |
3697 | 270 |
else |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
271 |
TextureList:= tex^.NextTexture; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
272 |
glDeleteTextures(1, @tex^.id); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
273 |
Dispose(tex); |
2947 | 274 |
end |
759 | 275 |
end; |
337 | 276 |
|
949 | 277 |
|
2735 | 278 |
procedure MakeScreenshot(filename: shortstring); |
1080 | 279 |
var p: Pointer; |
2947 | 280 |
size: Longword; |
281 |
f: file; |
|
282 |
// Windows Bitmap Header |
|
283 |
head: array[0..53] of Byte = ( |
|
284 |
$42, $4D, // identifier ("BM") |
|
285 |
0, 0, 0, 0, // file size |
|
286 |
0, 0, 0, 0, // reserved |
|
287 |
54, 0, 0, 0, // starting offset |
|
288 |
40, 0, 0, 0, // header size |
|
289 |
0, 0, 0, 0, // width |
|
290 |
0, 0, 0, 0, // height |
|
291 |
1, 0, // color planes |
|
292 |
24, 0, // bit depth |
|
293 |
0, 0, 0, 0, // compression method (uncompressed) |
|
294 |
0, 0, 0, 0, // image size |
|
295 |
96, 0, 0, 0, // horizontal resolution |
|
296 |
96, 0, 0, 0, // vertical resolution |
|
297 |
0, 0, 0, 0, // number of colors (all) |
|
298 |
0, 0, 0, 0 // number of important colors |
|
299 |
); |
|
1080 | 300 |
begin |
3107 | 301 |
// flash |
302 |
ScreenFade:= sfFromWhite; |
|
303 |
ScreenFadeValue:= sfMax; |
|
304 |
ScreenFadeSpeed:= 5; |
|
305 |
||
1080 | 306 |
size:= cScreenWidth * cScreenHeight * 3; |
307 |
p:= GetMem(size); |
|
308 |
||
2735 | 309 |
// update header information and file name |
310 |
||
3350 | 311 |
filename:= ParamStr(1) + '/Screenshots/' + filename + '.bmp'; |
2735 | 312 |
|
313 |
head[$02]:= (size + 54) and $ff; |
|
314 |
head[$03]:= ((size + 54) shr 8) and $ff; |
|
315 |
head[$04]:= ((size + 54) shr 16) and $ff; |
|
316 |
head[$05]:= ((size + 54) shr 24) and $ff; |
|
317 |
head[$12]:= cScreenWidth and $ff; |
|
318 |
head[$13]:= (cScreenWidth shr 8) and $ff; |
|
319 |
head[$14]:= (cScreenWidth shr 16) and $ff; |
|
320 |
head[$15]:= (cScreenWidth shr 24) and $ff; |
|
321 |
head[$16]:= cScreenHeight and $ff; |
|
322 |
head[$17]:= (cScreenHeight shr 8) and $ff; |
|
323 |
head[$18]:= (cScreenHeight shr 16) and $ff; |
|
324 |
head[$19]:= (cScreenHeight shr 24) and $ff; |
|
325 |
head[$22]:= size and $ff; |
|
326 |
head[$23]:= (size shr 8) and $ff; |
|
327 |
head[$24]:= (size shr 16) and $ff; |
|
328 |
head[$25]:= (size shr 24) and $ff; |
|
2163
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2162
diff
changeset
|
329 |
|
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2162
diff
changeset
|
330 |
//remember that opengles operates on a single surface, so GL_FRONT *should* be implied |
3663
8c28abf427f5
reduce the number of keywords used and switch to BMP format for screenshots
koda
parents:
3650
diff
changeset
|
331 |
//glReadBuffer(GL_FRONT); |
1080 | 332 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p); |
333 |
||
334 |
{$I-} |
|
2735 | 335 |
Assign(f, filename); |
1080 | 336 |
Rewrite(f, 1); |
337 |
if IOResult = 0 then |
|
2947 | 338 |
begin |
339 |
BlockWrite(f, head, sizeof(head)); |
|
340 |
BlockWrite(f, p^, size); |
|
341 |
Close(f); |
|
342 |
end; |
|
1080 | 343 |
{$I+} |
344 |
||
345 |
FreeMem(p) |
|
346 |
end; |
|
347 |
||
2619 | 348 |
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
349 |
{* for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7 *} |
|
350 |
var convertedSurf: PSDL_Surface = nil; |
|
351 |
begin |
|
2947 | 352 |
if (tmpsurf^.format^.bitsperpixel = 24) or ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) then |
353 |
begin |
|
354 |
convertedSurf:= SDL_ConvertSurface(tmpsurf, @conversionFormat, SDL_SWSURFACE); |
|
355 |
SDL_FreeSurface(tmpsurf); |
|
356 |
exit(convertedSurf); |
|
357 |
end; |
|
2705
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2699
diff
changeset
|
358 |
|
2947 | 359 |
exit(tmpsurf); |
2619 | 360 |
end; |
361 |
||
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
362 |
|
3038 | 363 |
procedure initModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
364 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
365 |
KBnum := 0; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
366 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
367 |
|
3038 | 368 |
procedure freeModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
369 |
begin |
3626 | 370 |
recordFileName:= ''; |
2947 | 371 |
while TextureList <> nil do FreeTexture(TextureList); |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
372 |
end; |
4 | 373 |
|
374 |
end. |