update color management for new sdl_image on mac
still has some trasparency problems
--- a/hedgewars/CCHandlers.inc Wed Oct 21 19:41:24 2009 +0000
+++ b/hedgewars/CCHandlers.inc Thu Oct 22 18:59:35 2009 +0000
@@ -624,8 +624,8 @@
SDL_FreeSurface(SDLPrimSurface);
end;
-{$IFDEF DARWIN}
-//remove the topbar from Mac and iPhone
+{$IFDEF IPHONEOS}
+//remove the topbar from iPhone
flags:= flags or SDL_NOFRAME;
{$ENDIF}
@@ -640,7 +640,7 @@
{$IFDEF DEBUGFILE}
AddFileLog('SDL video driver: ' + string(SDL_VideoDriverName(buf, sizeof(buf))));
{$ENDIF}
-PixelFormat:= SDLPrimSurface^.format
+PixelFormat:=@convFormat// SDLPrimSurface^.format
end;
procedure chVol_p(var s: shortstring);
--- a/hedgewars/SDLh.pas Wed Oct 21 19:41:24 2009 +0000
+++ b/hedgewars/SDLh.pas Thu Oct 22 18:59:35 2009 +0000
@@ -58,14 +58,14 @@
SDLLibName = 'libSDL.so';
{$ENDIF}
{$ENDIF}
- SDL_SWSURFACE = $00000000;
- SDL_HWSURFACE = $00000001;
- SDL_SRCALPHA = $00010000;
- SDL_INIT_VIDEO = $00000020;
- SDL_INIT_AUDIO = $00000010;
+ SDL_SWSURFACE = $00000000;
+ SDL_HWSURFACE = $00000001;
+ SDL_SRCALPHA = $00010000;
+ SDL_INIT_VIDEO = $00000020;
+ SDL_INIT_AUDIO = $00000010;
SDL_INIT_JOYSTICK = $00000200;
- SDL_APPINPUTFOCUS=$00000002;
+ SDL_APPINPUTFOCUS = 2;
{$IFDEF SDL13}
SDL_ASYNCBLIT = $08000000;
@@ -94,10 +94,9 @@
{$ENDIF}
{*begin sdl_event binding*}
- SDL_NOEVENT = 0;
- SDL_KEYDOWN = 2;
- SDL_KEYUP = 3;
- //SDL_QUITEV = 12;
+ SDL_NOEVENT = 0;
+ SDL_KEYDOWN = 2;
+ SDL_KEYUP = 3;
SDL_VIDEORESIZE = 16; // TODO: outdated? no longer in SDL 1.3?
{$IFDEF SDL13}
@@ -111,7 +110,7 @@
SDL_JOYHAT = 12;
SDL_JOYBUTTONDOWN = 13;
SDL_JOYBUTTONUP = 14;
- SDL_QUITEV = 15;
+ SDL_QUITEV = 15;
{$ELSE}
SDL_ACTIVEEVENT = 1;
SDL_MOUSEBUTTONDOWN = 5;
@@ -122,28 +121,23 @@
SDL_JOYHAT = 9;
SDL_JOYBUTTONDOWN = 10;
SDL_JOYBUTTONUP = 11;
- SDL_QUITEV = 12;
+ SDL_QUITEV = 12;
{$ENDIF}
{*end sdl_event binding*}
-{$IFDEF SDL13}
-{*#define SDL_BUTTON(X) (1 << ((X)-1))
-#define SDL_BUTTON_LEFT 1
-#define SDL_BUTTON_MIDDLE 2
-#define SDL_BUTTON_RIGHT 3
-#define SDL_BUTTON_X1 4
-#define SDL_BUTTON_X2 5
-#define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
-#define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
-#define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
-#define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1)
-#define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)*}
-{$ENDIF}
+//if little endian
RMask = $000000FF;
GMask = $0000FF00;
BMask = $00FF0000;
AMask = $FF000000;
+//else
+// RMask = $FF000000;
+// GMask = $00FF0000;
+// BMask = $0000FF00;
+// AMask = $000000FF;
+//endif
+
type PSDL_Rect = ^TSDL_Rect;
TSDL_Rect = record
@@ -333,30 +327,30 @@
TSDL_Event = record
case Byte of
{$IFDEF SDL13}
- //doublecheck the type of WINDOWEVENT TEXTINPUT
- SDL_NOEVENT: (type_: byte);
- SDL_WINDOWEVENT: (active: TSDL_ActiveEvent);
- SDL_KEYDOWN,
+ //doublecheck the type of WINDOWEVENT TEXTINPUT
+ SDL_NOEVENT: (type_: byte);
+ SDL_WINDOWEVENT: (active: TSDL_ActiveEvent);
+ SDL_KEYDOWN,
SDL_KEYUP: (key: TSDL_KeyboardEvent);
- SDL_TEXTINPUT: (txtin: byte);
- SDL_MOUSEMOTION: (motion: TSDL_MouseMotionEvent);
- SDL_MOUSEBUTTONDOWN,
- SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent);
+ SDL_TEXTINPUT: (txtin: byte);
+ SDL_MOUSEMOTION: (motion: TSDL_MouseMotionEvent);
+ SDL_MOUSEBUTTONDOWN,
+ SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent);
{$ELSE}
- SDL_NOEVENT: (type_: byte);
- SDL_ACTIVEEVENT: (active: TSDL_ActiveEvent);
- SDL_KEYDOWN,
- SDL_KEYUP: (key: TSDL_KeyboardEvent);
- SDL_QUITEV: (quit: TSDL_QuitEvent);
- SDL_VIDEORESIZE: (resize: TSDL_ResizeEvent);
- SDL_MOUSEBUTTONDOWN,
- SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent);
+ SDL_NOEVENT: (type_: byte);
+ SDL_ACTIVEEVENT: (active: TSDL_ActiveEvent);
+ SDL_KEYDOWN,
+ SDL_KEYUP: (key: TSDL_KeyboardEvent);
+ SDL_QUITEV: (quit: TSDL_QuitEvent);
+ SDL_VIDEORESIZE: (resize: TSDL_ResizeEvent);
+ SDL_MOUSEBUTTONDOWN,
+ SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent);
{$ENDIF}
- SDL_JOYAXIS: (jaxis: TSDL_JoyAxisEvent);
- SDL_JOYHAT: (jhat: TSDL_JoyHatEvent);
- SDL_JOYBUTTONDOWN,
- SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
- end;
+ SDL_JOYAXIS: (jaxis: TSDL_JoyAxisEvent);
+ SDL_JOYHAT: (jhat: TSDL_JoyHatEvent);
+ SDL_JOYBUTTONDOWN,
+ SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
+ end;
PByteArray = ^TByteArray;
TByteArray = array[0..65535] of Byte;
@@ -395,6 +389,7 @@
procedure SDL_GetRGB(pixel: Longword; fmt: PSDL_PixelFormat; r, g, b: PByte); cdecl; external SDLLibName;
function SDL_MapRGB(format: PSDL_PixelFormat; r, g, b: Byte): Longword; cdecl; external SDLLibName;
+function SDL_MapRGBA(format: PSDL_PixelFormat; r, g, b, a: Byte): Longword; cdecl; external SDLLibName;
function SDL_DisplayFormat(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
function SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
@@ -585,7 +580,7 @@
{$ENDIF}
function IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
-
+function IMG_LoadPNG_RW(rwop: PSDL_RWops): PSDL_Surface; cdecl; external SDL_ImageLibName;
(* SDL_net *)
const {$IFDEF WIN32}
--- a/hedgewars/uConsts.pas Wed Oct 21 19:41:24 2009 +0000
+++ b/hedgewars/uConsts.pas Thu Oct 22 18:59:35 2009 +0000
@@ -1556,6 +1556,35 @@
PosSprite: sprWater)
);
+
+const convFormat: TSDL_PixelFormat = (
+ palette: nil;
+ BitsPerPixel : 32;
+ BytesPerPixel: 4;
+ Rloss : 0;
+ Gloss : 0;
+ Bloss : 0;
+ Aloss : 0;
+//if little endian -> bgra
+ Rshift: 0;
+ Gshift: 8;
+ Bshift: 16;
+ Ashift: 24;
+//else -> argb (or rgba?)
+// Rshift: 24;
+// Gshift: 16;
+// Bshift: 8;
+// Ashift: 0;
+//endif
+ RMask : RMask;
+ GMask : GMask;
+ BMask : BMask;
+ AMask : AMask;
+ colorkey: 0;
+ alpha : 255
+);
+
+
var CountTexz: array[1..9] of PTexture;
implementation
--- a/hedgewars/uMisc.pas Wed Oct 21 19:41:24 2009 +0000
+++ b/hedgewars/uMisc.pas Thu Oct 22 18:59:35 2009 +0000
@@ -396,13 +396,13 @@
if (surf^.format^.BytesPerPixel = 3) then
begin
modeIntFormat:= GL_RGB;
- modeFormat:= modeIntFormat;
+ modeFormat:= GL_RGB;
end
else
if (surf^.format^.BytesPerPixel = 4) then
begin
modeIntFormat:= GL_RGBA;
- modeFormat:= modeIntFormat;
+ modeFormat:= GL_RGBA;
end
else
begin
--- a/hedgewars/uStore.pas Wed Oct 21 19:41:24 2009 +0000
+++ b/hedgewars/uStore.pas Thu Oct 22 18:59:35 2009 +0000
@@ -901,26 +901,8 @@
function LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface;
var tmpsurf: PSDL_Surface;
s: shortstring;
-{$IFDEF IPHONEOS}
+{$IFDEF DARWIN}
convertedSurf: PSDL_Surface;
-const TestFormat: TSDL_PixelFormat = (
- palette: nil;
- BitsPerPixel : 32;
- BytesPerPixel: 4;
- Rloss : 0;
- Gloss : 0;
- Bloss : 0;
- Aloss : 0;
- Rshift: 0;
- Gshift: 8;
- Bshift: 16;
- Ashift: 24;
- RMask : $000000FF;
- GMask : $0000FF00;
- BMask : $00FF0000;
- AMask : $FF000000;
- colorkey: 0;
- alpha : 255);
{$ENDIF}
begin
WriteToConsole(msgLoading + filename + '... ');
@@ -961,17 +943,21 @@
exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask));
end;
+{$IFDEF DARWIN}
+//for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7
+if (tmpsurf^.format^.bitsperpixel = 24) or ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) then
+begin
+ convertedSurf:= SDL_ConvertSurface(tmpsurf, @convFormat, SDL_SWSURFACE);
+ SDL_FreeSurface(tmpsurf);
+ tmpsurf:= convertedSurf;
+end;
+{$ENDIF}
+
if (imageFlags and ifTransparent) <> 0 then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
//if (imageFlags and ifAlpha) <> 0 then Result:= SDL_DisplayFormatAlpha(tmpsurf) else Result:= SDL_DisplayFormat(tmpsurf);
WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');
WriteLnToConsole(msgOK);
-{$IFDEF IPHONEOS}
-//for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7
-convertedSurf:= SDL_ConvertSurface(tmpsurf, @TestFormat, SDL_SWSURFACE);
-tmpsurf:= convertedSurf;
-{$ENDIF}
-
LoadImage:= tmpsurf //Result
end;
@@ -980,13 +966,13 @@
{$IFNDEF IPHONEOS}
glLoadExtension:= glext_LoadExtension(extension);
{$ELSE}
- glLoadExtension:= false;
+ glLoadExtension:= false;
{$ENDIF}
{$IFDEF DEBUGFILE}
if not glLoadExtension then
- AddFileLog('OpenGL: "' + extension + '" failed to load')
+ AddFileLog('OpenGL - "' + extension + '" failed to load')
else
- AddFileLog('OpenGL: "' + extension + '" loaded');
+ AddFileLog('OpenGL - "' + extension + '" loaded');
{$ENDIF}
end;
@@ -996,21 +982,25 @@
glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
{$IFDEF DEBUGFILE}
-AddFileLog('OpenGL: Renderer: ' + glGetString(GL_RENDERER));
-AddFileLog('OpenGL: Vendor: ' + glGetString(GL_VENDOR));
-AddFileLog('OpenGL: Version: ' + glGetString(GL_VERSION));
-AddFileLog('OpenGL: GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize));
+AddFileLog('OpenGL - Renderer: ' + string(pchar(glGetString(GL_RENDERER))));
+AddFileLog('OpenGL - Vendor: ' + string(pchar(glGetString(GL_VENDOR))));
+AddFileLog('OpenGL - Version: ' + string(pchar(glGetString(GL_VERSION))));
+AddFileLog('OpenGL - GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize));
{$ENDIF}
if MaxTextureSize = 0 then
begin
+{$IFDEF DARWIN}
+ MaxTextureSize:= 2048;
+{$ELSE}
MaxTextureSize:= 1024;
+{$ENDIF}
{$IFDEF DEBUGFILE}
- AddFileLog('OpenGL: Warning - driver didn''t provide any valid max texture size; assuming 1024');
+ AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024');
{$ENDIF}
end;
-vendor:= LowerCase(glGetString(GL_VENDOR));
+vendor:= LowerCase(string(pchar(glGetString(GL_VENDOR))));
if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then
cGPUVendor:= gvNVIDIA
else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then
@@ -1019,17 +1009,21 @@
cGPUVendor:= gvIntel;
-
{$IFNDEF IPHONEOS}
// since ATI seems to be unable to provide proper texture filtering/quality,
-// don't even try to load the extension on ATI cards
+// do not even try to load the extension on ATI cards
+
+{$IFDEF DARWIN}
+if true then
+{$ELSE}
if cGPUVendor <> gvATI then
+{$ENDIF}
SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two')
{$IFDEF DEBUGFILE}
else
AddFileLog('OpenGL: Skipped extension GL_ARB_texture_non_power_of_two due to ATI card')
{$ENDIF}
-; // don't touch this line! :)
+; // do not touch this line! :)
{$ENDIF}
// set view port to whole window