hedgewars/uStore.pas
changeset 3376 faee68a28b82
parent 3341 3de60a5986e9
child 3381 f8800c44b3de
equal deleted inserted replaced
3375:88bb88294e06 3376:faee68a28b82
    73 procedure SetScale(f: GLfloat);
    73 procedure SetScale(f: GLfloat);
    74 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
    74 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
    75 procedure RenderWeaponTooltip(atype: TAmmoType);
    75 procedure RenderWeaponTooltip(atype: TAmmoType);
    76 procedure ShowWeaponTooltip(x, y: LongInt);
    76 procedure ShowWeaponTooltip(x, y: LongInt);
    77 procedure FreeWeaponTooltip;
    77 procedure FreeWeaponTooltip;
    78 procedure Tint(r, g, b, a: Single);
    78 procedure Tint(r, g, b, a: Byte); inline;
       
    79 procedure Tint(c: Longword); inline;
    79 
    80 
    80 implementation
    81 implementation
    81 uses uMisc, uConsole, uLand, uLocale, uWorld{$IFDEF IPHONEOS}, PascalExports{$ENDIF};
    82 uses uMisc, uConsole, uLand, uLocale, uWorld{$IFDEF IPHONEOS}, PascalExports{$ENDIF};
    82 
    83 
    83 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    84 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    84 
    85 
    85 var HHTexture: PTexture;
    86 var HHTexture: PTexture;
    86     MaxTextureSize: LongInt;
    87     MaxTextureSize: LongInt;
    87     cGPUVendor: TGPUVendor;
    88     cGPUVendor: TGPUVendor;
    88 
    89     lastTint: Longword;
    89 procedure Tint(r, g, b, a: Single);
    90 
    90 begin
    91 {$IFNDEF IPHONEOS}
    91 glColor4f(r, g, b, a);
    92 procedure Tint(r, g, b, a: Byte); inline;
    92 end;
    93 begin
       
    94 Tint((a shl 24) or (b shl 16) or (g shl 8) or r);
       
    95 end;
       
    96 
       
    97 procedure Tint(c: Longword); inline;
       
    98 begin
       
    99 if c = lastTint then
       
   100     exit;
       
   101 glColor4ubv(@c);
       
   102 lastTint:= c;
       
   103 end;
       
   104 {$ELSE}
       
   105 procedure Tint(r, g, b, a: Byte); inline;
       
   106 var nc: Longword;
       
   107 begin
       
   108 nc:= (a shl 24) or (b shl 16) or (g shl 8) or r;
       
   109 if nc = lastTint then
       
   110     exit;
       
   111 glColor4ub(r, g, b, a);
       
   112 lastTint:= nc;
       
   113 end;
       
   114 
       
   115 procedure Tint(c: Longword); inline;
       
   116 begin
       
   117 if c = lastTint then
       
   118     exit;
       
   119 Tint(c and $FF, (c shr 8) and $FF, (c shr 16) and $FF, (c shr 24) and $FF);
       
   120 lastTint:= c;
       
   121 end;
       
   122 {$ENDIF}
    93 
   123 
    94 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
   124 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
    95 var r: TSDL_Rect;
   125 var r: TSDL_Rect;
    96 begin
   126 begin
    97 r:= rect^;
   127 r:= rect^;
   541    glRotatef(Angle, 0, 0,  1);
   571    glRotatef(Angle, 0, 0,  1);
   542 
   572 
   543 glTranslatef(Dir*OffsetX, OffsetY, 0);
   573 glTranslatef(Dir*OffsetX, OffsetY, 0);
   544 glScalef(Scale, Scale, 1);
   574 glScalef(Scale, Scale, 1);
   545 
   575 
   546 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   576 // Any reason for this call? And why only in t direction, not s?
       
   577 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   547 
   578 
   548 if Dir < 0 then
   579 if Dir < 0 then
   549     hw:= w div -2
   580     hw:= w div -2
   550 else
   581 else
   551     hw:= w div 2;
   582     hw:= w div 2;
   756 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   787 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   757 
   788 
   758 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   789 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   759 glDisableClientState(GL_VERTEX_ARRAY);
   790 glDisableClientState(GL_VERTEX_ARRAY);
   760 
   791 
   761 
       
   762 glColor4f(1,1,1,1);
       
   763 
       
   764 glPopMatrix
   792 glPopMatrix
   765 end;
   793 end;
   766 
   794 
   767 procedure DrawFillRect(r: TSDL_Rect);
   795 procedure DrawFillRect(r: TSDL_Rect);
   768 var VertexBuffer: array [0..3] of TVertex2f;
   796 var VertexBuffer: array [0..3] of TVertex2f;
   769 begin
   797 begin
   770 glDisable(GL_TEXTURE_2D);
   798 glDisable(GL_TEXTURE_2D);
   771 
   799 
   772 glColor4ub(0, 0, 0, 127);
   800 Tint($80000000);
   773 
   801 
   774 VertexBuffer[0].X:= r.x;
   802 VertexBuffer[0].X:= r.x;
   775 VertexBuffer[0].Y:= r.y;
   803 VertexBuffer[0].Y:= r.y;
   776 VertexBuffer[1].X:= r.x + r.w;
   804 VertexBuffer[1].X:= r.x + r.w;
   777 VertexBuffer[1].Y:= r.y;
   805 VertexBuffer[1].Y:= r.y;
   783 glEnableClientState(GL_VERTEX_ARRAY);
   811 glEnableClientState(GL_VERTEX_ARRAY);
   784 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   812 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   785 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   813 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   786 glDisableClientState(GL_VERTEX_ARRAY);
   814 glDisableClientState(GL_VERTEX_ARRAY);
   787 
   815 
   788 glColor4f(1, 1, 1, 1);
   816 Tint($FFFFFFFF);
   789 glEnable(GL_TEXTURE_2D)
   817 glEnable(GL_TEXTURE_2D)
   790 end;
   818 end;
   791 
   819 
   792 procedure StoreRelease;
   820 procedure StoreRelease;
   793 var ii: TSprite;
   821 var ii: TSprite;
  1123 
  1151 
  1124 procedure SetupOpenGL;
  1152 procedure SetupOpenGL;
  1125 var vendor: shortstring;
  1153 var vendor: shortstring;
  1126 begin
  1154 begin
  1127 {$IFDEF IPHONEOS}
  1155 {$IFDEF IPHONEOS}
  1128 //these are good performance savers, perhaps we could enable them by default
  1156     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); // no double buffering
  1129     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
       
  1130     SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
  1157     SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
  1131     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
  1158 {$ELSE}
       
  1159     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
       
  1160 {$ENDIF}
       
  1161     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); // no depth buffer
  1132     SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
  1162     SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
  1133     SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
  1163     SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
  1134     SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
  1164     SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
  1135     SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
  1165     SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); // no alpha channel required
  1136     SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
  1166     SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); // buffer has to be 16 bit only
  1137     //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
  1167     SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // try to prefer hardware rendering
  1138 {$ELSE}
       
  1139     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
       
  1140 {$ENDIF}
       
  1141 
  1168 
  1142 {$IFNDEF SDL13}
  1169 {$IFNDEF SDL13}
  1143 // this attribute is default in 1.3 and must be enabled in MacOSX
  1170 // this attribute is default in 1.3 and must be enabled in MacOSX
  1144 {$IFNDEF DARWIN}
  1171 {$IFNDEF DARWIN}
  1145     if cVSyncInUse then
  1172     if cVSyncInUse then
  1202     glTranslatef(0, -cScreenHeight / 2, 0);
  1229     glTranslatef(0, -cScreenHeight / 2, 0);
  1203 
  1230 
  1204     // enable alpha blending
  1231     // enable alpha blending
  1205     glEnable(GL_BLEND);
  1232     glEnable(GL_BLEND);
  1206     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1233     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
       
  1234     // disable/lower perspective correction (won't need it anyway)
       
  1235     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
       
  1236     // disable dithering
       
  1237     glDisable(GL_DITHER);
       
  1238     // enable 2d textures by default
       
  1239     glEnable(GL_TEXTURE_2D);
  1207 end;
  1240 end;
  1208 
  1241 
  1209 procedure SetScale(f: GLfloat);
  1242 procedure SetScale(f: GLfloat);
  1210 var
  1243 var
  1211 {$IFDEF IPHONEOS}
  1244 {$IFDEF IPHONEOS}
  1215 {$ENDIF}
  1248 {$ENDIF}
  1216 begin
  1249 begin
  1217     // leave immediately if scale factor did not change
  1250     // leave immediately if scale factor did not change
  1218     if f = cScaleFactor then exit;
  1251     if f = cScaleFactor then exit;
  1219 
  1252 
  1220     if f = scale then glPopMatrix   // "return" to default scaling
  1253     if f = scale then
       
  1254         glPopMatrix   // "return" to default scaling
  1221     else                // other scaling
  1255     else                // other scaling
  1222     begin
  1256         begin
  1223         glPushMatrix;       // save default scaling
  1257         glPushMatrix;       // save default scaling
  1224         glLoadIdentity;
  1258         glLoadIdentity;
  1225 {$IFDEF IPHONEOS}
  1259 {$IFDEF IPHONEOS}
  1226         glRotatef(-90, 0, 0, 1);
  1260         glRotatef(-90, 0, 0, 1);
  1227 {$ENDIF}
  1261 {$ENDIF}
  1228         glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
  1262         glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
  1229         glTranslatef(0, -cScreenHeight / 2, 0);
  1263         glTranslatef(0, -cScreenHeight / 2, 0);
  1230     end;
  1264         end;
  1231 
  1265 
  1232     cScaleFactor:= f;
  1266     cScaleFactor:= f;
  1233 end;
  1267 end;
  1234 
  1268 
  1235 ////////////////////////////////////////////////////////////////////////////////
  1269 ////////////////////////////////////////////////////////////////////////////////
  1250     end;
  1284     end;
  1251 
  1285 
  1252     TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
  1286     TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
  1253 
  1287 
  1254     glClear(GL_COLOR_BUFFER_BIT);
  1288     glClear(GL_COLOR_BUFFER_BIT);
  1255     glEnable(GL_TEXTURE_2D);
       
  1256     if Step < numsquares then r.x:= 0
  1289     if Step < numsquares then r.x:= 0
  1257     else r.x:= squaresize;
  1290     else r.x:= squaresize;
  1258     
  1291     
  1259     r.y:= (Step mod numsquares) * squaresize;
  1292     r.y:= (Step mod numsquares) * squaresize;
  1260     r.w:= squaresize;
  1293     r.w:= squaresize;
  1261     r.h:= squaresize;
  1294     r.h:= squaresize;
  1262     
  1295     
  1263     DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex);
  1296     DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex);
  1264 
  1297 
  1265     glDisable(GL_TEXTURE_2D);
       
  1266     SDL_GL_SwapBuffers();
  1298     SDL_GL_SwapBuffers();
  1267 {$IFDEF SDL13}
  1299 {$IFDEF SDL13}
  1268     SDL_RenderPresent();
  1300     SDL_RenderPresent();
  1269 {$ENDIF}
  1301 {$ENDIF}
  1270     inc(Step);
  1302     inc(Step);