hedgewars/uStore.pas
changeset 6611 d9d00e537010
parent 6598 fa518383563b
child 6614 f88f67a17a9d
equal deleted inserted replaced
6610:84b0bc1bf399 6611:d9d00e537010
   623     AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_VideoDriverName(buf, sizeof(buf))) + ')');
   623     AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_VideoDriverName(buf, sizeof(buf))) + ')');
   624 
   624 
   625 {$IFDEF SDL13}
   625 {$IFDEF SDL13}
   626     // this function creates an opengles1.1 context by default on mobile devices
   626     // this function creates an opengles1.1 context by default on mobile devices
   627     // use SDL_GL_SetAttribute to change this behaviour
   627     // use SDL_GL_SetAttribute to change this behaviour
   628     SDLGLcontext:=SDL_GL_CreateContext(SDLwindow);
   628     if SDLGLcontext = nil then
       
   629         SDLGLcontext:= SDL_GL_CreateContext(SDLwindow);
   629     SDLTry(SDLGLcontext <> nil, true);
   630     SDLTry(SDLGLcontext <> nil, true);
   630     SDL_GL_SetSwapInterval(1);
   631     SDL_GL_SetSwapInterval(1);
   631 {$ENDIF}
   632 {$ENDIF}
   632 
   633 
   633     // get the max (horizontal and vertical) size for textures that the gpu can support
   634     // get the max (horizontal and vertical) size for textures that the gpu can support
   708             cStereoMode:= smNone;
   709             cStereoMode:= smNone;
   709     end;
   710     end;
   710 {$ENDIF}
   711 {$ENDIF}
   711 
   712 
   712     // set view port to whole window
   713     // set view port to whole window
   713     if (rotationQt = 0) or (rotationQt = 180) then
   714     glViewport(0, 0, cScreenWidth, cScreenHeight)
   714         glViewport(0, 0, cScreenWidth, cScreenHeight)
       
   715     else
       
   716         glViewport(0, 0, cScreenHeight, cScreenWidth);
       
   717 
   715 
   718     glMatrixMode(GL_MODELVIEW);
   716     glMatrixMode(GL_MODELVIEW);
   719     // prepare default translation/scaling
   717     // prepare default translation/scaling
   720     glLoadIdentity();
   718     glLoadIdentity();
   721     glRotatef(rotationQt, 0, 0, 1);
       
   722     glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
   719     glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
   723     glTranslatef(0, -cScreenHeight / 2, 0);
   720     glTranslatef(0, -cScreenHeight / 2, 0);
   724 
   721 
   725     // enable alpha blending
   722     // enable alpha blending
   726     glEnable(GL_BLEND);
   723     glEnable(GL_BLEND);
   745         glPopMatrix         // "return" to default scaling
   742         glPopMatrix         // "return" to default scaling
   746     else                    // other scaling
   743     else                    // other scaling
   747         begin
   744         begin
   748         glPushMatrix;       // save default scaling
   745         glPushMatrix;       // save default scaling
   749         glLoadIdentity;
   746         glLoadIdentity;
   750         glRotatef(rotationQt, 0, 0, 1);
       
   751         glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
   747         glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
   752         glTranslatef(0, -cScreenHeight / 2, 0);
   748         glTranslatef(0, -cScreenHeight / 2, 0);
   753         end;
   749         end;
   754 
   750 
   755     cScaleFactor:= f;
   751     cScaleFactor:= f;
   995         cFullScreen:= (not cFullScreen)
   991         cFullScreen:= (not cFullScreen)
   996     else
   992     else
   997         cFullScreen:= s = '1';
   993         cFullScreen:= s = '1';
   998 
   994 
   999     AddFileLog('Preparing to change video parameters...');
   995     AddFileLog('Preparing to change video parameters...');
  1000 {$IFNDEF IPHONEOS}
   996 {$IFDEF SDL13}
  1001     {$IFDEF SDL13}
       
  1002     if SDLwindow = nil then
   997     if SDLwindow = nil then
  1003     {$ELSE}
   998 {$ELSE}
  1004     if SDLPrimSurface = nil then
   999     if SDLPrimSurface = nil then
  1005     {$ENDIF}
  1000 {$ENDIF}
  1006         begin
  1001         begin
  1007         // set window title
  1002         // set window title
  1008         SDL_WM_SetCaption('Hedgewars', nil);
  1003         {$IFNDEF SDL13}SDL_WM_SetCaption('Hedgewars', nil);{$ENDIF}
  1009         WriteToConsole('Init SDL_image... ');
  1004         WriteToConsole('Init SDL_image... ');
  1010         SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
  1005         SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
  1011         WriteLnToConsole(msgOK);
  1006         WriteLnToConsole(msgOK);
  1012         // load engine icon
  1007         // load engine icon
  1013     {$IFNDEF DARWIN}
  1008     {$IFNDEF DARWIN}
  1021             end;
  1016             end;
  1022     {$ENDIF}
  1017     {$ENDIF}
  1023         end
  1018         end
  1024     else
  1019     else
  1025         begin
  1020         begin
       
  1021 {$IFDEF IPHONEOS}
       
  1022         // chFullScr is called when there is a rotation event and needs the SetScale and SetupOpenGL to set up the new resolution
       
  1023         // this 6 gl functions are the relevant ones and are hacked together here for optimisation
       
  1024         glMatrixMode(GL_MODELVIEW);
       
  1025         glPopMatrix;
       
  1026         glLoadIdentity();
       
  1027         glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
       
  1028         glTranslatef(0, -cScreenHeight / 2, 0);
       
  1029         glViewport(0, 0, cScreenWidth, cScreenHeight);
       
  1030         exit;
       
  1031 {$ELSE}
  1026         SetScale(cDefaultZoomLevel);
  1032         SetScale(cDefaultZoomLevel);
  1027      {$IF DEFINED(DARWIN) OR DEFINED(WIN32) or DEFINED(ANDROID)}
  1033      {$IF DEFINED(DARWIN) OR DEFINED(WIN32) or DEFINED(ANDROID)}
  1028         reinit:= true;
  1034         reinit:= true;
  1029         StoreRelease(true);
  1035         StoreRelease(true);
  1030         ResetLand;
  1036         ResetLand;
  1032         //uTextures.freeModule; //DEBUG ONLY
  1038         //uTextures.freeModule; //DEBUG ONLY
  1033     {$ENDIF}
  1039     {$ENDIF}
  1034         AddFileLog('Freeing old primary surface...');
  1040         AddFileLog('Freeing old primary surface...');
  1035         SDL_FreeSurface(SDLPrimSurface);
  1041         SDL_FreeSurface(SDLPrimSurface);
  1036         SDLPrimSurface:= nil;
  1042         SDLPrimSurface:= nil;
  1037         end;
  1043 {$ENDIF}
  1038 {$ENDIF}
  1044         end;
  1039 
  1045 
  1040     // these attributes must be set up before creating the sdl window
  1046     // these attributes must be set up before creating the sdl window
  1041 {$IFNDEF WIN32}
  1047 {$IFNDEF WIN32}
  1042 (* On a large number of testers machines, SDL default to software rendering when opengl attributes were set.
  1048 (* On a large number of testers machines, SDL default to software rendering when opengl attributes were set.
  1043    These attributes were "set" after CreateWindow in .15, which probably did nothing.
  1049    These attributes were "set" after CreateWindow in .15, which probably did nothing.
  1054     {$IFDEF MOBILE}
  1060     {$IFDEF MOBILE}
  1055     // make the sdl window appear on the second monitor when present
  1061     // make the sdl window appear on the second monitor when present
  1056     x:= x or (SDL_GetNumVideoDisplays() - 1);
  1062     x:= x or (SDL_GetNumVideoDisplays() - 1);
  1057     y:= y or (SDL_GetNumVideoDisplays() - 1);
  1063     y:= y or (SDL_GetNumVideoDisplays() - 1);
  1058 
  1064 
  1059     SDL_SetHint('SDL_IOS_ORIENTATIONS','LandscapeLeft LandscapeRight');
  1065     if isPhone() then
       
  1066         SDL_SetHint('SDL_IOS_ORIENTATIONS','LandscapeLeft LandscapeRight');
       
  1067 
       
  1068     // on mobile the SDL_WINDOW_RESIZABLE makes the window respond to rotation events
  1060     flags:= flags or SDL_WINDOW_BORDERLESS or SDL_WINDOW_RESIZABLE;
  1069     flags:= flags or SDL_WINDOW_BORDERLESS or SDL_WINDOW_RESIZABLE;
  1061     {$ENDIF}
  1070     {$ENDIF}
  1062 
  1071 
  1063     if SDLwindow = nil then
  1072     if SDLwindow = nil then
  1064         if cFullScreen then
  1073         if cFullScreen then
  1110 begin
  1119 begin
  1111     RegisterVariable('fullscr', vtCommand, @chFullScr, true);
  1120     RegisterVariable('fullscr', vtCommand, @chFullScr, true);
  1112 
  1121 
  1113     SDLPrimSurface:= nil;
  1122     SDLPrimSurface:= nil;
  1114 
  1123 
  1115     rotationQt:= 0;
       
  1116     cScaleFactor:= 2.0;
  1124     cScaleFactor:= 2.0;
  1117     Step:= 0;
  1125     Step:= 0;
  1118     ProgrTex:= nil;
  1126     ProgrTex:= nil;
  1119     SupportNPOTT:= false;
  1127     SupportNPOTT:= false;
  1120 //    cGPUVendor:= gvUnknown;
  1128 //    cGPUVendor:= gvUnknown;