diff -r 69f1dc50a1fa -r 40fc0deb388f hedgewars/uMisc.pas --- a/hedgewars/uMisc.pas Tue Jan 22 17:18:58 2008 +0000 +++ b/hedgewars/uMisc.pas Fri Jan 25 20:47:50 2008 +0000 @@ -18,7 +18,7 @@ unit uMisc; interface -uses uConsts, SDLh, uFloat; +uses uConsts, SDLh, uFloat, GL; {$INCLUDE options.inc} var isCursorVisible : boolean = false; isTerminated : boolean = false; @@ -115,7 +115,8 @@ procedure SendKB; procedure SetLittle(var r: hwFloat); procedure SendStat(sit: TStatInfoType; s: shortstring); -function Str2PChar(const s: shortstring): PChar; +function Str2PChar(const s: shortstring): PChar; +function Surface2Tex(surf: PSDL_Surface): GLuint; var CursorPoint: TPoint; TargetPoint: TPoint = (X: NoPointX; Y: 0); @@ -253,6 +254,30 @@ RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' end; +function Surface2Tex(surf: PSDL_Surface): GLuint; +var mode: LongInt; + texId: GLuint; +begin +if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else +if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else + begin + TryDo(false, 'Surface2Tex: BytePerPixel not in [3, 4]', true); + Surface2Tex:= 0; + exit + end; + +glGenTextures(1, @texId); + +glBindTexture(GL_TEXTURE_2D, texId); + +glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels); + +glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); +glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + +Surface2Tex:= texId +end; + var i: LongInt; {$ENDIF}