hedgewars/uMisc.pas
changeset 754 94ac14829085
parent 753 40fc0deb388f
child 755 edf26e9554ac
equal deleted inserted replaced
753:40fc0deb388f 754:94ac14829085
   256 
   256 
   257 function Surface2Tex(surf: PSDL_Surface): GLuint;
   257 function Surface2Tex(surf: PSDL_Surface): GLuint;
   258 var mode: LongInt;
   258 var mode: LongInt;
   259     texId: GLuint;
   259     texId: GLuint;
   260 begin
   260 begin
       
   261 if SDL_MustLock(surf) then
       
   262    SDLTry(SDL_LockSurface(surf) >= 0, true);
       
   263 
   261 if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else
   264 if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else
   262 if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else
   265 if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else
   263    begin
   266    begin
   264    TryDo(false, 'Surface2Tex: BytePerPixel not in [3, 4]', true);
   267    TryDo(false, 'Surface2Tex: BytePerPixel not in [3, 4]', true);
   265    Surface2Tex:= 0;
   268    Surface2Tex:= 0;
   269 glGenTextures(1, @texId);
   272 glGenTextures(1, @texId);
   270 
   273 
   271 glBindTexture(GL_TEXTURE_2D, texId);
   274 glBindTexture(GL_TEXTURE_2D, texId);
   272 
   275 
   273 glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels);
   276 glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels);
       
   277 
       
   278 if SDL_MustLock(surf) then
       
   279    SDL_UnlockSurface(surf);
   274 
   280 
   275 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
   281 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
   276 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
   282 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
   277 
   283 
   278 Surface2Tex:= texId
   284 Surface2Tex:= texId