hedgewars/uStore.pas
changeset 10302 ea0b0e2efd95
parent 10276 89056c7254ef
child 10304 7e40820b7ed6
equal deleted inserted replaced
10301:6a225b469eef 10302:ea0b0e2efd95
    42 function  LoadDataImageAltFile(const path: TPathType; const filename, altFile: shortstring; imageFlags: LongInt): PSDL_Surface;
    42 function  LoadDataImageAltFile(const path: TPathType; const filename, altFile: shortstring; imageFlags: LongInt): PSDL_Surface;
    43 
    43 
    44 procedure LoadHedgehogHat(var HH: THedgehog; newHat: shortstring);
    44 procedure LoadHedgehogHat(var HH: THedgehog; newHat: shortstring);
    45 procedure LoadHedgehogHat2(var HH: THedgehog; newHat: shortstring; allowSurfReuse: boolean);
    45 procedure LoadHedgehogHat2(var HH: THedgehog; newHat: shortstring; allowSurfReuse: boolean);
    46 
    46 
       
    47 procedure InitZoom(zoom: real);
       
    48 
    47 procedure SetupOpenGL;
    49 procedure SetupOpenGL;
    48 procedure SetScale(f: GLfloat);
       
    49 function  RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
    50 function  RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
    50 procedure RenderWeaponTooltip(atype: TAmmoType);
    51 procedure RenderWeaponTooltip(atype: TAmmoType);
    51 procedure ShowWeaponTooltip(x, y: LongInt);
    52 procedure ShowWeaponTooltip(x, y: LongInt);
    52 procedure FreeWeaponTooltip;
    53 procedure FreeWeaponTooltip;
    53 procedure MakeCrossHairs;
    54 procedure MakeCrossHairs;
    60 {$ENDIF}
    61 {$ENDIF}
    61 procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
    62 procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
    62 procedure SetSkyColor(r, g, b: real);
    63 procedure SetSkyColor(r, g, b: real);
    63 
    64 
    64 {$IFDEF GL2}
    65 {$IFDEF GL2}
    65 procedure UpdateModelviewProjection;
       
    66 {$ENDIF}
       
    67 
       
    68 procedure EnableTexture(enable:Boolean);
       
    69 
       
    70 procedure SetTexCoordPointer(p: Pointer;n: Integer);
       
    71 procedure SetVertexPointer(p: Pointer;n: Integer);
       
    72 procedure SetColorPointer(p: Pointer;n: Integer);
       
    73 
       
    74 procedure updateViewLimits();
       
    75 
       
    76 {$IFDEF GL2}
       
    77 var
    66 var
    78     shaderMain: GLuint;
    67     shaderMain: GLuint;
    79     shaderWater: GLuint;
    68     shaderWater: GLuint;
    80 {$ENDIF}
    69 {$ENDIF}
    81 
    70 
   108 begin
    97 begin
   109     if tmpHatSurf = nil then exit;
    98     if tmpHatSurf = nil then exit;
   110     SDL_FreeSurface(tmpHatSurf);
    99     SDL_FreeSurface(tmpHatSurf);
   111     tmpHatSurf:= nil;
   100     tmpHatSurf:= nil;
   112     prevHat:= 'NoHat';
   101     prevHat:= 'NoHat';
       
   102 end;
       
   103 
       
   104 procedure InitZoom(zoom: real);
       
   105 begin
       
   106     SetScale(zoom);
       
   107     UpdateViewLimits();
   113 end;
   108 end;
   114 
   109 
   115 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: PChar): TSDL_Rect;
   110 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: PChar): TSDL_Rect;
   116 var w, h: LongInt;
   111 var w, h: LongInt;
   117     tmpsurf: PSDL_Surface;
   112     tmpsurf: PSDL_Surface;
  1090     glEnable(GL_BLEND);
  1085     glEnable(GL_BLEND);
  1091     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1086     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1092     // disable/lower perspective correction (will not need it anyway)
  1087     // disable/lower perspective correction (will not need it anyway)
  1093 end;
  1088 end;
  1094 
  1089 
  1095 procedure EnableTexture(enable:Boolean);
       
  1096 begin
       
  1097     {$IFDEF GL2}
       
  1098     if enable then
       
  1099         glUniform1i(glGetUniformLocation(shaderMain, pchar('enableTexture')), 1)
       
  1100     else
       
  1101         glUniform1i(glGetUniformLocation(shaderMain, pchar('enableTexture')), 0);
       
  1102     {$ELSE}
       
  1103     if enable then
       
  1104         glEnable(GL_TEXTURE_2D)
       
  1105     else
       
  1106         glDisable(GL_TEXTURE_2D);
       
  1107     {$ENDIF}
       
  1108 end;
       
  1109 
       
  1110 procedure SetTexCoordPointer(p: Pointer; n: Integer);
       
  1111 begin
       
  1112 {$IFDEF GL2}
       
  1113     glBindBuffer(GL_ARRAY_BUFFER, tBuffer);
       
  1114     glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
       
  1115     glEnableVertexAttribArray(aTexCoord);
       
  1116     glVertexAttribPointer(aTexCoord, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
       
  1117 {$ELSE}
       
  1118     n:= n;
       
  1119     glTexCoordPointer(2, GL_FLOAT, 0, p);
       
  1120 {$ENDIF}
       
  1121 end;
       
  1122 
       
  1123 procedure SetVertexPointer(p: Pointer; n: Integer);
       
  1124 begin
       
  1125 {$IFDEF GL2}
       
  1126     glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
       
  1127     glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
       
  1128     glEnableVertexAttribArray(aVertex);
       
  1129     glVertexAttribPointer(aVertex, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
       
  1130 {$ELSE}
       
  1131     n:= n;
       
  1132     glVertexPointer(2, GL_FLOAT, 0, p);
       
  1133 {$ENDIF}
       
  1134 end;
       
  1135 
       
  1136 procedure SetColorPointer(p: Pointer; n: Integer);
       
  1137 begin
       
  1138 {$IFDEF GL2}
       
  1139     glBindBuffer(GL_ARRAY_BUFFER, cBuffer);
       
  1140     glBufferData(GL_ARRAY_BUFFER, n * 4, p, GL_STATIC_DRAW);
       
  1141     glEnableVertexAttribArray(aColor);
       
  1142     glVertexAttribPointer(aColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, pointer(0));
       
  1143 {$ELSE}
       
  1144     n:= n;
       
  1145     glColorPointer(4, GL_UNSIGNED_BYTE, 0, p);
       
  1146 {$ENDIF}
       
  1147 end;
       
  1148 
       
  1149 {$IFDEF GL2}
       
  1150 procedure UpdateModelviewProjection;
       
  1151 var
       
  1152     mvp: TMatrix4x4f;
       
  1153 begin
       
  1154     //MatrixMultiply(mvp, mProjection, mModelview);
       
  1155 {$HINTS OFF}
       
  1156     hglMVP(mvp);
       
  1157 {$HINTS ON}
       
  1158     glUniformMatrix4fv(uCurrentMVPLocation, 1, GL_FALSE, @mvp[0, 0]);
       
  1159 end;
       
  1160 {$ENDIF}
       
  1161 
       
  1162 (*
  1090 (*
  1163 procedure UpdateProjection;
  1091 procedure UpdateProjection;
  1164 var
  1092 var
  1165     s: GLfloat;
  1093     s: GLfloat;
  1166 begin
  1094 begin
  1177     glLoadMatrixf(@mProjection[0, 0]);
  1105     glLoadMatrixf(@mProjection[0, 0]);
  1178     glMatrixMode(GL_MODELVIEW);
  1106     glMatrixMode(GL_MODELVIEW);
  1179 {$ENDIF}
  1107 {$ENDIF}
  1180 end;
  1108 end;
  1181 *)
  1109 *)
  1182 
       
  1183 
       
  1184 procedure updateViewLimits();
       
  1185 var tmp: real;
       
  1186 begin
       
  1187     // cScaleFactor is 2.0 on "no zoom"
       
  1188     tmp:= cScreenWidth / cScaleFactor;
       
  1189     ViewRightX:= round(tmp); // ceil could make more sense
       
  1190     ViewLeftX:= round(-tmp); // floor could make more sense
       
  1191     tmp:= cScreenHeight / cScaleFactor;
       
  1192     ViewBottomY:= round(tmp) + cScreenHeight div 2; // ceil could make more sense
       
  1193     ViewTopY:= round(-tmp) + cScreenHeight div 2; // floor could make more sense
       
  1194 end;
       
  1195 
       
  1196 procedure SetScale(f: GLfloat);
       
  1197 begin
       
  1198 // leave immediately if scale factor did not change
       
  1199     if f = cScaleFactor then
       
  1200         exit;
       
  1201 
       
  1202     if f = cDefaultZoomLevel then
       
  1203 {$IFDEF GL2}
       
  1204         hglPopMatrix         // "return" to default scaling
       
  1205 {$ELSE}
       
  1206         glPopMatrix
       
  1207 {$ENDIF}
       
  1208     else                    // other scaling
       
  1209         begin
       
  1210 {$IFDEF GL2}
       
  1211         hglPushMatrix;       // save default scaling
       
  1212         hglLoadIdentity;
       
  1213         hglScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
       
  1214         hglTranslatef(0, -cScreenHeight / 2, 0);
       
  1215 {$ELSE}
       
  1216         glPushMatrix;       // save default scaling
       
  1217         glLoadIdentity;
       
  1218         glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
       
  1219         glTranslatef(0, -cScreenHeight / 2, 0);
       
  1220 {$ENDIF}
       
  1221         end;
       
  1222 
       
  1223     cScaleFactor:= f;
       
  1224     updateViewLimits();
       
  1225 
       
  1226 {$IFDEF GL2}
       
  1227     UpdateModelviewProjection;
       
  1228 {$ENDIF}
       
  1229 end;
       
  1230 
       
  1231 
  1110 
  1232 ////////////////////////////////////////////////////////////////////////////////
  1111 ////////////////////////////////////////////////////////////////////////////////
  1233 procedure AddProgress;
  1112 procedure AddProgress;
  1234 var r: TSDL_Rect;
  1113 var r: TSDL_Rect;
  1235     texsurf: PSDL_Surface;
  1114     texsurf: PSDL_Surface;