hedgewars/uStore.pas
changeset 11507 bd9a2f1b0080
parent 11409 e0600c5964c7
child 11518 02a13be714d2
equal deleted inserted replaced
11506:24bef86e3f3a 11507:bd9a2f1b0080
   110 finalRect.h:= h + cFontBorder * 2;
   110 finalRect.h:= h + cFontBorder * 2;
   111 clr.r:= Color shr 16;
   111 clr.r:= Color shr 16;
   112 clr.g:= (Color shr 8) and $FF;
   112 clr.g:= (Color shr 8) and $FF;
   113 clr.b:= Color and $FF;
   113 clr.b:= Color and $FF;
   114 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, s, clr);
   114 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, s, clr);
   115 SDLTry(tmpsurf <> nil, 'TTF_RenderUTF8_Blended', true);
   115 if tmpsurf = nil then exit;
   116 tmpsurf:= doSurfaceConversion(tmpsurf);
   116 tmpsurf:= doSurfaceConversion(tmpsurf);
   117 SDLTry(tmpsurf <> nil, 'TTF_RenderUTF8_Blended, doSurfaceConversion', true);
   117 
   118 SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect);
   118 if tmpsurf <> nil then
   119 SDL_FreeSurface(tmpsurf);
   119 begin
   120 finalRect.x:= X;
   120     SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect);
   121 finalRect.y:= Y;
   121     SDL_FreeSurface(tmpsurf);
   122 finalRect.w:= w + cFontBorder * 2 + 4;
   122     finalRect.x:= X;
   123 finalRect.h:= h + cFontBorder * 2;
   123     finalRect.y:= Y;
       
   124     finalRect.w:= w + cFontBorder * 2 + 4;
       
   125     finalRect.h:= h + cFontBorder * 2;
       
   126 end;
       
   127 
   124 WriteInRect:= finalRect
   128 WriteInRect:= finalRect
   125 end;
   129 end;
   126 
   130 
   127 procedure MakeCrossHairs;
   131 procedure MakeCrossHairs;
   128 var tmpsurf: PSDL_Surface;
   132 var tmpsurf: PSDL_Surface;
   354         with Fontz[fi] do
   358         with Fontz[fi] do
   355             begin
   359             begin
   356             s:= cPathz[ptFonts] + '/' + Name;
   360             s:= cPathz[ptFonts] + '/' + Name;
   357             WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... ');
   361             WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... ');
   358             Handle:= TTF_OpenFontRW(rwopsOpenRead(s), true, Height);
   362             Handle:= TTF_OpenFontRW(rwopsOpenRead(s), true, Height);
   359             SDLTry(Handle <> nil, 'TTF_OpenFontRW', true);
   363             if SDLCheck(Handle <> nil, 'TTF_OpenFontRW', true) then exit;
   360             TTF_SetFontStyle(Handle, style);
   364             TTF_SetFontStyle(Handle, style);
   361             WriteLnToConsole(msgOK)
   365             WriteLnToConsole(msgOK)
   362             end;
   366             end;
   363 
   367 
   364 if not cOnlyStats then
   368 if not cOnlyStats then
   603         if rwops <> nil then
   607         if rwops <> nil then
   604             begin
   608             begin
   605             // anounce that loading failed
   609             // anounce that loading failed
   606             OutError(msgFailed, false);
   610             OutError(msgFailed, false);
   607 
   611 
   608             SDLTry(false, 'LoadImage', (imageFlags and ifCritical) <> 0);
   612             if SDLCheck(false, 'LoadImage', (imageFlags and ifCritical) <> 0) then exit;
   609             // rwops was already freed by IMG_Load_RW
   613             // rwops was already freed by IMG_Load_RW
   610             rwops:= nil;
   614             rwops:= nil;
   611             end else
   615             end else
   612             OutError(msgFailed, (imageFlags and ifCritical) <> 0);
   616             OutError(msgFailed, (imageFlags and ifCritical) <> 0);
   613         exit;
   617         exit;
   732     SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16);       // buffer should be 16
   736     SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16);       // buffer should be 16
   733     SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // prefer hw rendering
   737     SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // prefer hw rendering
   734 end;
   738 end;
   735 
   739 
   736 procedure SetupOpenGL;
   740 procedure SetupOpenGL;
   737 var buf: array[byte] of char;
       
   738 begin
   741 begin
   739     AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_GetCurrentVideoDriver()) + ')');
   742     AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_GetCurrentVideoDriver()) + ')');
   740 
   743 
   741     // TODO: this function creates an opengles1.1 context
   744     // TODO: this function creates an opengles1.1 context
   742     // un-comment below and add proper logic to support opengles2.0
   745     // un-comment below and add proper logic to support opengles2.0
   743     //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
   746     //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
   744     //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
   747     //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
   745     if SDLGLcontext = nil then
   748     if SDLGLcontext = nil then
   746         SDLGLcontext:= SDL_GL_CreateContext(SDLwindow);
   749         SDLGLcontext:= SDL_GL_CreateContext(SDLwindow);
   747     SDLTry(SDLGLcontext <> nil, 'SDLGLcontext', true);
   750     if SDLCheck(SDLGLcontext <> nil, 'SDLGLcontext', true) then exit;
   748     SDL_GL_SetSwapInterval(1);
   751     SDL_GL_SetSwapInterval(1);
   749 
   752 
   750     RendererSetup();
   753     RendererSetup();
   751 
   754 
   752 // gl2 init/matrix code was here, but removed
   755 // gl2 init/matrix code was here, but removed
   986     // create hidden window
   989     // create hidden window
   987     SDLwindow:= SDL_CreateWindow(PChar('hedgewars video rendering (SDL2 hidden window)'),
   990     SDLwindow:= SDL_CreateWindow(PChar('hedgewars video rendering (SDL2 hidden window)'),
   988                                  SDL_WINDOWPOS_CENTERED_MASK, SDL_WINDOWPOS_CENTERED_MASK,
   991                                  SDL_WINDOWPOS_CENTERED_MASK, SDL_WINDOWPOS_CENTERED_MASK,
   989                                  cScreenWidth, cScreenHeight,
   992                                  cScreenWidth, cScreenHeight,
   990                                  SDL_WINDOW_HIDDEN or SDL_WINDOW_OPENGL);
   993                                  SDL_WINDOW_HIDDEN or SDL_WINDOW_OPENGL);
   991     SDLTry(SDLwindow <> nil, 'SDL_CreateWindow', true);
   994     if SDLCheck(SDLwindow <> nil, 'SDL_CreateWindow', true) then exit;
   992     SetupOpenGL();
   995     SetupOpenGL();
   993 end;
   996 end;
   994 {$ENDIF} // USE_VIDEO_RECORDING
   997 {$ENDIF} // USE_VIDEO_RECORDING
   995 
   998 
   996 procedure chFullScr(var s: shortstring);
   999 procedure chFullScr(var s: shortstring);
  1022     AddFileLog('Preparing to change video parameters...');
  1025     AddFileLog('Preparing to change video parameters...');
  1023     if SDLwindow = nil then
  1026     if SDLwindow = nil then
  1024         begin
  1027         begin
  1025         // set window title
  1028         // set window title
  1026         WriteToConsole('Init SDL_image... ');
  1029         WriteToConsole('Init SDL_image... ');
  1027         SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, 'IMG_Init', true);
  1030         if SDLCheck(IMG_Init(IMG_INIT_PNG) <> 0, 'IMG_Init', true) then exit;
  1028         WriteLnToConsole(msgOK);
  1031         WriteLnToConsole(msgOK);
  1029         end
  1032         end
  1030     else
  1033     else
  1031         begin
  1034         begin
  1032         AmmoMenuInvalidated:= true;
  1035         AmmoMenuInvalidated:= true;
  1080     if cFullScreen then
  1083     if cFullScreen then
  1081         flags:= flags or SDL_WINDOW_FULLSCREEN;
  1084         flags:= flags or SDL_WINDOW_FULLSCREEN;
  1082 
  1085 
  1083     if SDLwindow = nil then
  1086     if SDLwindow = nil then
  1084         SDLwindow:= SDL_CreateWindow(PChar('Hedgewars'), x, y, cScreenWidth, cScreenHeight, flags);
  1087         SDLwindow:= SDL_CreateWindow(PChar('Hedgewars'), x, y, cScreenWidth, cScreenHeight, flags);
  1085     SDLTry(SDLwindow <> nil, 'SDL_CreateWindow', true);
  1088     if SDLCheck(SDLwindow <> nil, 'SDL_CreateWindow', true) then exit;
  1086 
  1089 
  1087     // load engine ico
  1090     // load engine ico
  1088     {$IFNDEF DARWIN}
  1091     {$IFNDEF DARWIN}
  1089     ico:= LoadDataImage(ptGraphics, 'hwengine', ifIgnoreCaps);
  1092     ico:= LoadDataImage(ptGraphics, 'hwengine', ifIgnoreCaps);
  1090     if ico <> nil then
  1093     if ico <> nil then