hedgewars/uMisc.pas
changeset 755 edf26e9554ac
parent 754 94ac14829085
child 759 8da05b316d81
equal deleted inserted replaced
754:94ac14829085 755:edf26e9554ac
   114 procedure SetKB(n: Longword);
   114 procedure SetKB(n: Longword);
   115 procedure SendKB;
   115 procedure SendKB;
   116 procedure SetLittle(var r: hwFloat);
   116 procedure SetLittle(var r: hwFloat);
   117 procedure SendStat(sit: TStatInfoType; s: shortstring);
   117 procedure SendStat(sit: TStatInfoType; s: shortstring);
   118 function  Str2PChar(const s: shortstring): PChar;
   118 function  Str2PChar(const s: shortstring): PChar;
   119 function  Surface2Tex(surf: PSDL_Surface): GLuint;
   119 function  Surface2Tex(surf: PSDL_Surface): PTexture;
   120 
   120 
   121 var CursorPoint: TPoint;
   121 var CursorPoint: TPoint;
   122     TargetPoint: TPoint = (X: NoPointX; Y: 0);
   122     TargetPoint: TPoint = (X: NoPointX; Y: 0);
   123 
   123 
   124 implementation
   124 implementation
   252 function RectToStr(Rect: TSDL_Rect): shortstring;
   252 function RectToStr(Rect: TSDL_Rect): shortstring;
   253 begin
   253 begin
   254 RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')'
   254 RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')'
   255 end;
   255 end;
   256 
   256 
   257 function Surface2Tex(surf: PSDL_Surface): GLuint;
   257 function Surface2Tex(surf: PSDL_Surface): PTexture;
   258 var mode: LongInt;
   258 var mode: LongInt;
   259     texId: GLuint;
   259     texId: GLuint;
   260 begin
   260 begin
   261 if SDL_MustLock(surf) then
   261 if SDL_MustLock(surf) then
   262    SDLTry(SDL_LockSurface(surf) >= 0, true);
   262    SDLTry(SDL_LockSurface(surf) >= 0, true);
       
   263 
       
   264 new(Surface2Tex);
       
   265 Surface2Tex^.w:= surf^.w;
       
   266 Surface2Tex^.h:= surf^.h;
   263 
   267 
   264 if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else
   268 if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else
   265 if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else
   269 if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else
   266    begin
   270    begin
   267    TryDo(false, 'Surface2Tex: BytePerPixel not in [3, 4]', true);
   271    TryDo(false, 'Surface2Tex: BytePerPixel not in [3, 4]', false);
   268    Surface2Tex:= 0;
   272    Surface2Tex^.id:= 0;
   269    exit
   273    exit
   270    end;
   274    end;
   271 
   275 
   272 glGenTextures(1, @texId);
   276 glGenTextures(1, @Surface2Tex^.id);
   273 
   277 
   274 glBindTexture(GL_TEXTURE_2D, texId);
   278 glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id);
   275 
   279 
   276 glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels);
   280 glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels);
   277 
   281 
   278 if SDL_MustLock(surf) then
   282 if SDL_MustLock(surf) then
   279    SDL_UnlockSurface(surf);
   283    SDL_UnlockSurface(surf);
   280 
   284 
   281 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
   285 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
   282 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
   286 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
   283 
       
   284 Surface2Tex:= texId
       
   285 end;
   287 end;
   286 
   288 
   287 
   289 
   288 var i: LongInt;
   290 var i: LongInt;
   289 {$ENDIF}
   291 {$ENDIF}