hedgewars/uMisc.pas
changeset 1912 c3d31fb59f0e
parent 1911 6283bd8a960b
child 1916 9c3d0e3df6bb
equal deleted inserted replaced
1911:6283bd8a960b 1912:c3d31fb59f0e
   288 begin
   288 begin
   289 toPowerOf2:= 1;
   289 toPowerOf2:= 1;
   290 while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1
   290 while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1
   291 end;
   291 end;
   292 
   292 
       
   293 procedure ResetVertexArrays(texture: PTexture);
       
   294 begin
       
   295 with texture^ do
       
   296 	begin
       
   297 	vb[0].X:= 0;
       
   298 	vb[0].Y:= 0;
       
   299 	vb[1].X:= w;
       
   300 	vb[1].Y:= 0;
       
   301 	vb[2].X:= w;
       
   302 	vb[2].Y:= h;
       
   303 	vb[3].X:= 0;
       
   304 	vb[3].Y:= h;
       
   305 
       
   306 	tb[0].X:= 0;
       
   307 	tb[0].Y:= 0;
       
   308 	tb[1].X:= rx;
       
   309 	tb[1].Y:= 0;
       
   310 	tb[2].X:= rx;
       
   311 	tb[2].Y:= ry;
       
   312 	tb[3].X:= 0;
       
   313 	tb[3].Y:= ry
       
   314 	end;
       
   315 end;
       
   316 
   293 function NewTexture(width, height: Longword; buf: Pointer): PTexture;
   317 function NewTexture(width, height: Longword; buf: Pointer): PTexture;
   294 begin
   318 begin
   295 new(NewTexture);
   319 new(NewTexture);
   296 NewTexture^.w:= width;
   320 NewTexture^.w:= width;
   297 NewTexture^.h:= height;
   321 NewTexture^.h:= height;
   298 NewTexture^.rx:= 1.0;
   322 NewTexture^.rx:= 1.0;
   299 NewTexture^.ry:= 1.0;
   323 NewTexture^.ry:= 1.0;
       
   324 
       
   325 ResetVertexArrays(NewTexture);
   300 
   326 
   301 glGenTextures(1, @NewTexture^.id);
   327 glGenTextures(1, @NewTexture^.id);
   302 
   328 
   303 glBindTexture(GL_TEXTURE_2D, NewTexture^.id);
   329 glBindTexture(GL_TEXTURE_2D, NewTexture^.id);
   304 
   330 
   413 	Surface2Tex^.rx:= 1.0;
   439 	Surface2Tex^.rx:= 1.0;
   414 	Surface2Tex^.ry:= 1.0;
   440 	Surface2Tex^.ry:= 1.0;
   415 	glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels);
   441 	glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels);
   416 	end;
   442 	end;
   417 
   443 
       
   444 ResetVertexArrays(Surface2Tex);
       
   445 
   418 if SDL_MustLock(surf) then
   446 if SDL_MustLock(surf) then
   419    SDL_UnlockSurface(surf);
   447 	SDL_UnlockSurface(surf);
   420 
   448 
   421 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   449 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   422 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
   450 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
   423 end;
   451 end;
   424 
   452