hedgewars/uStore.pas
branchsdl2transition
changeset 9682 aa2431ed87b2
parent 9677 71626318f80e
child 9684 8113075dc7cc
equal deleted inserted replaced
9679:dfaa39674e1e 9682:aa2431ed87b2
    98 clr.r:= Color shr 16;
    98 clr.r:= Color shr 16;
    99 clr.g:= (Color shr 8) and $FF;
    99 clr.g:= (Color shr 8) and $FF;
   100 clr.b:= Color and $FF;
   100 clr.b:= Color and $FF;
   101 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr);
   101 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr);
   102 tmpsurf:= doSurfaceConversion(tmpsurf);
   102 tmpsurf:= doSurfaceConversion(tmpsurf);
   103 SDLTry(tmpsurf <> nil, true);
   103 SDLTry(tmpsurf <> nil, 'TTF_RenderUTF8_Blended, doSurfaceConversion', true);
   104 SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect);
   104 SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect);
   105 SDL_FreeSurface(tmpsurf);
   105 SDL_FreeSurface(tmpsurf);
   106 finalRect.x:= X;
   106 finalRect.x:= X;
   107 finalRect.y:= Y;
   107 finalRect.y:= Y;
   108 finalRect.w:= w + cFontBorder * 2 + 4;
   108 finalRect.w:= w + cFontBorder * 2 + 4;
   312         with Fontz[fi] do
   312         with Fontz[fi] do
   313             begin
   313             begin
   314             s:= cPathz[ptFonts] + '/' + Name;
   314             s:= cPathz[ptFonts] + '/' + Name;
   315             WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... ');
   315             WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... ');
   316             Handle:= TTF_OpenFontRW(rwopsOpenRead(s), true, Height);
   316             Handle:= TTF_OpenFontRW(rwopsOpenRead(s), true, Height);
   317             SDLTry(Handle <> nil, true);
   317             SDLTry(Handle <> nil, 'TTF_OpenFontRW', true);
   318             TTF_SetFontStyle(Handle, style);
   318             TTF_SetFontStyle(Handle, style);
   319             WriteLnToConsole(msgOK)
   319             WriteLnToConsole(msgOK)
   320             end;
   320             end;
   321 
   321 
   322 MakeCrossHairs;
   322 MakeCrossHairs;
   697     AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_VideoDriverName(buf, sizeof(buf))) + ')');
   697     AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_VideoDriverName(buf, sizeof(buf))) + ')');
   698 {$ENDIF}
   698 {$ENDIF}
   699 
   699 
   700     AuxBufNum:= AuxBufNum;
   700     AuxBufNum:= AuxBufNum;
   701 
   701 
   702 {$IFDEF MOBILE}
   702 {$IFDEF SDL2}
   703     // TODO: this function creates an opengles1.1 context
   703     // TODO: this function creates an opengles1.1 context
   704     // un-comment below and add proper logic to support opengles2.0
   704     // un-comment below and add proper logic to support opengles2.0
   705     //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
   705     //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
   706     //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
   706     //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
   707     if SDLGLcontext = nil then
   707     if SDLGLcontext = nil then
   708         SDLGLcontext:= SDL_GL_CreateContext(SDLwindow);
   708         SDLGLcontext:= SDL_GL_CreateContext(SDLwindow);
   709     SDLTry(SDLGLcontext <> nil, true);
   709     SDLTry(SDLGLcontext <> nil, 'SDLGLcontext', true);
   710     SDL_GL_SetSwapInterval(1);
   710     SDLTry(SDL_GL_SetSwapInterval(1) = 0, 'SDL_GL_SetSwapInterval', true);
   711 {$ENDIF}
   711 {$ENDIF}
   712 
   712 
   713     // get the max (h and v) size for textures that the gpu can support
   713     // get the max (h and v) size for textures that the gpu can support
   714     glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
   714     glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
   715     if MaxTextureSize <= 0 then
   715     if MaxTextureSize <= 0 then
  1072     // create hidden window
  1072     // create hidden window
  1073     SDLwindow:= SDL_CreateWindow('hedgewars video rendering (SDL2 hidden window)',
  1073     SDLwindow:= SDL_CreateWindow('hedgewars video rendering (SDL2 hidden window)',
  1074                                  SDL_WINDOWPOS_CENTERED_MASK, SDL_WINDOWPOS_CENTERED_MASK,
  1074                                  SDL_WINDOWPOS_CENTERED_MASK, SDL_WINDOWPOS_CENTERED_MASK,
  1075                                  cScreenWidth, cScreenHeight,
  1075                                  cScreenWidth, cScreenHeight,
  1076                                  SDL_WINDOW_HIDDEN or SDL_WINDOW_OPENGL);
  1076                                  SDL_WINDOW_HIDDEN or SDL_WINDOW_OPENGL);
  1077     SDLTry(SDLwindow <> nil, true);
  1077     SDLTry(SDLwindow <> nil, 'SDL_CreateWindow', true);
  1078     SetupOpenGL();
  1078     SetupOpenGL();
  1079 end;
  1079 end;
  1080 {$ELSE}
  1080 {$ELSE}
  1081 procedure InitOffscreenOpenGL;
  1081 procedure InitOffscreenOpenGL;
  1082 var ArgCount: LongInt;
  1082 var ArgCount: LongInt;
  1132         // set window title
  1132         // set window title
  1133     {$IFNDEF SDL2}
  1133     {$IFNDEF SDL2}
  1134         SDL_WM_SetCaption(_P'Hedgewars', nil);
  1134         SDL_WM_SetCaption(_P'Hedgewars', nil);
  1135     {$ENDIF}
  1135     {$ENDIF}
  1136         WriteToConsole('Init SDL_image... ');
  1136         WriteToConsole('Init SDL_image... ');
  1137         SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
  1137         SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, 'IMG_Init', true);
  1138         WriteLnToConsole(msgOK);
  1138         WriteLnToConsole(msgOK);
  1139         // load engine icon
  1139         // load engine icon
  1140     {$IFNDEF DARWIN}
  1140     {$IFNDEF DARWIN}
  1141     {$IFNDEF SDL2}
  1141     {$IFNDEF SDL2}
  1142         ico:= LoadDataImage(ptGraphics, 'hwengine', ifIgnoreCaps);
  1142         ico:= LoadDataImage(ptGraphics, 'hwengine', ifIgnoreCaps);
  1206     if cFullScreen then
  1206     if cFullScreen then
  1207         flags:= flags or SDL_WINDOW_FULLSCREEN;
  1207         flags:= flags or SDL_WINDOW_FULLSCREEN;
  1208 
  1208 
  1209     if SDLwindow = nil then
  1209     if SDLwindow = nil then
  1210         SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
  1210         SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
  1211     SDLTry(SDLwindow <> nil, true);
  1211     SDLTry(SDLwindow <> nil, 'SDL_CreateWindow', true);
  1212 {$ELSE}
  1212 {$ELSE}
  1213     flags:= SDL_OPENGL or SDL_RESIZABLE;
  1213     flags:= SDL_OPENGL or SDL_RESIZABLE;
  1214     if cFullScreen then
  1214     if cFullScreen then
  1215         flags:= flags or SDL_FULLSCREEN;
  1215         flags:= flags or SDL_FULLSCREEN;
  1216     if not cOnlyStats then
  1216     if not cOnlyStats then
  1262 procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
  1262 procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
  1263 begin
  1263 begin
  1264     if GameType = gmtRecord then
  1264     if GameType = gmtRecord then
  1265         exit;
  1265         exit;
  1266 {$IFDEF SDL2}
  1266 {$IFDEF SDL2}
  1267     SDL_GL_SwapWindow(SDLwindow);
  1267     SDLTry(SDL_GL_SwapWindow(SDLwindow) <> 0, 'SDL_GL_SwapWindow', true);
  1268 {$ELSE}
  1268 {$ELSE}
  1269     SDL_GL_SwapBuffers();
  1269     SDL_GL_SwapBuffers();
  1270 {$ENDIF}
  1270 {$ENDIF}
  1271 end;
  1271 end;
  1272 
  1272